Attiny25/45/85 FW Development Thread

1922 posts / 0 new
Last post
Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

ADC Power

 

Been testing some power things to get a feel for some details like pin state settings.

 

While I was at it I tested the ADC in the sleep loop again, now with very different software than before and a little more carefully.  With a 64x adc prescale (standard in bistro) and 1/4 s sleeps it adds 5uA to the average current drain during a loop (where most of the time is speant sleeping)  That's turning the ADC off before entering sleep. It's not actually the ADC power causing that increase though.  The ADC power is small compared to the CPU power.  It's the time that the ADC keeps the loop awake that adds that power.  With a 4x adc prescale, still more than fine for detecting wake, it makes no measurable difference at all to the sleep loop (should be about 16 times less, so about 0.3uA).

That 5uA would go up to 10 for a 1/8s sleep loop (because the relative amount of time on is twice as much)  which would matter even without BODS, but just lowering the prescale fixes it.  I'm not using the ADC in bistro anyway, but I'm not ruling it out as a valid option, and it could be used to reduce voltage constraints the divider.  The open question is still if impacts shutoff detection speed, but I don't see it being the case.  The adc can run pretty fast and these fall times with present hardware are at least 250us.

 

The more important thing I learned is that I don't need to worry about leaving the adc on during normal on time, because the power draw compared to the cpu or even compared to idle clock power isn't much.  That will help with stabilizing ADC reads.  I have things within 0.2V already.  I think (well the manual says so) that switching to the 1.1 Vref as the voltage to measure (what is done with Vcc), requires a few ms of stabilization.  That may be trickier than it seems with the present main loop and thermal measurements with strobes, but I'm sure it's not too bad, just haven't tried to fix it yet. Actually I probably broke in the first place.

 

 

 

LightRider
LightRider's picture
Offline
Last seen: 3 years 9 hours ago
Joined: 08/05/2015 - 09:52
Posts: 2007
Location: U.P. MI, USA

Flintrock, considering your testings do you concider it possible hardware wise, to create a blf four channel driver in the near future. Application mainly RGBW controlling.

DavidEF
DavidEF's picture
Offline
Last seen: 2 weeks 5 days ago
Joined: 06/05/2014 - 06:00
Posts: 7699
Location: Salisbury, North Carolina, USA

LightRider wrote:
Flintrock, considering your testings do you concider it possible hardware wise, to create a blf four channel driver in the near future. Application mainly RGBW controlling.

+1 I want it too! Big Smile

The Cycle of Goodness: “No one prospers without rendering benefit to others”
- The YKK Philosophy

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

You mean will I write one?  Probably not. Is it possible?  I'm not sure. I'm not at all sure 4 channel PWM is possible, but I just don't know. 

 

Of course there's the issue of what pin to put it on.  In an eswitch light or a >1-S light, you'd have to get both switches and the voltage measurements crammed on the same pin (or maybe piggyback the switch and reset pins, hmm..). That would require using the ADC for the switch detection.  That's  possible, but it's not what I have now and it's very significant change, because it requires the adc running full time on interrupt control, switching between channels essentiallly in the background, instead of polling it as bistro is setup for, so a pretty big change.

 

Going to an ADC based system would provide more options, but not sure if I'll do it.

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

That switch on the reset pin might be simpler than the adc route, but it requires a little hardware, diode or resistors, to keep the switch voltage above the reset voltage.

 

Come to think of it, all that only applies if you need the tail switch and e-switch to behave independently, and it's not a big issue for non-eswitch 2S lights (just mis-spoke), just lose one place to add more capacitance.

 

If it's good enough to have the tail switch and e-switch behave the same, they can double up on the divider pin as things are now, with no change. 

Tom E
Tom E's picture
Offline
Last seen: 8 hours 4 min ago
Joined: 08/19/2012 - 08:23
Posts: 14052
Location: LI NY

4 channel PWM is certainly possible. We're doin 3 channels now, and I believe the ATtiny 25/45/85 can do 4 channels with PWM max. But these Atmel's are I/O pin limited, so not the best choice, or could use an external mux. An EE design engineer I work with designed a driver for mux'ing 3 or 4 output channels for a marine application - cockpit lighting, but before he even got to the prototype phase, a pretty much exact matched product came out on the market for a decent price, negating the purpose of producing it. There's been an SRK driver developed using the ATtiny84 a while back, mentioned here, but never open sourced. The 84 has 12 general purpose I/O pins instead of our limited 5 I/O pins, so you got a whole lot more of versatility. It's a 14 pin package though, not 8, so takes more real estate, more complex driver design.

chouster
Offline
Last seen: 1 month 5 days ago
Joined: 02/20/2014 - 15:05
Posts: 746
Location: germany

As it is right now, are the frequencies on all PWM channels the same? I remember TK mentioning somewhere, that running the 1xAMC7135 channel on PB3 maybe isn’t that great of an idea because the higher frequency maybe wouldn’t go that well with realizing nice moon modes.

Tom E
Tom E's picture
Offline
Last seen: 8 hours 4 min ago
Joined: 08/19/2012 - 08:23
Posts: 14052
Location: LI NY

Haven't checked it in that much detail. I was think'n of PWM'ing an indicator LED used as a 4th channel but didn't do the research, just recall seeing it discussed, mentioned, and think the Atmel specs mention PWM can be applied on 4 channels.

LightRider
LightRider's picture
Offline
Last seen: 3 years 9 hours ago
Joined: 08/05/2015 - 09:52
Posts: 2007
Location: U.P. MI, USA

I don’t have a clue about most of this stuff but I did a bit of digging on the subject a while back. 4 pmw channels is definately doable, for sure on the 85, but it was mentioned that the reset pin would need to be forfeited with no reflash ability. I also remember something g about needing the 85 dev board to accomplish it. (At least this is what my notes say, I don’t really remember any of it…) Smile

Tom E
Tom E's picture
Offline
Last seen: 8 hours 4 min ago
Joined: 08/19/2012 - 08:23
Posts: 14052
Location: LI NY

Ohh - if you have the Atmel Dragon (a developer's kit), you can utilize the ability to have the reset pin as an I/O pin and not lose the ability to re-program the 85.

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

I'm pretty sure there are two clocks being used in bistro, and I think two are all that's available, but the clocks are just counters and an "output compare register" sets the duty cycle by matching a particular clock value during the cycle.  I believe two OCR's are sharing one clock.  What I didn't know is if the second clock can be used with two OCR's.  From Tom's answer, it sounds like it can.

 

Yeah,  I think there are ways to squeeze in 4 pins, it just depends on how creative the software is and/or what other features get compromised.  two switches and voltage CAN be done on one pin.  low (maybe < 0.5V) = tail switch power off; mid (from 0.9 to 1.8 maybe) = voltage sense range; high (Vcc) = eswitch engaged.. wired to short voltage pin to Vcc (R2 still means it's not a short to ground). I guess I'm kind of imagining a light where a tail switch cuts power and the eswitch doesn't.  I don't know what really exists.  But even just having two eswitches, the story should be the same. 

 

That can be done if the ADC is used to detect OTSM power-off.   It's just from a bistro perspective, not the way things are being done now.  But if the eswitch instead shorts to ground and behaves the same as the tail switch, then that already would work the way things are now.

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

Hmm another creative way might be to have the eswitch still pull low but not as low.

So < 0.3V = main swtich.  0.5 to 0.9 = eswitch, 0.9 to 1.8V off limits due to pin change tolerance,  > 1.8V = voltage sense.  That would work with the present bistro software. The eswitch would wire from pin 7 to ground with an appropriate series resistor to pull it part way down.  You still detect the switch press with a pin change, but then in the wake loop check the value with the ADC to see which switch hit.  It avoids needing to implement a general ADC interrupt setup.  It could work.  Tail led's complicate things because they shift all the voltages a little, but it could probably all be made to work.  

 

I kind of like it actually.  Can we have resistance inline with the switch wire or it needs to be on the board?  

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

I'm not seeing 4 PWM's.  There are four output compare registers but looking at the pin diagram on page two of the data sheet I don't see how they can be applied to 4 separate pins.  PB3 and PB4 only get OC1B and not OC1B and PB2 gets nothing.  OCOA and OCOB are pb 0 and 1, but OC1A  (and not OC1A) is also only on pb 0 and 1. So I don't see how to make use of OC1A on a new pin.  Maybe I'm missing something.

 

Maybe you can hack this by placing an interrupt on OC1A and "manually" flipping the output of pb3 from an interrupt handler?  Actually this does sound possible.  I'm already running a secondary interrupt off one of the PWM clocks for idle timing, not sure why you couldn't rig something like that. 

Flashy Mike
Flashy Mike's picture
Offline
Last seen: 9 hours 35 min ago
Joined: 01/14/2016 - 16:38
Posts: 1222
Location: Germany

Regarding multiple channels:
There is an alternative to PWM if you need more channels: BAM (Bit Angle Modulation), 8 channels are easily doable (if you have the pins). I did some tests last year and it worked out quite well. It’s a bit tricky to program and I wouldn’t choose this method if I needed smooth ramping with 7135 at low levels.

Regarding the reset pin:
if you use this pin you don’t need expensive programmers for further reprogramming. I built a cheap fuse resetter with this instructions:
http://www.rickety.us/2010/03/arduino-avr-high-voltage-serial-programmer/
I used a arduino nano and a cheap MT3608 boost converter for the 12 V ouput.

Tom E
Tom E's picture
Offline
Last seen: 8 hours 4 min ago
Joined: 08/19/2012 - 08:23
Posts: 14052
Location: LI NY

I'm not sure what you guys are say'n. Certainly we do 3 PWM outputs now, but you see only 2 are possible?

PB4 (pin #3) is PWM'ing now for the FET in BistroTriple and narsilTriple.

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

 

I'm not saying only two are possible.  However, only 3 are possible using the hardware waveform generators.  There are 4 output compare registers but two of them have waveform generators that attach to the same pins.  

 

Anyway, yes, I've figured out how to get 4 in principle.  You need to leave the 4th compare register detached from the pin, and enable its(the register not the pin) interrupt, and use the interrupt to  bit-bang the OTC pin. In phase mode you need to keep track of ups and downs.  (why are we using phase-correct mode though?)

It's not too bad really. The datasheet recommends against it because it will keep the CPU busy.  On the other hand, what else is this CPU busy doing hunh?  It's not like we're going to connect these lights to SETI are we?  I shouldn't ask. 

 

Sigh.. the tripple version was clearly whipped up a littel quickly to work and was no longer compatible with single and double versions anyway, so I've started cleaning that all up and adding capability for a fourth channel too. It does mean ramps don't have nice names anymore but are just RAMP_PWM1 ... etc, but calling it 7135s just inhibits keeping the code flexible.  

 

 I've also simplified the defines to maybe make configuring creative driver setups a bit easier.  I don't promise TK would approve of all the changes.  Maybe someday I'll even finish something.  

 

Oh someone asked about frequency.  As far as I can tell bistro tripple is running at CPU frequency.  The PWM ramps up to 255, but the 7135 and 7135s are in phase mode so it ramps up and down, so that's a frequency of 8Mhz/500 so 16khz.  The FET doesn't have a phase correct option and appears to me to be running at 32 khz!  Unless I'm missing something.  

LightRider
LightRider's picture
Offline
Last seen: 3 years 9 hours ago
Joined: 08/05/2015 - 09:52
Posts: 2007
Location: U.P. MI, USA

This is one of the examples I found that created four pwm outputs on the 85.

http://www.technoblogy.com/show?LE0

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

This stuff gets a little silly now:

 

#ifdef PWM4_LVL
inline void set_output(uint8_t pwm1, uint8_t pwm2, uint8_t pwm3, uint8_t pwm4) {
#elif defined(PWM3_LVL)
inline void set_output(uint8_t pwm1, uint8_t pwm2, uint8_t pwm3) {
#elif defined(PWM2_LVL)
inline void set_output(uint8_t pwm1, uint8_t pwm2) {
#else
inline void set_output(uint8_t pwm1,) {
#endif


but it actually does save a few bytes over using globals. It kind of just went from one to two, and then someone hacked a third on, and  now it's kind of silly.

 

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

LightRider wrote:
This is one of the examples I found that created four pwm outputs on the 85. http://www.technoblogy.com/show?LE0

[/quote]

 

Exactly the way I've headed with it. Interrupt for the 4th, like I said.  Apparently I can figure that out, but not how to end a quote after a link.

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

Ok, it's now configurable to use any combination of 4 outputs, trying to get the hardware defines more simplified and flexible too.

LightRider
LightRider's picture
Offline
Last seen: 3 years 9 hours ago
Joined: 08/05/2015 - 09:52
Posts: 2007
Location: U.P. MI, USA

Oh ha, and this was another example of software PMW on four channel.

http://www.instructables.com/id/Software-PWM-with-arduinoattiny/

Seems you have surpassed this info already though. Great work!

DavidEF
DavidEF's picture
Offline
Last seen: 2 weeks 5 days ago
Joined: 06/05/2014 - 06:00
Posts: 7699
Location: Salisbury, North Carolina, USA

Flintrock wrote:

LightRider wrote:
This is one of the examples I found that created four pwm outputs on the 85. http://www.technoblogy.com/show?LE0


 


Exactly the way I’ve headed with it. Interrupt for the 4th, like I said.  Apparently I can figure that out, but not how to end a quote after a link.

You had one too many end-quotes. Wink

The Cycle of Goodness: “No one prospers without rendering benefit to others”
- The YKK Philosophy

Tom E
Tom E's picture
Offline
Last seen: 8 hours 4 min ago
Joined: 08/19/2012 - 08:23
Posts: 14052
Location: LI NY

This all sounds great Flintrock! I gotta get a looksy when you post it all. Quick read of the article as well...

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

Well, distracted with this

http://budgetlightforum.com/node/52604

 

And by the way, things are bit broken now.  I said I implemented it, but I've done a bunch of "clean" up and reorganizing and  who knows how long it will take me to recover from that. I haven't even tried to run it yet.  I already know of one thing I broke (a feature that I added though), but I'm not going backwards.  I'll twiddle at getting it all in shape as I get time.

Texas_Ace
Texas_Ace's picture
Offline
Last seen: 1 week 3 days ago
Joined: 03/24/2016 - 07:44
Posts: 9036
Location: Everything is brighter in Texas

thats way over my head lol

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

Facepalm  It  ended up being just a dumb mistake.  After all that I deleted it.  I just didn't have optimization on at the time, doh. 

 

Some days are like that programming.  You know like when waste a bunch of time just to figure out the program you're running is in a different directory than the one you're compiling, which explains why the last 10 ways you tried to fix it didn't work.  I'm pretty sure anyone who's programmed much has done that one before... or maybe it's just me.

Tom E
Tom E's picture
Offline
Last seen: 8 hours 4 min ago
Joined: 08/19/2012 - 08:23
Posts: 14052
Location: LI NY

I can vouch for that, for sure.... Was gonna ask bout the S optimize setting, but thought that was little insulting smilefrown. Anything one could get wrong, I've done, I'm sure. All a matter of how fast you can figure it out. Many times I come in the next morning and it's obvious, staring me in the face.

Flintrock
Offline
Last seen: 3 years 3 months ago
Joined: 09/10/2016 - 20:29
Posts: 1544

So here's a new one.  Vcc ADC reading seems to mess with the light a bit.

 

I did of bunch of recent changes without testing, just getting the code organized, surprised things mostly work still, but they seem to.  Except the light had a pule, a heartbeat.  After  burning through another 20 flashes on this poor attiny's life it boiled down to the adc being on and set to the Vcc reference, and having changed the timing of things I noticed now when not before.  In fact I intentionally was cycling the ADC on longer between voltage and thermal mode to stabilize readings, but  that's the heartbeat.  Of course ADC_on was the last thing I suspected.  It seems that an adc reference on the Vcc pin is disturbing the electronics and dims (we don't want dim) the light a little.

 

It's a full single 7135 mode, no PWM.  Being a regulator I'd hope it wouldn't be too sensitive to a little voltage fluctuation.  I have found these things are pretty finicky,very  easy to break entirely.  Maybe I should replace the 7135 and see what happens.

Tom E
Tom E's picture
Offline
Last seen: 8 hours 4 min ago
Joined: 08/19/2012 - 08:23
Posts: 14052
Location: LI NY

Sorry if I missed something, but if the opamp gives use true regulation, why do we need a 7135? Couldn't the FET give use everything we need?

Texas_Ace
Texas_Ace's picture
Offline
Last seen: 1 week 3 days ago
Joined: 03/24/2016 - 07:44
Posts: 9036
Location: Everything is brighter in Texas
Tom E wrote:

Sorry if I missed something, but if the opamp gives use true regulation, why do we need a 7135? Couldn’t the FET give use everything we need?

The opamp driver is not released yet, DEL has not been able to look at it to see if it is even ready for release.

He is dealing with the normal Avenger driver.

Pages