OTSM in concept?

Hello everyone…

I’m toying around with building a driver from scratch just to learn and have a fun project. There are already tons of really great drivers and firmware out there so my goal isn’t really to create a new better solution but again just to learn and make something myself.

I guess my first question is: does anyone have a simple high level concept of how OTSM works with attiny? I understand how the capacitor idea works but not quite grasping otsm yet. Again just looking for the high level concept.

Thanks !
Jesse

If you have enough power you can keep one of the timers in the attiny running for a while, to measure how long the power has been off. You can use that to detect short/medium/long presses. The timers in the chip are more accurate (especially at low/high temperature) than the usual method, which is to watch a OTC (off-time capacitor) discharge to measure how long the switch has been pressed.

There are some concept explanations here: Texas Avenger "TA" Driver series - Triple channel + Bistro or Narsil + Clicky or E-switch - The Ultimate open source driver!

If you grasp the concept of that, then here is a more technical description:

With OTSM you have an interrupt monitoring power on a IO pin. As soon as power off is detected, the code needs to shutdown everything and put the MCU in to low power sleep mode, waking it up in small periods (0.125 seconds in may case) to check weather power is restored. Each wake up cycle is counted, and this number is read when power is restored. Then you know exactly how long the flashlight was off (with 0.125 accuracy in may case). OTSM requires a larger cap because this is what powers the MCU during these sleep / wake up cycles.

In short, with OTC the flashlight and it’s MCU is truly off. With OTSM the MCU isn’t off, it’s powered by the cap while it measures off time until either the light is turned on or the cap power runs out. So, you need a cap large enough to power the MCU beyond your maximum desired off time.

Thanks this is exactly what i was looking for. Your breakdown was perfect makes sense…I was mainly confused because for some reason i thought otsm eliminated an external cap. Thanks again.

So i guess next question are we writing the saved / last brightness etc to eprom every time we detect a change in settings? Assuming we are saving the last brightness level chosen. Seems like it would wear out the eeprom?

Well, if you look at the ATtiny85 datasheet you will see it is guaranteed to last 100000 write/erase cycles. If you don’t implement wear leveling you have to change mode on average 27.4 times every day for about 10 years before it starts to wear out. Concerned about that? If so, implement wear leveling so that the mode byte address changes. I have dedicated 16 bytes for mode change wear leveling, so I have to change mode 438.3 times per day for 10 years before it wears out, or 43.8 times per day for 100 years. Are you still concerned?

Lol guess that answers that one :slight_smile: Thanks again Mike!

No worries! Keep us updated in your driver progress. It’s always fun to see others progress and there are a bunch of us here who can give you pointers when needed :beer: