Tiny13V reset TCNT0 before SLEEP too 0

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a battery operated project that controls a tiny stepper motor that can be stepped directly from the chip ports.

I am using idle mode sleep and timer0 prescaled at 1024 to wake up from sleep. It then reads the ADC updates the stepper and goes back to sleep. The question is do I just write the tcnt0 to $00 while the interrupts are cleared (cli) or do I have to clear the timer interrupt bit as well?

Second question, Is the power reduced when prescaling the chip using the CLKPR at 4.8MHZ internal oscillator or should I think about the 128khz oscillator I have never set it to run at that speed.

I want to end up checking about 5 second intervals, from sleep, the stepper from 20 degrees to 120 degrees is only 600 steps.

It will use 2 1.5V batteries rated at 110MA and I want to get 90 days before battery is out. using the Tiny13V

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,
I am doing a Tiny13 project to make very slow sine waves and did the numbers for timer rollovers recently.
If the Tiny13 runs at 4.8MHz internal RC clock, then the system clock period is .2083 microseconds. Prescaling by 1024 gives a timer clock period of 21.3 microseconds. Timer rollover (going from 00 to 0xff in an 8bit TCNT0 count) takes 0.0546 sec (18.3 rollovers per second).
Using the 128KHz internal clock gives a system clock period of 7.8 microseconds. A 1024 prescale gives a 0.008 second timer increment clock period and 2.048 seconds for a 256 count rollover. The program could toggle a flag at each rollover (timer overflow) and then do an ADC conversion each time the flag goes high.
Since the system clock is executing instructions at one per 7.8 microseconds and there is 8000 microseconds between the Timer Overflow (TCNT0 goes to 00 from 0xff) and the count to 01, there isn't any need to set the timer to 00 because the interrupt code will be finished long before the TCNT0 transistion from 00 to 01.

Using the 128KHz speed will definitely give longer battery life than the 4.8MHz speed regardless of the code. Another approach would be to use a large value resistor and capacitor to get a long RC time constant. Connect the resistor and capacitor to the INT0 pin and set the system to wake on a rising edge. Then go into PowerDown sleep mode instead of Idle. When the rising voltage on the INT0 pin reaches the trigger level for logic high, then the Tiny13 will awaken from deep sleep and run the INT0 interrupt. The timer won't be used. PowerDown mode uses much less battery current than Idle mode but can only awaken by a reset or INT0 edge. It seems that the Tiny13 could be in PowerDown mode almost all the time and be active at 128KHz system clock speed briefly every five seconds. There may be reasons why this wouldn't work; it's just a concept.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You might check out the new generation--Tiny25s are now available along with Tiny45s. I think you will find it easier to shave uA with each newer generation, but maybe not.

As far as power vs. clock questions, that should be fairly easy. Mount a bare chip with minimum external components and hang a decent meter on Vcc. Then add you external subsystems and re-test.

With Tiny25/45, or Mega48/88/168, I think you will find that the best power-down performance will be to use the watchdog timer interrupt to wake up rather than the "regular" AVR timers which need a higher-powered clock running. I suspect this will also be true on the Tiny13. You should be able to get down to a few uA.

So, let's talk power budget. You want 100mAH to last 100 days; 1mAH/day. 40uAH/hour. So we need to average 40uA draw to meet budget.

So we power-down, consuming say 5uA waking every 4 seconds or 8 seconds for maybe 10ms? 100ms? for a look-around and go back to sleep. 80ms every 8 seconds is 1% of total time. We have 35uA to work with each hour, so we can draw 3500uA or 3.5mA which should be right around what a wound-up AVR would draw with the A/D fired up. Remember to completely shut down the A/D, and when you awake you will need to do a few conversions (at least throw the first one away) to get decent results. Hopefully your stepper won't suck much but I'm a bit scared of that.

It's kind of fun, actually. Only needs a decent meter, the datasheet, and your head. Take my advice & build up from bare rather than trying to figure out where your overdraws are coming from. The AVR >>will<< be as good as or better than the datasheet numbers.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Using the 128KHz speed will definitely give longer battery life than the 4.8MHz speed regardless of the code.

I cannot necessarily agree with that. AVR power consumption in active mode is proportional to clock speed. Plus there is going to be a fixed draw regardless of clock speed in active, maybe a couple of hundred uA.

So if the "task" to do each awakening takes 1000 cycles (say) then you get to go back to sleep much faster--1/40 the time--running at 4.8MHz vs. 128kHz. Now, this app apparently wants to do some A/D that you might have to wait for, but power-save is pretty good at that.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Teusch, yes I do have some Tiny25 samples but they are dips, I have to do it surface mount and I have the t13's in stock. I will look at them for production though.

I used the CLKPR system clock prescale of 128 that brings the 4.8MHZ down to 37,500 Prescaled the timer0 to 1024 and I get about 14 seconds sleep time per rollover.

Using just a loop that goes to sleep wakes up and pauses for 65,535 clocks I can read the meter when it switches from sleep to awake just executing a loop.

At a clock prescale of 128 timer prescale 1024

42.7ua sleep and 50ua in loop

at system clock of 64

41ua sleep and 56 in loop

Kind of strange the ua is higher in sleep mode with higher system clock prescale just a tad but it is lower by 6ua while running.

Watchdog is off, comparator is off as well.

I did answer the question though on resetting the timer back to 0. I load the tcnt0 with 0 just before going to sleep with interrupts off (cli) then sei and sleep. Otherwise the 8 bit timer could be anywhere and I would get unknown sleep delays.

So I guess if I can average 70ua its about 65 days.

I like the idea on the capacitor interrupt, The stepper is connected to pb0,pb1,and pb2 but setting all 3 pins to input while shut down would allow for that and triple the battery life or more.

I have not put much thought to it yet but I am thinking there must be a way to trigger the interrupt from power down on a change in temperature but the board space is less than 1 sq inch for this circuit and I think that might take a few more components and of course some power as well.

So , I am off to find calculations on rc time to test the power down mode and then finish the prorotype.

By the way these tiny steppers I can get for about 2 bucks if this project sells if anyone needs some tiny steppers. Here is a link to the product

http://www.microcomponents.ch/pr...

EDIT I forgot to mention the numbers above are at 3V VCC, at 4.5V it jumps to 63.6 and 76.6 at the system clock prescale of 128

It actually runs at 1.6V at 26ua sleep and 30ua in an endless loop. I don't have a good bench supply so I just used a 3V regulated wart and 2 100ohm resistors to get the 1.6V test.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All the uA VALUES IN ABOVE POST ARE BUNK

That's what happens when you don't use fluke, My RS Special meter I swear was saying those numbers, now it's 300uA sleep mode. I thought that was too good to be true, well I better get to the int0 capacitor powerdown logic then.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

After reviewing the Tiny13 datasheet, I think that the best approach would be to use the Watchdog Interrupt set a 4 seconds and 128KHz. The watchdog runs in power-down sleep mode which should give the best power savings. The suggestion of a resistor and capacitor was before I realized that the Tiny13 could run a clock in deep background while in power down mode. The 128KHz clock is in the specified range of the ADC clock also.
The suggestion that the project be moved to Tiny45 is good because Digikey has raised the price of the Tiny13 and lowered the price of the Tiny45 until they are about the same (about $1.34 US in quantity 25). The Tiny45 has four times as much memory, a second timer, a serial interface (but not a UART), and allows for operation with a crystal (which for some unknown reason, the Tiny13 doesn't allow).
If the project were to use a resistor and capacitor for a timer, then the INT0 port could discharge the capacitor by being set as an output port and then having logic low applied. This might cause too much current to flow from the capacitor through the port pin because the capacitor would be grounded when the pin went to logic low and it would very quickly discharge. So a 10 ohm or so resistor between the capacitor and the port pin would be a good idea.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks so much Simonetta for all the time looking at this. It was late last night and I don't have a clue what I did to the programming on the chip that gave me the .300 mA readings But tonight after reprogramming I am back at 41.4uA in idle mode and 56uA in an endless loop using the 128 prescale at 4.8MHZ Attached picture shows sleep mode 041.4 uA so it must be true. I know the datasheet shows 1MHZ, 1.8V: 240uA so when I looked at that I thought I had lost my mind seeing 41.7uA but now like I say it does run at 3V with 4.8mhz with a 128 prescale at 41.4 ua

Anyway , you are correct the watchdog is what I should use to do it and that is what I will do.

However...

I will set it up to check every 1 second and add one more thing to the circuit. A tiny motion detector.

While updating the gauge I will also be detecting any movement or the product, when I sense no movement for some time I will power down with a pin change interrupt set. Using only .1ua it can sit on the shelf for a long time and still come alive when picked up.

I found these motion tilt switches for .55cents over 10k qty to $1.35 ea in small quantities and a sample is in the mail, photo attached.

This will solve my power problem, as there is no need to update the gauge when nobody is looking at it or using it because it takes 10 to 14 ma to move it.

Actually I originally selected the tiny45 for this project because I wanted to use the on board thermistor. I will look at it again.

Attachment(s):