Show Posts
Pages: [1] 2
1  Using Arduino / Microcontrollers / Re: ATMEGA328p Standalone 8MHz @ 2.5v on: December 23, 2012, 06:07:31 pm
Can you or anyone else post some tests? I can't until I buy a new meter.
2  Using Arduino / Microcontrollers / Re: ATMEGA238p Standalone 8MHz @ 2.5v on: December 22, 2012, 07:22:26 pm
I originally had the same issue with 2.5V not running the sketch. I disabled brown-out detection by setting the extended fuse to 0x07 and that fixed it.

So it looks like 2.5 mA is normal for this circuit. That's still much better than 16.5 mA and is going to increase battery life in my project quite a bit.

Looks like I'm going to invest in a better meter. Merry Christmas me!
3  Using Arduino / Microcontrollers / Re: ATMEGA238p Standalone 8MHz @ 2.5v on: December 22, 2012, 05:25:53 pm
I've received quite a few responses and I would like to thank everyone for their input. I've come to accept the multimeter I bought is terrible. Thank you RadioShack. I should have realized that if it doesn't cost much, it's probably because it's not worth much. I recommend it to no one.

With that aside, I added the .01uF capacitors between the ground and Vcc pins as close to the chip as possible per dc42's request (and in Nick's page).

Nick, the socket on the right you couldn't read in the picture says V / ohms / mA. However, I moved to the left socket as suggested and I am seeing a reading that jumps between .002 and .003 Amps (2 - 3 mA). That's the highest resolution I can get from the socket. This reading is consistent with what I had from the borrowed (non RadioShack) meter and is also consistent with the ATMEGA328p datasheet as pointed out by user dc42.

Regarding the note on the ATMEGA328p's reliability under 2.8V @ 8MHz, I will keep this in mind. I tested with a 3V CR2032 and saw the roughly the same results for current. I also loaded a sketch to blink pin 13 and I didn't see any inconsistent blinking to indicate it is rebooting. The project this will be used in will run @ 3.3V, I just don't have an unregulated 3.3V power source at the moment.

Overall, I'm quite happy to see the current drop from about 16 mA to just under 3 mA, but I do see a conflict between what the ATMEGA328p datasheet states and what Nick's test is showing me.

I'm curious to see what other people are reading for current.
4  Using Arduino / Microcontrollers / Re: ATMEGA238p Standalone 8MHz @ 2.5v on: December 22, 2012, 03:37:53 am
I hope this helps. You will notice the meter has since changed, the other one was borrowed and since returned. This is the original meter I measured 5 mA with. The power source is two AA NiMH rechargeable batteries connected in series. The first image is confirmation on the voltage reading. The second image is how I am measuring the current.





Quote
Measure the current through just a resistor.

I measured through just a 10k resistor and read 0.46 mA. I'm not sure if that is what you were asking for. How does this measure the accuracy of the meter?
5  Using Arduino / Microcontrollers / Re: ATMEGA238p Standalone 8MHz @ 2.5v on: December 22, 2012, 12:30:25 am
I didn't have an enclosure to keep the batteries in so I held them together. The meter is in series between the battery and the positive end of the circuit. I also tried another ATMEGA328p, same results.
6  Using Arduino / Microcontrollers / Re: ATMEGA238p Standalone 8MHz @ 2.5v on: December 21, 2012, 10:06:28 pm


I tried another multimeter and that one is measuring 2.7 mA.  Closer, but not quite where I would expect. Yes, I confirmed the 2.5 V using both multimeters. I am using two NiMH rechargeable batteries in series. They are rated for 1.2 V, but I am measuring a little over from each. Is it possible the multimeters are just off? I noticed the second multimeter reads "Connect Test Leads". I can't make it go away.
7  Using Arduino / Microcontrollers / Re: ATMEGA238p Standalone 8MHz @ 2.5v on: December 21, 2012, 01:28:48 am
Quote
Or were you expecting the current consumption to be much higher than 5 mA and got the decimal in the wrong place (51 mA versus 0.51 mA)?

As I stated in my original question...

Quote
According to the post, it should be consuming 0.51ma

Search for "0.51 mA" in Nick's tutorial, it's titled "More savings with lower voltages" and is just over halfway down. That is the section I am referring to. According to the chart, it should be consuming 0.51 mA, unless I am misunderstanding something.
8  Using Arduino / Microcontrollers / ATMEGA328p Standalone 8MHz @ 2.5v on: December 21, 2012, 12:22:15 am
I've been reading Nick Gammon's post ( http://gammon.com.au/power) on power management for the ATMEGA 328p and I am having trouble reaching the same level of efficiency. I configured the fuses to use the internal 8MHz clock and it is connected to 2.5v. According to the post, it should be consuming 0.51ma. However, I'm measuring 5ma (yes I double checked, it says "ma"). I loaded script A (from Nick's post) to the ATMEGA as a baseline test.

Code:
void setup(){}
void loop(){}

My power supply is unregulated.
These are the fuses as read from avrdude:
lfuse: 0xe2
hfuse: 0xde
efuse: 0x07

Here is how I have the ATMEGA 328p wired:

Pin 1: 10k resistor >> 2.5v
Pin 7: 2.5v
Pin 8: Gnd
Pin 20: 2.5v
Pin 22: Gnd
10uf capacitor between 2.5v & Gnd

Also, I temporarily loaded a sketch which blinks an LED on digital 13 just to make sure it is functioning.

Does anyone know what I am doing wrong?

[EDIT] I updated the title of this thread, it said ATMEGA238p rather than ATMEGA328p
9  Using Arduino / Programming Questions / Re: Serial Garbage on Sleep Wake on: November 28, 2012, 11:20:05 pm
I tried delay(10) and the registers in separate tests and both worked. I didn't try the resistor. Thank you both for your help.
10  Using Arduino / Programming Questions / Serial Garbage on Sleep Wake on: November 28, 2012, 10:00:52 pm
I'm seeing some odd behavior regarding the Serial output when waking the Arduino from sleep mode.

Code:
#include <avr/sleep.h>
#include <avr/power.h>

void setup()
{
  Serial.begin(9600);
  Serial.println("leaving setup");
}

void loop()
{
    Serial.println("sleeping...");
    Serial.flush();
   
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    attachInterrupt(0, pin2Interrupt, LOW);
    sleep_mode();
    // sleeping
    sleep_disable();
    delay(1000);
    Serial.println("awake");
}

void pin2Interrupt()
{
  detachInterrupt(0);
}

I see the following output:
-------------------------------------
leaving setup
sleeping... Cáawake
sleeping... Cáawake
sleeping... Cáawake
-------------------------------------

I'm not sure why the "Cá" is printed. Also the line break is missing. I have pin2 attached to a 555 timer circuit to wake the Arduino every eight seconds via interrupt.

Any ideas as to what is causing this?
11  Using Arduino / Programming Questions / Re: Watchdog Timer ISR(WDT_vect) and Serial.println on: November 26, 2012, 10:31:21 pm
Sorry about the long wait. It was a holiday weekend in the United States.

I found the web page I referenced earlier which contains details on how the watchdog works. This is why I have the infinite loop in the ISR.
http://www.atmel.com/Images/doc2551.pdf
page 5

Quote
The infinite loop at the end of the interrupt handler prevents the main code from potentially causing more damage.

I seem to need it to trigger the reset as well. I have a working example writing to the EEPROM in the ISR and then printing the data using Serial.println on startup. I think I have everything I need to move on. Thanks once again for everyone's advice.

Code:

#include <avr/wdt.h>
#include <EEPROM.h>

byte check = 0;
byte value = 0;

/* sets the watchdog timer both interrupt and reset mode with an 8 second timeout */
void enableWatchdog()
{
  cli();
  MCUSR &= ~(1<<WDRF);
  wdt_reset();
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  WDTCSR = (~(1<<WDP1) & ~(1<<WDP2)) | ((1<<WDE) | (1<<WDIE) | (1<<WDP3) | (1<<WDP0));
  sei();
}

/* disables the watchdog timer */
void disableWatchdog()
{
  cli();
  wdt_reset();
  MCUSR &= ~(1<<WDRF);
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  WDTCSR = 0x00;
  sei();
}

/* this is called when the watchdog times out and before the reset */
ISR(WDT_vect)
{
  randomSeed(analogRead(0)); // leave analog 0 unconnected (http://arduino.cc/en/Reference/Random)
  value = random(0,255);     // just a meaningless random number to retrieve later
  EEPROM.write(1, value);    // write the random number to the second byte
  EEPROM.write(0,1);         // write a "1" to the first byte to indicate the data in second byte is valid and the ISR triggered properly
  while(true);               // triggers the second watchdog timeout for a reset
}


void setup()
{
  disableWatchdog();
  enableWatchdog();
  Serial.begin(9600);
  check = EEPROM.read(0);
 
  // if the watchdog triggered and the ISR completed, the first EEPROM byte will be a "1"
  if(check == 1)
  {
    value = EEPROM.read(1);
    EEPROM.write(0,0); // reset byte so the EEPROM is not read on next startup
    Serial.print("Watchdog was triggered and the following was read from EEPROM: ");
    Serial.println(value);
  }
 
  Serial.println("Finished setup...");
}

void loop()
{
  while(true);
}

12  Using Arduino / Programming Questions / Re: Watchdog Timer ISR(WDT_vect) and Serial.println on: November 20, 2012, 06:43:30 pm
I originally coded the ISR to be a "catch-all" in the event an unexpected issue causes a lock-up, there is no actual issue to debug at the moment. I know nothing can be done if the offending code is located in the ISR.

bperrybap - I am using 1.0.1. I have seen plenty of watchdog examples which have a Serial.println in the ISR, they must have been written pre-1.x.

Nick - The "while" is in the ISR so the watchdog will timeout a second time and cause a reset. I remember reading somewhere that in order to get both the interrupt and the reset, I need to trigger the watchdog twice. Let me know if this isn't true or if there is a better alternative. I tested your claim of interrupts being disabled in the ISR and you're spot on. I altered the ISR as below and it works. The delay is needed to allow time for Serial.println before disabling interrupts again.

Code:
ISR(WDT_vect)
{
  detachInterrupt(1);
  detachInterrupt(0);
  sei();
  Serial.println("Watchdog triggered");
  delay(50);
  cli();
  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH);
  while(true);
}

I found this is also the reason the MicroSD doesn't work in the ISR. Is there a way to write to Serial/MicroSD without interrupts enabled? If not, what would be the best alternative?

I was thinking of writing to the EEPROM when in the ISR. Then in setup, read the EEPROM, write to MircoSD and continue on as normal. If anyone wondering why add the MicroSD to the mix, all other data is logged to it and I would like to have a central location.

Thanks everyone for the advice.
13  Using Arduino / Programming Questions / Watchdog Timer ISR(WDT_vect) and Serial.println on: November 19, 2012, 11:53:21 pm
I am unable to get Serial.println to work when inside the ISR method triggered before a watchdog timeout. I have the optiboot bootloader installed. The watchdog is set to expire after 8 seconds and is set up to trigger both the interrupt and a reset. It appears the reset is working correctly because I see the "Finished Setup..." message repeatedly. Also, I have an LED attached to digital 6 and it lights up as indicated in the code, but for some reason Serial.println() does not work.

My original goal was to write some debug info to a MicroSD card but that wasn't working either so I tried with the Serial.println for simplicity.

Here is what I am seeing (I would have expected "Watchdog triggered" to be printed before the LED was lit)

Finished setup...
[pause]
[LED lights for 8 seconds]
Finished setup...
[pause]
[LED lights for 8 seconds]
Finished setup...
[pause]
[LED lights for 8 seconds]
Finished setup...
[pause]
[LED lights for 8 seconds]
Finished setup...
[pause]
[LED lights for 8 seconds]


Code:
#include <avr/wdt.h>

void enableWatchdog()
{
  cli();
  MCUSR &= ~(1<<WDRF);
  wdt_reset();
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  WDTCSR = (~(1<<WDP1) & ~(1<<WDP2)) | ((1<<WDE) | (1<<WDIE) | (1<<WDP3) | (1<<WDP0));
  sei();
}

void disableWatchdog()
{
  cli();
  wdt_reset();
  MCUSR &= ~(1<<WDRF);
  WDTCSR |= (1<<WDCE) | (1<<WDE);
  WDTCSR = 0x00;
  sei();
}

ISR(WDT_vect)
{
  Serial.println("Watchdog triggered");
  pinMode(6, OUTPUT);
  digitalWrite(6, HIGH);
  while(true);
}


void setup()
{
  disableWatchdog();
  enableWatchdog();
  Serial.begin(9600);
  Serial.println("Finished setup...");
}

void loop()
{
  while(true);
}
14  Using Arduino / Programming Questions / Re: Servo Instance Created from Inside another Class on: June 03, 2011, 04:53:07 pm
I did exactly what you suggested and it worked. Thank you for your help.
15  Using Arduino / Programming Questions / Re: Servo Instance Created from Inside another Class on: June 02, 2011, 06:54:36 pm
Happy to know I would fail your interview  smiley. I made the suggested changes. It did help stop the "jiggling" of the servo. However, now it doesn't move at all and just makes a high pitch buzzing noise. I pasted the modified code below just to verify this is what you had in mind.

mainCode
Code:
#include <Servo.h>
#include "ServoTest.h"

ServoTest t;

void setup()
{
}

void loop()
{
  t.set(45);
  delay(1500);
  t.set(90);
  delay(1500);
}

ServoTest.h
Code:
#pragma once
#include <Servo.h>

class ServoTest
{   
  private:
    Servo servo;
  public:
    ServoTest();
    void set(int);
};

ServoTest.cpp
Code:
#include "ServoTest.h"

ServoTest::ServoTest()
{
  servo.attach(8);
}

void ServoTest::set(int value)
{
  servo.write(value);
}

Pages: [1] 2