Attiny25/45/85 FW Development Thread

1911 posts / 0 new
Last post
Fritz t. Cat
Fritz t. Cat's picture
Offline
Last seen: 1 year 10 months ago
Joined: 05/07/2013 - 00:33
Posts: 2535
Location: Si Valley

Is it the time it take the heat to get from the LED to the sensor that you are compensating for?
The LED won’t get any hotter after you reduce the current.

Flashlight designers should look at lighthouses and pottery.
这些谁设计的手电筒应该看灯塔,以及在陶器。

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

Just modded my SupFire M6 to add the indicator LED and light pipe, then upgraded the 85 to the latest Narsil. I used this light pipe: mouser-LPCM050CTP, only $0.56 each. Came out nice! The 3 LED's will work on a PWM setting of 2 for moon mode, and I measured a true 0.1 lumens on fresh SAM 30Q BT's. On hi, measured lumens: 5202 @start, 4991 @30 secs. It's got U3 2A XM-L2's on 20 mm Noctigons, 20 AWG wires.

I think the brightness of the indicator came out really nice using a 1K resistor with an orange LED, mounted tombstone style on a ground pad, directly in front of the light pipe (had to align the old driver/contact board up). It's bright enough to see in a well lit room, but not too bright, and mounted next to the button makes it easy to find the button in the dark. Here's some pics:

The 1K resistor, also tombstone style mounted on a pad from pin #3. The blue wire is for the switch (pin #2):

The light pipe is about 11mm long, while the M6 thickness is about 8 mm, but because I could set the LED position a bit back on the board, it matched up pretty well:

 

Regular office light:

Here's the 0.1 lumens 2 PWM setting:

wight
Offline
Last seen: 7 months 1 week ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA

Fritz t. Cat wrote:
Is it the time it take the heat to get from the LED to the sensor that you are compensating for?
The LED won’t get any hotter after you reduce the current.
Err, it won’t? The LED’s temperature doesn’t simply “track” with input current. Think about it – this is just like an electric oven. Reducing the input current may or may not reduce the temperature – it depends on ambient temp, what’s around the oven, and whether you reduced the current from 100% to 80% or maybe 50% to 30%. Somewhere in there exists a “steady state” break point – above that point temperature will rise and below it temperature will fall.

For this application using lookup tables is tricky: they only fully function when they are created with knowledge of the many variables (LED, battery, light mass, external mass, ambient temp). Holding or not holding the flashlight makes a huge difference, but how do we know which lookup table to use (hand vs. no-hand) at any given time?

PID lets us dodge almost everything, I think. (can you tell that I’ve got stars in my eyes?) You brought up slow/laggy measurements – that may be an issue, I’m not really certain. My immediate take is that whether it’s an issue depends on your goal: I think most of us are ignoring the LED temp and are only interested in maintaining flashlight usability with very high power setups. (someone please let me know if I’m wrong!) In the case of maintaining usability, getting laggy temp measurements isn’t really a big deal – they’ll be reasonably close to “flashlight surface” temps and we should be able to tune the PID settings to achieve the right performance. To re-iterate – for me the “right” performance is a flashlight which I can continue to grip without burning myself, but also a flashlight that will not become scalding hot if I set it down on a table for 60s.

Tom E wrote:
Just modded my SupFire M6 to add the indicator LED and light pipe, then upgraded the 85 to the latest Narsil. I used this light pipe: mouser-LPCM050CTP, only $0.56 each. Came out nice! The 3 LED’s will work on a PWM setting of 2 for moon mode, and I measured a true 0.1 lumens on fresh SAM 30Q BT’s. On hi, measured lumens: 5202 start, 4991 30 secs. It’s got U3 2A XM-L2’s on 20 mm Noctigons, 20 AWG wires.

I think the brightness of the indicator came out really nice using a 1K resistor with an orange LED, mounted tombstone style on a ground pad, directly in front of the light pipe (had to align the old driver/contact board up). It’s bright enough to see in a well lit room, but not too bright, and mounted next to the button makes it easy to find the button in the dark. Here’s some pics:

http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
The 1K resistor, also tombstone style mounted on a pad from pin #3. The blue wire is for the switch (pin #2):
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
The light pipe is about 11mm long, while the M6 thickness is about 8 mm, but because I could set the LED position a bit back on the board, it matched up pretty well:
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
Regular office light:
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...
Here’s the 0.1 lumens 2 PWM setting:
http://i1054.photobucket.com/albums/s496/TomE2012/Custom%20Mods/SupFire%...

Very slick Tom E, good work. What type of wire are you using for your little hookup wires? The sheathing on the green wire which goes to the LED caught my eye as odd…

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

Halo...
Halo...'s picture
Offline
Last seen: 4 years 2 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Soo, the tiny25/45/85 includes a useful extra feature which I should point out over here. They can measure vcc internally. No pin or voltage divider resistors needed. See my post here: http://budgetlightforum.com/comment/910199#comment-910199

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

wight - that green wire is really old stuff I had laying around, not sure from where. It's maybe 3-4" with a large amt of the ends stripped - that's why a good amt is bare, it was partially used already. Guess'n it's bout 30 AWG single strand. Think'n it was wire wrap wire? Looks like this wire wrap pre-cut here.

Halo - that sounds interesting! I'm surprised the 1.1v ref would drop same as a direct batt readings, but I don't claim to understand these MCU's for sure.

wight
Offline
Last seen: 7 months 1 week ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA

Aha, thanks. I misunderstood what I was seeing before.

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

Halo...
Halo...'s picture
Offline
Last seen: 4 years 2 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Tom E wrote:
I’m surprised the 1.1v ref would drop same as a direct batt readings, but I don’t claim to understand these MCU’s for sure.
:-/ Sorry, I didn’t follow that.
Your variable vcc is set as the reference then you measure the stable 1.1v. It’s backwards from how you normally set up measurements

~ edited ~

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

Ahh, ok. Think I kind of/sort of understand. The 1.1v source is always a true 1.1v, but the reference source to read it is Vcc, used as the comparison for measuring 1.1v, so what you read will vary as the Vcc reference source varies. The resolution is less because you are reading 1.1v instead of a true batt+ level, I suppose, so almost 4X less resolution.

wight
Offline
Last seen: 7 months 1 week ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA

I’m actually still a little unclear on how this works Halo. Previously I suppose we were doing “single ended” measurements where we compared the voltage from our hardware voltage divider against a 1.1v bandgap. You’ve proposed measuring the 1.1v bandgap against Vcc (~4v for example).

I think I’m following you now Tom E. Are we thinking that 4v might yield a value of ~281/1023 and 3v might yield a value of ~375/1023? That doesn’t seem like a very large delta, but let’s stretch this out.

4.2v - 268
4.1v - 274
4v - 281
3.9v - 289
3.8v - 296
3.7v - 304
3.6v - 313
3.5v - 322
3.4v - 331
3.3v - 341
3.2v - 352
3.1v - 363
3v - 375
2.9v - 388
2.8v - 402
2.7v - 417
2.6v - 433
2.5v - 450

That actually looks much better. For our purposes we generally care about something like 4.2v through 2.8v I believe, so we’ve got about 134 measurement points in there. This is approximately double the resolution we normally have since we normally get 8-bit measurements ranging from the low hundreds to the high hundreds (120 through 190 or something like that).

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

Halo...
Halo...'s picture
Offline
Last seen: 4 years 2 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

I actually have / had some example code. I'm looking for it.

~ edit ~

  long readVcc() {
  ADMUX = _BV(MUX3) | _BV(MUX2);   // Set reference to Vcc and measurement to internal 1.1V bandgap
 
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
 
  uint8_t low  = ADCL; // must read ADCL first, it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
 
  long result = (high<<8) | low;
  //Note: might need to discard first result
 
  result = 1125300L / result; // Calculate Vcc in millivolts; 1125300 = 1.1*1023*1000
  return result;
}
ImA4Wheelr
Offline
Last seen: 3 months 1 week ago
Joined: 02/03/2013 - 14:51
Posts: 7932
Location: SC

Awesome Halo…. So dump the voltage divider and free up a pin? Sounds great. Would need of to factor for voltage drop if using a reverse polarity protection diode. Guess a voltage divider and pin would still be needed if using 2S or more cells. Especially, if using a voltage regulator chip to power the MCU.

Sweet mod up in Post 755 Tom E.

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

I think this Halo method for measuring voltage would have a big advantage for e-switch lights in parasitic drain. I could be off on this, not sure, but using V = I * R, would the 4.7K and 22K resistors we use result in about a 0.157 mA drain by itself? This was probably discussed somewhere in the past I would think. Can anyone confirm, theoretical or otherwise? I’m measuring about 0.300 mA parasitic drain on a few of my e-switch lights, while a NC MH20 (0.027 mA) and SWM C20C (0.009 mA) are much lower.

wight
Offline
Last seen: 7 months 1 week ago
Joined: 11/27/2013 - 16:40
Posts: 4969
Location: Virginia, USA

For single cell momentary applications if we eliminate both resistors and the polarity protection diode we should have enough space to use a mosfet for polarity protection. This would eliminate almost 100% of the voltage drop we currently see while using a diode for polarity protection.

EDIT: At least with the older boards. The “new stuff” like A17DD-L v30+ is still in flux and already packed super tight, but I’d certainly like to implement a PCB to use this technique for momentary stuff.

Still fine, still on a break. One day I’ll catch up with you folks! previous wight catchup Wink
list of my drivers & variants (A17DD, FET+1 stuff, WIP stuff, etc)

Halo...
Halo...'s picture
Offline
Last seen: 4 years 2 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Sharpie wrote:
The Halo idea for Vbat measurement

I’d like to note that I didn’t come up with it. Heard about it, went looking for an example, then half forgot about.
I heard about it in relation to a different AVR originally. But saw that it’s also available for attiny25/45/85. Not an option with tiny13 though. This was before attiny25/45/85 came into use.
Fritz t. Cat
Fritz t. Cat's picture
Offline
Last seen: 1 year 10 months ago
Joined: 05/07/2013 - 00:33
Posts: 2535
Location: Si Valley

wight wrote:
Fritz t. Cat wrote:
Is it the time it take the heat to get from the LED to the sensor that you are compensating for?
The LED won’t get any hotter after you reduce the current.
Err, it won’t? The LED’s temperature doesn’t simply “track” with input current. Think about it – this is just like an electric oven. Reducing the input current may or may not reduce the temperature – it depends on ambient temp, what’s around the oven, and whether you reduced the current from 100% to 80% or maybe 50% to 30%. Somewhere in there exists a “steady state” break point – above that point temperature will rise and below it temperature will fall.

For this application using lookup tables is tricky: they only fully function when they are created with knowledge of the many variables (LED, battery, light mass, external mass, ambient temp). Holding or not holding the flashlight makes a huge difference, but how do we know which lookup table to use (hand vs. no-hand) at any given time?

PID lets us dodge almost everything, I think. (can you tell that I’ve got stars in my eyes?) You brought up slow/laggy measurements – that may be an issue, I’m not really certain. My immediate take is that whether it’s an issue depends on your goal: I think most of us are ignoring the LED temp and are only interested in maintaining flashlight usability with very high power setups. (someone please let me know if I’m wrong!) In the case of maintaining usability, getting laggy temp measurements isn’t really a big deal – they’ll be reasonably close to “flashlight surface” temps and we should be able to tune the PID settings to achieve the right performance. To re-iterate – for me the “right” performance is a flashlight which I can continue to grip without burning myself, but also a flashlight that will not become scalding hot if I set it down on a table for 60s.

I am trying to imagine what a PID might be. As I understand it, there is a heat sensor either on the driver board or on the LED’s star. If it’s on the driver, then there is a delay and a steady state reduction in temperature from the LED to the driver, and these might be more or less than the delay and the steady reduction from the LED to the flashlight body. There is also heat originating in the FET, but without or with a small gate resistor that is small. So I don’t see how to do much better than regulating the current to keep a constant sensor temperature. One will have to try it to decide on that temperature, but is should be somewhere around the desired flashlight body temperature. It will be cooler when you hold it or the wind blows than not, but not by a huge amount because that will cool the driver through the star and increase the current.
The LED temperature will overshoot because of the delay and have a higher steady temperature than the driver, but maybe it can take that. I don’t see a possibility for doing a lot better than just a simple thermostat.
On the other hand, you do need also to know how much to reduce the current on the first step, so the light output doesn’t vary too much. After that things will change more slowly.
Also, the gain of the thermostat can’t be too high, or with the delay, it will oscillate, turning the light off and on. That is, the table or whatever has to be over some range of temperature.

Flashlight designers should look at lighthouses and pottery.
这些谁设计的手电筒应该看灯塔,以及在陶器。

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

Hhmm – I should really try measuring the sleep mode amps on a board without the diode or resistors – fairly easy to do… Dunno if anyone did that before.

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

Double posting this here as well: http://budgetlightforum.com/node/29150

I did the tests. First removed the diode, bridged the pad with solder, and saw absolutely no difference in the parasitic drain at all - zero, nothing. Still doing in the 0.30 to 0.32 mA range.

Then I pulled the 22K resistor. The light acted kind of weird, because I didn't re-burn the MCU with firmware not supporting LVP. Anyway, it would settle down, and go into its sleep state. There I measured in the 0.16 mA range, which is about exactly what I expected - it went to half the draw, as calculated from the resistor values.

So, not sure why the diode had no effect or did I mis-understand if it was supposed to help?

Btw, in terms of draw over time, a 0.16 mA steady draw would drain a cell 1 Ah in 260 days, if I did the math correct.

DEL
DEL's picture
Offline
Last seen: 2 years 8 months ago
Joined: 06/28/2015 - 08:35
Posts: 559
Location: Canada
Tom E wrote:
First removed the diode, bridged the pad with solder, and saw absolutely no difference in the parasitic drain at all – zero, nothing. Still doing in the 0.30 to 0.32 mA range. .

So, not sure why the diode had no effect or did I mis-understand if it was supposed to help?

The diode is in series with the MCU. Bridging it cannot improve the parasitic drain. If anything that gives a slightly higher voltage to the MCU, which may increase the drain ever so slightly. If there was a diode+drain related discussion it may have been about the zener diode used on 6 V drivers? That arrangement forms a type of shunt regulator, with a huge parasitic drain by definition.

Still a mystery where the other 0.160 mA is going. Your fuse values indicate that you are not using BOD, so that is good.
Maybe some MCU peripherals are not shutting down properly during sleep?

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

Thanks DEL – yep, that’s what I’m thinking – something else that’s not getting shut down. Spoke last night to my EE buddy here and he said the same thing bout the diode we are using. He also mentioned these diodes will consume voltage though when the MCU is drawing power, so I think I need to know exactly what the draw is. Using the “85” and not the “85v” rated at 2.7v minimum, means you can’t afford to loose much voltage via the diode. Think’n the drain was 0.1-0.2 volts from what I recall, which means our LVP needs to cut off no less than 2.9v. I believe the loss’s caused by the diode is why we moved the voltage divider resistors before the diode, and are using a 22K instead of the 19.1K.

Haven’t had a chance yet, but I need to dive deep into the Atmel 25/45/85 specs to see if we are missing something on sleep mode. I am aware that you have control of several sub-systems for sleep/low power.
Yep, I heard bout the brown-out taking amps in sleep mode – the details were posted here a while back.

DEL
DEL's picture
Offline
Last seen: 2 years 8 months ago
Joined: 06/28/2015 - 08:35
Posts: 559
Location: Canada
Tom E wrote:
He also mentioned these diodes will consume voltage though when the MCU is drawing power, so I think I need to know exactly what the draw is. Using the “85” and not the “85v” rated at 2.7v minimum, means you can’t afford to loose much voltage via the diode.

You can assume a 0.25 V drop for the Schottky-type diodes we are using (or try to measure it while the MCU is running, it does vary with current and temperature.)

There is a discussion in one of the threads to replace D1 with a ‘boot-strapped’ PMOS FET – this would give practically zero voltage loss.

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

I don’t think it’s necessary to replace the diode to reduce the draw, it’s just that with an “85”, you have to be extra careful with your LVP cutoff value. The 2.7v is actually 2.95v then, therefore, your cutoff point should be 3.0v or 3.1v for a little cushion. When I bought my ATTiny85’s from Mouser or DigiKey, I bought the 85V’s but the last batch I bought from RMM are the “85”‘s.

Mike C
Mike C's picture
Offline
Last seen: 3 weeks 3 days ago
Joined: 01/22/2014 - 08:03
Posts: 2486
Location: Sweden

What driver are you using? I always take the cell voltage measurement before the diode. I thought that’s what everyone else did too.

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

wight’s FET+1 and MntE’s FET+1 board, reflowed myself. Cell voltage before the diode? Not sure I understand – I’m just measuring at the same place I always measure amps – at the tail: between batt- and the edge of the battery tube.

Halo...
Halo...'s picture
Offline
Last seen: 4 years 2 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

A tiny85 won’t drop dead at 2.69v. Atmel just does not guarantee they will remain reliable outside the specs. The official specs are often conservative. People can and do run them a bit outside of specs and have no problems. Some even sell devices that use AVRs running outside of specs. I believe, iirc boards from jeelabs are (or were) running at a clock speed + voltage that is outside of spec and he said he never ran into a problem even among hundreds of chips.

Also what speed are you running at? You can increase reliability by running at a lower clock speed (like 4Mhz) + you’ll get a bit of power savings. I posted awhile ago, somewhere Big Smile probably this thread, code to use the clock prescaler to adjust the speed beyond the options that the fuses give you.

~ edit ~
Yep, using our nifty new “search within thread” feature it comes up by searching “clkpr”.

Halo… wrote:
CLKPR divides the clock.
6.5.2 of the datasheet, page 32-33.
This should do 4mhz if I’m not mistaken.

// special procedure required to change clock prescaler
cli();                                // Interrupts must be disabled
CLKPR=(1<<CLKPCE);   // Enable clock change for next 4 cycles
CLKPR=1;                       // Clock/2, 4mhz
sei();                               // Re-enable interrupts

I have not tested this. My lights aren’t having any problems and my tiny85 is in use.
Reducing the clock also reduces power consumption. Smile
Apparently, I was talking to some guy named Tom E in the above quote. So, I guess it’s nothing new to you? Oops
Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

I forget far more than I remember. It’s dejavu all over again. I recall reading this and maybe other posts about it, but it’s untested, and I thought incomplete at the time. There’s 2 timed things I need – the 16 msec timer (or need to know exactly what it is), and the built-in _delay_ms() routine, so any change that impacts these is a problem. I don’t have any decent development/debug capabilities with these parts, and not much time to explore these things with unknown advantages? I am looking to lower sleep mode parasitic drain, and don’t see the relationship between processor speed and parasitic drain. Sorry, I haven’t had time to do the crazy hours of research on this.

Don’t get me wrong – all good ideas, but don’t ask me to go off and take the risk of time for a possible benefit, which I’m not clear on. I am very handcuffed with this firmware development environment from what I’m used to, lacking single step level debugging, profiling, etc., so experimenting is very time consuming.

I am very committed to 8 Mhz right now because I know it works. I haven’t seen anything posted in detail, fully working, or fully explained and tested to work, at lower speeds. Again, no time for the R&D. Early on I tried a lower speed via the fuses, and timing of something was way off, even though I thought I made all the proper settings. This, of course, is a shame because others are doing this I’m pretty sure, but I just can’t find the source code and/or fuse settings, etc., or they are unwilling/not allowed to post it.

Halo...
Halo...'s picture
Offline
Last seen: 4 years 2 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

I sometimes feel like I forget far more than I remember as well. Glad I’m not alone. Big Smile

ToyKeeper mentioned testing it here. Not sure how it effects _delay_ms() and the 16 msec timer you’re using. But it should be one of two possibilities, cuts it in half or no effect. About power savings, I don’t have any links off hand but I’ve also seen people test combinations of different levels of sleep with different clock speeds to verify what you get in the real world. I expect the savings to be minor. I brought it up more because you’re concerned about the tiny85 being rated at 2.7v minimum. Even with the tiny85v you’re not suppose to go below 2.7v if your running at 8MHz. 4Mhz is the max (officially) for the 1.8-2.7v range.

Halo...
Halo...'s picture
Offline
Last seen: 4 years 2 months ago
Joined: 12/15/2011 - 02:39
Posts: 3304
Location: Halo island

Are you disabling adc before power down sleep?
(ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off)

(ADCSRA |= (1<<ADEN)) // re-enable ADC

You’re not using the watchdog, right?

Mike C
Mike C's picture
Offline
Last seen: 3 weeks 3 days ago
Joined: 01/22/2014 - 08:03
Posts: 2486
Location: Sweden

Tom E wrote:
wight’s FET+1 and MntE’s FET+1 board, reflowed myself. Cell voltage before the diode? Not sure I understand – I’m just measuring at the same place I always measure amps – at the tail: between batt- and the edge of the battery tube.

If the voltage divider gets the voltage before the diode, then the voltage drop of the diode is irrelevant for LVP readings. I design all my drivers this way and just assumed that everyone else did too. I guess I shouldn’t be assuming so much.

Before diode:

After diode:

Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

Halo... wrote:
Are you disabling adc before power down sleep? (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off) (ADCSRA |= (1<<ADEN)) // re-enable ADC You're not using the watchdog, right?

Crap - not turning that off. Not sure who wrote wrote the sleep mode function originally, probably Johnny C? So I do use the watchdog but it's being turned off, but the ADC is not being shut OFF then ON. Below are the functions form Narsil, but again, originally ported over, probably from STAR Momentary:

 

/**************************************************************************************
* ADC_on - Turn the AtoD Converter ON
* ======
**************************************************************************************/
inline void ADC_on() {
// For 13A: ADMUX  = (1 << REFS0) | (1 << ADLAR) | ADC_CHANNEL; // 1.1v reference, left-adjust, ADC1/PB2

   ADMUX  = (1 << REFS1) | (1 << ADLAR) | ADC_CHANNEL; // 1.1v reference, left-adjust, ADC1/PB2

   DIDR0 |= (1 << ADC_DIDR);                    // disable digital input on ADC pin to reduce power consumption
   ADCSRA = (1 << ADEN ) | (1 << ADSC ) | ADC_PRSCL;   // enable, start, pre-scale
}

/**************************************************************************************
* ADC_off - Turn the AtoD Converter OFF
* =======
**************************************************************************************/
inline void ADC_off() {
   ADCSRA &= ~(1<<7); //ADC off
}
void sleep_until_switch_press()
{
   // This routine takes up a lot of program memory :(
   // Turn the WDT off so it doesn't wake us from sleep
   // Will also ensure interrupts are on or we will never wake up
   WDT_off();
   // Need to reset press duration since a button release wasn't recorded
   pressDuration = 0;
   // Enable a pin change interrupt to wake us up
   // However, we have to make sure the switch is released otherwise we will wake when the user releases the switch
   while (is_pressed()) {
      _delay_ms(16);
   }
   PCINT_on();
   // Enable sleep mode set to Power Down that will be triggered by the sleep_mode() command.
   //set_sleep_mode(SLEEP_MODE_PWR_DOWN);
   // Now go to sleep
   sleep_mode();
   // Hey, someone must have pressed the switch!!
   // Disable pin change interrupt because it's only used to wake us up
   PCINT_off();
   // Turn the WDT back on to check for switch presses
   WDT_on();
   // Go back to main program
}
Tom E
Tom E's picture
Offline
Last seen: 1 hour 15 min ago
Joined: 08/19/2012 - 08:23
Posts: 13394
Location: LI NY

Mike C – yes, thanks for the info. Yep, I understand the impact of the diode on the voltage divider. Think someone said earlier the drop from the diode we use is 0.25v. This is why we used a 19.1K initially in Nanjg’s but use a 22K now (before the diode) to get about the same A-D values.
If the wight FET+1 thread, someone mentioned using 10X the resistors: 220K and 47K. Not sure if it’s possible to read them, but that would be great if we could. It would cut the parasitic drain to 10% of the 0.16 mA the voltage divider is taking now, if I understand it all correctly.

So, I do have some marching orders from this – add turning off the AtoD converter for sleep (simple to try), and gotta find out more bout the voltage divider resistor values. Again, not sure if CPU speed effects parasitic drain, but if it did, might be minor compare to the voltage divider problem. I’d like to have the time to research the 1.1v ref reading proposed solution – not sure I can do this, without lots of time.

Pages