??? 05/17/08 04:59 Read: times |
#154833 - Here's my code Responding to: ???'s previous message |
This is for the LPC925, and is the combination of works from Code Architect and the SILABs code (thanks to original authours)
Please note that for some reason when posting some of the [-i-] stuff got converted to italics. I have gone through and added dashes before and after the [-i-] to make it look right but it won't compile obviously. Anyway you get the gist of it. INT_DEC = 256 Marshall void adc_isr ( void ) interrupt 14 using 1{ static xdata unsigned int accumulator[ANALOG_INPUTS] ={0}; // Here's where we integrate the // ADC samples from input AIN0.0 static xdata unsigned int_dec=INT_DEC; // Integrate/decimate counter // we post a new result when // int_dec = 0 unsigned char i; // adc1 conversion complete? if (ADCON1 & 0x08) { // clear ADCI1 flag ADCON1 &= ~0x08; // read results from AD1DAT0 - AD1DAT3 //the inputs are swapped in the hardware so swapp them to correct order ASAP accumulator[0] += AD1DAT1; // Read ADC value and add to running total accumulator[1] += AD1DAT0; // Read ADC value and add to running total accumulator[2] += AD1DAT3; // Read ADC value and add to running total accumulator[3] += AD1DAT2; // Read ADC value and add to running total int_dec--; // Update decimation counter // when last of the analog inputs // sampled if (int_dec == 0){ // If zero, then post result int_dec = INT_DEC; // Reset counter for(i=0; i<ANALOG_INPUTS; i++) { gui_AIResult[-i-] = accumulator[-i-] >> 4; //Copy decimated values into Result //as we have added the result 256 times //we can shift only 4 bits to the right //in order to get our extra 4bits of resolution //if we shift it 8 bits then we get an average of //the last 256 samples. accumulator[-i-] = 0; // Reset accumulators } } } |