optimisations in adc code
This commit is contained in:
parent
ea03c8ca67
commit
ee0f2a921d
|
@ -30,12 +30,13 @@ uint16_t adc_read_single(uint8_t channel) {
|
|||
return ADCW;
|
||||
}
|
||||
|
||||
uint16_t adc_read_avg(uint8_t channel, uint8_t nsamples) {
|
||||
uint32_t sum = 0;
|
||||
uint16_t adc_read_avg(const uint8_t channel, const uint8_t nsamples) {
|
||||
uint16_t sum = 0;
|
||||
uint8_t count = nsamples % 60;
|
||||
|
||||
for (uint8_t i=0; i<nsamples;++i ) {
|
||||
for (uint8_t i=0; i<count;++i ) {
|
||||
sum += adc_read_single(channel);
|
||||
}
|
||||
|
||||
return (uint16_t)(sum / nsamples);
|
||||
return (sum / count);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef _adc_h
|
||||
#define _adc_h
|
||||
|
||||
void adc_init(void);
|
||||
uint16_t adc_read_single(uint8_t);
|
||||
uint16_t adc_read_avg(uint8_t, uint8_t);
|
||||
extern void adc_init(void);
|
||||
extern uint16_t adc_read_single(uint8_t);
|
||||
extern uint16_t adc_read_avg(uint8_t, uint8_t);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue