Show Posts
|
|
Pages: [1]
|
|
1
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: ADC Noise Reduction code please
|
on: January 22, 2011, 11:26:34 pm
|
Have you noticed a problem with analogRead? My analogRead values have been jumping around a bit. Admittedly, this could be due to any number of reasons. However, I figured Atmel must have put the noise reduction mode in for a reason and thought I'd give it a try first. But this didn't turn out to be so straightforward with Arduino, so I'm on to looking at my hardware now.
|
|
|
|
|
2
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: ADC Noise Reduction code please
|
on: January 22, 2011, 09:19:52 pm
|
|
Well, I'm sure a lot of people would find it useful to have a function that reads an analog input using ADC noise reduction, defined as such:
int analogNoiseReducedRead(int pinNumber)
But coding this is beyond my knowledge and skills. Anyone feel like taking it on and posting it here?
|
|
|
|
|
3
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: ADC Noise Reduction code please
|
on: January 22, 2011, 07:55:45 pm
|
Would this work? #include <avr/sleep.h>
void setup() { Serial.begin(9600); }
void loop() { int reading; reading = analogNoiseReducedRead(0); Serial.println(); delay(500); }
int analogNoiseReducedRead(int pinNumber) { int reading; ADCSRA |= _BV( ADIE ); //Set ADC interrupt set_sleep_mode(SLEEP_MODE_ADC); //Set sleep mode reading = analogRead(pinNumber); //Start reading sleep_enable(); //Enable sleep do { //Loop until reading is completed sei(); //Enable interrupts sleep_mode(); //Go to sleep cli(); //Disable interrupts } while(((ADCSRA&(1<<ADSC))!= 0)); //Loop if the interrupt that woke the cpu was something other than the ADC finishing the reading sleep_disable(); //Disable sleep ADCSRA &= ~ _BV( ADIE ); //Clear ADC interupt sei(); //Enable interrupts return(reading); }
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Waking Arduino once per minute on timer based int
|
on: May 14, 2009, 12:22:40 am
|
|
Hi Brian, Your code is great, but unfortunately the ATMega168 and ATMega328 (which I believe come with the Arduino Duemilanove, which I have on order) do not have watchdog clock dividers, unlike the AT90USB82 that you are using.
This means that the maximum time between watchdog interrupts for the Arduino Duemilanove is 8 seconds... Bummer!
Looks like the best I can do is what r55boy suggested... waking it up every 8 seconds to increment a counter then putting it back to sleep again... On every n wake ups execute the main code.
|
|
|
|
|
11
|
Forum 2005-2010 (read only) / Development / Re: byte sized datalogger, anyone?
|
on: May 31, 2009, 09:05:42 pm
|
|
Hi Nachtwind, As it stands it only uses built-in EEPROM, but I'm sure it could be adapted. Being very new to all of this I'm not really sure how easy or difficult it would be to do so.
Personally I don't have much need for more memory. I'm using an ATMega328, which (I am led to believe) has 1024 bytes of EEPROM available. So, it can fit 40 days worth of 1-hour time step data for one variable, which is plenty for my application.
I will post some files in the next few days if people are interested.
|
|
|
|
|
12
|
Forum 2005-2010 (read only) / Development / byte sized datalogger, anyone?
|
on: May 31, 2009, 05:05:11 am
|
I have just finished building a byte-sized (literally & figuratively) DataLogger library for EEPROM data storage and retrieval. It includes the following functions: - .AddVariable(int Size, Int Cycle): Adds variables to the data logger of a given size and cycle*
- .Write(int VarNum, int Value): Stores a value for a given variable
- .Read(int VarNum, int ValNum): Retrieves a value for a given variable
- .Encode(float Value, float Min, float Max): Encodes (scales between Min and Max) a value into 1-byte ready for storage
- .Decode(int Value, float Min, float Max): (The inverse to encode) Decodes a retrieved value, ready for use
- .Export(): Writes all data to the serial port in CSV format for easy copy-and-pasting from the serial monitor into a spreadsheet for analysis (columns = variables, rows = values).
- Additional functions for retrieving specific information about the DataLogger and its variables; for clearing values from one or all variables; for initialising a variable of the DataLogger class type.
* A variable being cycled (Cycle ==1) means that values are progressively overwritten once the variable's memory block is full. (Cycle == 0 [ch8594] not cycled) Would others find this useful? If so, let me know and I will document and post it.
|
|
|
|
|
14
|
Forum 2005-2010 (read only) / Interfacing / How to change ADC resolution?
|
on: May 31, 2009, 04:41:24 am
|
|
I'd like to change the ADC resolution to 8-bit. I am using a Duemilanove with ATMega328.
I understand that the default resolution of the Ardiunio's analog inputs is 10-bits (1024 levels). I am storing analog values as single bytes in EEPROM, so the additional 2-bits of resolution is unnecessary. I could mathematically convert 10-bit to 8-bit and then store, but thought it would be more efficient to just reduce the ADC resolution to 8-bit (1 byte) if possible.
Does anyone know how to do this?
|
|
|
|
|