Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Sleep Function (not delay) on: October 21, 2007, 12:22:35 pm
I was wondering if anyone knew how one might program a sleep function that actually sleeps the arduino microprocessor and wakes up after a preset number of milliseconds or clock cycles.  I would imagine this could be done with the watchdog timer.  Basically, I don't want to use the delay function, as that is just a while loop. I really want to sleep the chip (for power saving reasons) and wait for a timed interrupt.

Any advice or code would be greatly appreciated,
Chris


2  Forum 2005-2010 (read only) / Syntax & Programs / Re: EEPROM reading and writing on: October 18, 2007, 10:30:21 pm
Just wanted to follow up on my post since no one ever responded and I finally found a solution.  For what ever reason, the arduino wrapper is busted.  However, using the native libraries works...

you'll need to #include <avr/eeprom.h>


Code:
void setVal(int index, int value)
{
   eeprom_busy_wait();
   eeprom_write_word((uint16_t*)(index*2),(uint16_t)value);  //mult by 2 to store uint16 (2 bytes)
}

int getVal(int index)
{
   eeprom_busy_wait();
   return (int)eeprom_read_word((uint16_t*)(index*2)); //mult by 2 to store uint16 (2 bytes)
}
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: EEPROM reading and writing on: September 27, 2007, 11:00:29 pm
Here is another blob of code that illustrates the problem.  The Serial.println("test") is never executed.  There is no tx light activity either.  It just appears to die on the previous line: EEPROM.write(addr, val);

Code:
#include <EEPROM.h>

int addr = 0;

void setup()
{
   Serial.begin(9600);
}

void loop()
{
  int val = analogRead(0) / 4;
  EEPROM.write(addr, val);
   Serial.println("test");

  addr = addr + 1;
  if (addr == 512)
    addr = 0;
  
  delay(100);
}
4  Forum 2005-2010 (read only) / Syntax & Programs / EEPROM reading and writing on: September 27, 2007, 10:56:27 pm
I'm having a great deal of trouble with something that should be straightforward - I'm obviously missing something.  Hoping someone out there has a second to help.

I am trying to read and write to the EEPROM.  However, it appears writes lock up my arduino or garbles the serial output and runs irregularly.  Am I trashing program memory/code somehow?

Here is my sample program:

Code:
#include <EEPROM.h>

int address = 0;
byte value;

void setup()
{
  Serial.begin(9600);
}

void loop()
{  
  EEPROM.write(address,(byte)5);
  delay(100);
  value = EEPROM.read(address);
  
  Serial.println(value);
  
  address = address + 1;
  
  if (address == 512)
    address = 0;
    
  delay(100);
}


I've tried small delays, big delays, no delay.  If I remove the line that writes, the program runs fine.  Reading is not a problem.

Thank you in advance,
Chris
5  Forum 2005-2010 (read only) / Syntax & Programs / Power saving options on: October 18, 2007, 01:43:33 pm
I need to reduce the Arduino's power footprint as much as possible (in software preferably).  I was wondering if anyone has had any experience with avr/power.h?  

Link here: http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html

Does the Arduino codebase already do some optimization, or is everything turned on?  If I'm not using the ADC pins, can I disable that whole unit?  Which timers can I turn off?  I think timer0 is used for loop(), what about the other ones?  

Any help would be massively appreciated.  

Best,
Chris

(P.S. http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html seems promising as well, but I'm hoping power.h has lower hanging fruit).  
6  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Faster Analog Read? on: April 20, 2008, 11:57:03 pm
Wow.  Thank you jmknapp and oracle.

So if I just include your defines in the top of my code and the function calls in my setup, I should be good to go?  As in, analogReads will just return a lot faster (at a bit lower precision)?

How exactly is your code setting it to a prescale of 16.  I don't see any numbers in there..

Chris
7  Forum 2005-2010 (read only) / Frequently-Asked Questions / Faster Analog Read? on: April 20, 2008, 01:18:13 pm
I need to read an analog signal at about 50khz (for maybe 50-500 samples, not sure yet).  The reference seems to indicate the analogRead() takes about 100us, which is good enough for 10khz.  Is this limitation set by the Arduino libraries, or the ATMEGA chip?

Any help much appreciated,
Chris

P.S. does anyone know how fast the digital read is?
8  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: How to increase battery runtime when running Xbee? on: June 16, 2009, 01:24:24 pm
The arduino is pretty power hungry itself (30mA or something significant).  You can dial down the clock frequency if you don't need the performance and get it down to 5-10mA.  Search on the forum for details.

Chris
Pages: [1]