![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ADC Spike2
Revision 1:0d866e3f26ab, committed 2010-03-09
- Comitter:
- simonb
- Date:
- Tue Mar 09 16:41:55 2010 +0000
- Parent:
- 0:db49fab3bd78
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 09 15:58:33 2010 +0000 +++ b/main.cpp Tue Mar 09 16:41:55 2010 +0000 @@ -7,33 +7,30 @@ //Initialise ADC to maximum SAMPLE_RATE and cclk divide set to 1 ADC adc(SAMPLE_RATE, 1); -uint32_t adc_max[6], adc_av[6], adc_min[6]; +uint32_t adc_max, adc_av, adc_min; int snap = 0; void min_max_av(int chan, uint32_t value) { - static uint64_t adc_tot[6], counter = 0; - uint32_t adc_max_tmp[6], adc_av_tmp[6], adc_min_tmp[6]; + static uint64_t adc_tot, counter = 0; + static uint32_t adc_max_tmp, adc_min_tmp; - int i, adc_value; + int adc_value; - for (i=0; i<6; i++) { - adc_value = adc.read(adc.channel_to_pin(i)); - //Update min, max and average records and totals - if (adc_value > adc_max_tmp[i]) adc_max_tmp[i] = adc_value; - if (adc_value < adc_min_tmp[i]) adc_min_tmp[i] = adc_value; - adc_tot[i] += adc_value; - counter++; - //If snapshot requested then sample data and reset average - if (snap) { - adc_av[i] = (int)(adc_tot[i] / counter); - adc_max[i] = adc_max_tmp[i]; - adc_av[i] = adc_av_tmp[i]; - adc_min[i] = adc_min_tmp[i]; - adc_max_tmp[i] = 0; - adc_min_tmp[i] = 0xFFFF; - adc_av_tmp[i] = 0; - } + adc_value = adc.read(p20); + //Update min, max and average records and totals + if (adc_value > adc_max_tmp) adc_max_tmp = adc_value; + if (adc_value < adc_min_tmp) adc_min_tmp = adc_value; + adc_tot += adc_value; + counter++; + //If snapshot requested then sample data and reset average + if (snap) { + adc_max = adc_max_tmp; + adc_av = (int)(adc_tot / counter); + adc_min = adc_min_tmp; + adc_max_tmp = 0; + adc_min_tmp = 0xFFFF; + adc_tot = 0; } if (snap) counter = 0; snap = 0; @@ -54,7 +51,6 @@ } int main() { - int i; printf("\nRequested max sample rate is %u, actual max sample rate is %u.\n", SAMPLE_RATE, adc.actual_sample_rate()); @@ -64,29 +60,19 @@ adc.startmode(0,0); adc.burst(1); adc.setup(p20,1); - adc.setup(p19,1); - adc.setup(p18,1); - adc.setup(p17,1); - adc.setup(p16,1); - adc.setup(p15,1); - //For burst mode, only one interrupt is required - //which can be on any enabled pin. We have enabled all - //of them here. - adc.interrupt_state(p15,1); + adc.interrupt_state(p20,1); printf("Burst mode, printing once per second...\n"); while (1) { snap = 1; wait(0.5); - for (i=0; i<6; i++) { - printf ("CH %u Min :", i); - bar(adc_min[i]); - printf ("CH %u Av :", i); - bar(adc_av[i]); - printf ("CH %u Max :", i); - bar(adc_max[i]); + printf ("Min :"); + bar(adc_min); + printf ("Av :"); + bar(adc_av); + printf ("Max :"); + bar(adc_max); printf("\n"); - } printf("......................................................\n"); wait(0.5); }