avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] ADC Free Running Mode at several ADC channelspossible


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] ADC Free Running Mode at several ADC channelspossible?
Date: Fri, 23 Feb 2007 17:54:47 +0100
User-agent: Mutt/1.5.11

As David Breeze wrote:

> It is up to you to keep track of the current channel, which you can
> of course read back from the ADMUX register.

e.g.:

uint16_t adcs[8];

ISR(ADC_vect)
{
  static uint8_t oldchan;
  uint8_t curchan = ADMUX & 7;

  adcs[oldchan] = ADCW;
  oldchan = curchan;

  if (++curchan == 8)
    curchan = 0;

  ADMUX = (ADMUX & ~7) | curchan;
}

Assuming proper initialization, this will, over time, fill in the
values of all 8 channels into the array adcs[].  The current channel
is always sampled at the beginning of one measurement, so the ISR is
called later, and switching the channel will only affect the next
measurement cycles (right before the ISR is called again).  When
starting up, channel 0 will be measured twice as the ISR came too
late switching to 1.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]