0

I am using sdFat library the analog bin logger example,

Github: SdFat/SdFat/examples/AnalogBinLogger/

The program is working fine and every thing but the thing is, this high speed datalogger uses interrupts and timers to make the ADC work at a pre-determined sampling frequency and it DOES NOT use the normal analogRead ()

What I want is, when the input of some analog pin is bellow a pre-determined value, I want to write HIGH or LOW to some digital pin, my question is, how can I compare the new sample in the analog bin logger example as I simply want to compare the new sample as in:

if ( analogRead() < 256 ) {// do something}

knowing that there is no analogRead() in the program because it uses timers and interrupts.

2

In the function

ISR(ADC_vect) {

the variable d contains the current sample:

  // Read ADC data.
#if RECORD_EIGHT_BITS
  uint8_t d = ADCH;
#else  // RECORD_EIGHT_BITS
  // This will access ADCL first.
  uint16_t d = ADC;
#endif  // RECORD_EIGHT_BITS

So you can just "do something" depending on what is in d. Of course, since this is a timer interrupt you have limited time to do anything, so you need to make sure that whatever you do is fast and efficient - so really you want to be using direct port access instead of digitalWrite().

| improve this answer | |
  • this is perfect, thanks but how to know which analog pin that this d value belongs to, because more than one channel are being used? @majenko – Sabir Moglad Mar 16 '16 at 17:45
  • 1
    @SabirMoglad Try looking at adcindex. – Majenko Mar 16 '16 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.