Skip to main content

ESPCLOCK4 - A Rethink On Tick Pulse Generation

Having dabbled recently with PWM (Pulse Width Modulation) for motor control, it struck me that maybe the same technique can be applied for pulsing the Lavet stepper motor in the analog clock.

Just a recap. The Lavet stepper motor within the analog clock is design to function at ~1.5V. However, the output on the ESP8266 and ESP32 is 3.3V, and in ESPCLOCK3, the ATtiny85 is powered at ~3V. For reasons I don't fully understand, the pulse width needs to be as long as 100ms in this case, otherwise the clock will not tick reliably. This also leads to high power draw, because higher voltage + longer pulse width. In contrast, the original clock signal is 32ms pulse width at ~1.5V (which can go as low as ~1.1V since it is running on a normal AA battery).

So in ESPCLOCK3, a diode bridge is introduced, where 2 diodes in each direction drops the 3V output by the ATtiny85 down to ~1.8V (3V - 0.6V x 2), which worked remarkably well in reducing the power draw and making the clock tick with 100% reliability.

Much like PWM in DC motor control, the idea is to eliminate the diode bridge and instead output a PWM modulated pulse signal, which should reduce the effective voltage to the clock.


With some experimentation, the ideal duty cycle of the PWM was found to be 62.5%. The output is 1.25ms on, 0.75ms off, repeated 20 times (for a total of 40ms). Both 62.5% and 40ms were found to be lower bounds for reliable operation.

The 62.5% duty cycle surprised me, because from my naive calculation, for an effective voltage of say, 1.5V, the duty cycle should be 1.5 / 3.3, which is 45%. 62.5% duty cycle implies an effective voltage of ~2V, which is much higher than I expected. I suspect my naive formula for calculating the duty cycle is wrong.

It was quite easy to modify the test program to output PWM pulses. This macro was added:

// Pulse given tickpin - 40ms duration = 20 x (1.25/2ms) PWM => 62.5% duty cycle ~ 2V
#define X_TICK_PIN(pin) \
    I_MOVI(R0, 20), \
  M_LABEL(_PULSE_##pin), \
    X_GPIO_SET(pin, 1), I_DELAY(10000), \
    X_GPIO_SET(pin, 0), I_DELAY(16000-10000), \
    I_SUBI(R0, R0, 1), \
    M_BGE(_PULSE_##pin, 1)

The macro is then used in the ticking logic:

    // Decide which pin to tick
    X_RTC_LOAD(TICK_PIN, R0),                           
    M_BGE(_HANDLE_TICKPIN2, 2), 
    // Pulse tick pin 1
    X_TICK_PIN(TICKPIN1),
    X_RTC_SAVEI(TICK_PIN, 2),
    I_HALT(),
  M_LABEL(_HANDLE_TICKPIN2),
    // Pulse tick pin 2
    X_TICK_PIN(TICKPIN2),
    X_RTC_SAVEI(TICK_PIN, 1),
    I_HALT()

I was pleasantly surprised this worked very well. It made the clock tick reliably without the diode bridge. Even better, this approach brought the power draw from 1.37mA down to 1.13mA, so it's a keeper!

Comments

  1. What would the code equivalent for X_TICK_PIN be if I want to drive the clock using PCA9685 https://www.nxp.com/products/power-management/lighting-driver-and-controller-ics/ic-led-controllers/16-channel-12-bit-pwm-fm-plus-ic-bus-led-controller:PCA9685 via ESP32 ?

    ReplyDelete
    Replies
    1. Apologies, but I am not mighty familiar with the PCA9685. But it's just a standard PWN signal. As long as you can program it to output a PWN signal on one of its pins, you can play around with the duration and duty cycle of the signal. It doesn't take long to find the approximate duration/duty-cycle to use for a particular clock. It takes longer to home in on the right values for reliable operation. Sometimes slippages will occur after 10 or 20 minutes, so it is not sufficient to let the clock run for only a few minutes.

      Delete
    2. Will try that next week. Was being lazy and trying to get the conversion of your X_TICK_PIN code to more standard PWM code :)

      Delete

Post a Comment

Popular posts from this blog

Update: Line adapter for Ozito Blade Trimmer

Update (Dec 2021): If you access to a 3D printer, I would now recommend this solution , which makes it super easy to replace the trimmer line. I have been using it for a few months now with zero issue.

Attiny85 timer programming using Timer1

This Arduino sketch uses Timer1 to drive the LED blinker: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /* * Program ATTiny85 to blink LED connected to PB1 at 1s interval. * Assumes ATTiny85 is running at 1MHz internal clock speed. */ #include <avr/io.h> #include <avr/wdt.h> #include <avr/sleep.h> #include <avr/interrupt.h> bool timer1 = false , led = true ; // Interrupt service routine for timer1 ISR(TIMER1_COMPA_vect) { timer1 = true ; } void setup() { // Setup output pins pinMode( 1 , OUTPUT); digitalWrite( 1 , led); set_sleep_mode(SLEEP_MODE_IDLE); // Setup timer1 to interrupt every second TCCR1 = 0 ; // Stop timer TCNT1 = 0 ; // Zero timer GTCCR = _BV(PSR1); // Reset prescaler OCR1A = 243 ; // T = prescaler / 1MHz = 0.004096s; OCR1A = (1s/T) - 1 = 243 OCR1C = 243 ; // Set to same value to reset timer1 to

Line adapter for Ozito Blade Trimmer

This is an adapter for Ozito 18V battery trimmer (and possibly some Bosch trimmers as well) that uses a plastic blade for cutting. It lets you insert a 2.4mm trimmer line (about 8cm long) and use that for cutting. Simply cut a length of trimmer line and briefly heat up one end with a lighter so that a little bulb is formed. Then insert the trimmer line into the adapter and slot that into the trimmer as per normal. Make sure the trimmer line is not so long that it touches the safety guard. If that is the case, simply trim off any excess with a cutter or scissors. This part is best printed using PETG, which is a tougher and more flexible material. PLA is more rigid and breaks more easily. However, even with PETG, it will still break when it hits something really hard. Since this takes only 0.5m of material and 15 minutes to print, I will usually print a batch of nine at a time at very little cost. The blades that they sell do not break when it hits a hard object, but