Attiny25/45/85 FW Development Thread

Ahh, ok. The change of frequency would be a complication I suppose, can be handled though. Also wondering bout the switches. True e-switches are generally made for that. The mechanical rev and fwd clickies are generally not designed for frequent use. I'm pretty fussy bout the feel of the switches on e-switch lights. I much prefer an easier engaged switch, which they seem to be going away from. Mechanical switches to use as an e-switch? Dunno, I'd have to check a few and see.

By the way, the watchdog isn't the only useful timer. I've also setup a TCNT0 timer that I'm using for idle-mode delay loops. The rate in this case is constrained constrained by pwm configuration to 8 overflows per ms, but you I could see faster if I looked at the clock itself instead of overflows, and a 16bit overflow counter can still go out pretty long too if needed. It seems more flexible to me than a watchdog for power-on use, but then you don't always need 1ms resolution. I needed it to sneak idle sleeps into the strobe delays.

No, no.. I'm fine with bistro on clickies. No negativity meant but I'm not sure I'd love the ramping of stuff of Narsil. I'll try it once I have an eswitch light and who knows, may love it. But I was just thinking of this for true e-switch lights, like having bistro for the Q8.

OH.. just got your point about frequency.. in the wake. Yeah, no big deal. I need a timeout after n seconds of wakes to do a couple of things for sure. It's not required to change the frequency, just would help with drain some, but with BODS working, I'm already getting great drain at 1/4s, from an e-switch perspective.

Yea, in NarsilTriple I'm using the ADC complete interrupt for 1.1V ref LVP and temperature reading. DEL developed this code and I integrated it into NarsilTriple. What I like bout his LVP is it's algorithm based, no lookup table, and seems pretty accurate. Plan is to drop it into standard Narsil (2 channel) as well so we can have temp monitoring and lower standby drain in the BLF Q8.

For the Q8, we are already committed to the 2 channel driver design, so too late to convert. DEL has his own 2 channel SRK driver design as well, which I like the look of, but again, all too late for the Q8 project.

Wish I could combine the 2 Narsil source branches into one master - might look into that. Compile switching may get a bit crazy...

The algorithm definitely sounds nice. For Vcc reading though, I just don't believe it will work for accurate battery checks (anything will work for just LVP, you just need to calculate one value and the compiler can do the calculation unless it's UI configurable). Anyway, the Vcc ADC results end up very curved, mostly because of how it must be read.

Yea, under normal circumstances, I've found over a wide range it seems pretty accurate - pulled the cell and tested on a DMM. I'm think'n where it goes astray is under heat, or under load, or both, not sure. The other day thought I saw a reading of 2.n V when the cell actually was 3.2V when pulled.

A table won't do any better as far as those things. If anything you could correct for heat with an algorithm, but that's going a bit overboard in my opinion. It's jut this Vcc curve that's pretty hard to calculate with a machine that can't really do math. In excel I calculated it real accurately, real easily. On attiny85 it could still be done though. It just takes a bunch of bytes. Math takes steps. It's either built into the machine, or it needs instructions, and the attiny25 is stuck either way.

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.

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! :smiley:

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.

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.

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.

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.

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.

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…) :slight_smile:

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.

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.

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?

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.