/** * This file is part of license combination gpl version 3 license and eCos. * The corresponding license terms are below. * * gpl version 3 Licence: * * The file were developed during the student thesis "Datensammlung in Wireless * Sensor Networks fuer Autonomic Home NetworkingÒ of Thomas Kothmayr and is * included in the dissertation "Secure Data Transmission in Wireless * Sensor Networks" by Corinna Schmitt during employment at the Technische * UniversitŠt MŸnchen, Department Computer Science, Chair Network * Architectures and Services (Germany). * Copyright (C) 2013 * Authors: Thomas Kothmayr and Corinna Schmitt (schmitt[at]net.in.tum.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3 of the License * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * * eCos Licence: (http://ecos.sourceware.org) * * This file is part of eCos, the Embedded Configurable Operating System. * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, * 2007, 2008, 2009 Free Software Foundation, Inc. * * eCos is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 any later version. * * eCos is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with eCos; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * As a special exception, if other files instantiate templates or use * macros or inline functions from this file, or you compile this file and * link it with other works to produce a work based on this file, this file * does not by itself cause the resulting work to be covered by the GNU * General Public License. However the source code for this file must still * be made available in accordance with section (3) of the GNU General * Public License v2. * * This exception does not invalidate any other reasons why a work based on * this file might be covered by the GNU General Public License. * */ Interface: tos.chips.atm128.adc.Atm128AdcMultiple

Interface: tos.chips.atm128.adc.Atm128AdcMultiple

interface Atm128AdcMultiple

Hardware Abstraction Layer interface of Atmega128 for acquiring data from multiple channels using the ATmega128's free-running mode.

Because of the possibility that samples may be imprecise after switching channels and/or reference voltages, and because there is a one sample delay on swithcing channels and reference voltages, Atm128ADCMultiple is complex. Two straightforward uses are:

  1. Acquire N samples from channel C:
    1. call getData to start sampling on channel C at the desired rate (note that the choice of prescalers is very limited, so you don't have many choices for sampling rate)
    2. ignore the first dataReady event
    3. use the results of the next N dataReady() events, return FALSE on the last one
  2. Acquire one sample each from channels C1, ..., Cn (this pseudocode assumes that none of these channels are differential)
    1. call getData to start sampling on channel C1
    2. on the ith dataReady event switch to channel Ci+1 by changing *newChannel
    3. the data passed to the ith dataReady event is for channel Ci-1 (the data from the first dataReady event is ignored)

Author:
Hu Siquan <husq@xbow.com>
David Gay

Commands
command bool getData(uint8_t channel, uint8_t refVoltage, bool leftJustify, uint8_t prescaler) Initiates free-running ADC conversions, with the ability to switch channels and reference-voltage with a one sample delay.

Events
event bool dataReady(uint16_t data, bool precise, uint8_t channel, uint8_t *newChannel, uint8_t *newRefVoltage) Returns the next sample in a free-running conversion.

Commands - Details

getData

command bool getData(uint8_t channel, uint8_t refVoltage, bool leftJustify, uint8_t prescaler)

Initiates free-running ADC conversions, with the ability to switch channels and reference-voltage with a one sample delay.

Parameters:
channel - Initial A/D conversion channel. The channel can be changed in the dataReady event, though these changes happen with a one-sample delay (this is a hardware restriction).
refVoltage - Initial A/D reference voltage. See the ATM128_ADC_VREF_xxx constants in Atm128ADC.h. Like the channel, the reference voltage can be changed in the dataReady event with a one-sample delay.
leftJustify - TRUE to place A/D result in high-order bits (i.e., shifted left by 6 bits), low to place it in the low-order bits
prescaler - Prescaler value for the A/D conversion clock. If you specify ATM128_ADC_PRESCALE, a prescaler will be chosen that guarantees full precision. Other prescalers can be used to get faster conversions. See the ATmega128 manual for details.
Returns:
TRUE if the conversion will be precise, FALSE if it will be imprecise (due to a change in reference voltage, or switching to a differential input channel)

Events - Details

dataReady

event bool dataReady(uint16_t data, bool precise, uint8_t channel, uint8_t *newChannel, uint8_t *newRefVoltage)

Returns the next sample in a free-running conversion. Allow the user to switch channels and/or reference voltages with a one sample delay.

Parameters:
data - a 2 byte unsigned data value sampled by the ADC.
precise - if this conversion was precise, FALSE if it wasn't (we assume that the second conversion after a change of reference voltage or after switching to a differential channel is precise)
channel - Channel this sample was from.
newChannel - Change this parameter to switch to a new channel for the second next sample.
newRefVoltage - Change this parameter to change the reference voltage for the second next sample.
Returns:
TRUE to continue sampling, FALSE to stop.