Saturday, November 7, 2020

0000 0000 0100 1000

"Blinky" the Ice Blue Solar Light

Putting the Stable Joule Thief (SJT) into service, in this post I am cutting the guts out of a standard solar garden light and making an ice blue blinking version. I'm not sure why.

Firstly the SJT itself which is a variation on the QX5252 IC circuit which looks like:


Using this circuit I've made up a few PCBs that allow a slow running ATTiny13a (at 128kHz) to be programmed. This one sleeps incessantly and just wakes up and blinks an LED from time to time (0.125s on, 2s off).

Here's the PCB version I'm using for this project.


Needing some code to sleep and blink the microcontroller, I dug out an old assembly project and modified it as follows:

.nolist
.include "tn13adef.inc" ; Define device ATtiny13A
.list
; **********************************
;        H A R D W A R E
; **********************************

; Device: ATtiny13A, Package: 8 - pin - PDIP_SOIC
;
;           ____________
;        1 /            | 8
;      o-- | RESET  VCC | --o
;      o-- | PB3    PB2 | --o
;      o-- | PB4    PB1 | --o
;      o-- | GND    PB0 | --o
;        4 |____________| 5
;

; **********************************
;         C O D E
; **********************************

    .cseg
    .org 000000

; **********************************
; R E S E T  &  I N T - V E C T O R S
; **********************************
    rjmp Main               ; Reset vector
    reti ; INT0
    reti ; PCI0
    reti ; OVF0
    reti ; ERDY
    reti ; ACI
    reti ; OC0A
    reti ; OC0B
    rjmp mytimer_ISR        ; my interrupt
    reti ; ADCC

; **********************************
;  I N T - S E R V I C E   R O U T .
; **********************************

mytimer_ISR:

    ;  sleep is interrupted, program returns
    reti

; **********************************
;  M A I N   P R O G R A M   I N I T
; **********************************
;
Main:
    ldi r16, Low(RAMEND)
    out SPL, r16              ; Init LSB stack pointer

    ; output mode for PB4, input for the rest
    ldi r16, 0b00010000
    out DDRB, r16

    ; turn on PB4, enable internal pullups
    ; on the rest of the pins
    ldi r16, 0b11111111
    out PORTB, r16

; **********************************
;    P R O G R A M   L O O P
; **********************************

Loop:

    rcall waitabit            ; 1/8 second (on)
    rcall waitalot            ; 2 seconds (off)

    rjmp loop

waitabit:

    ; reset watchdog timer
    wdr

    ; 1/8 second timer
    ldi r16, 0b01000011       ; see datasheet
    out WDTCR, r16

    rcall sleepnow
    rcall flipbit
    ret

waitalot:

    ; reset watchdog timer
    wdr

    ; 2 second timer
    ldi r16, 0b01000111      ; see datasheet
    out WDTCR, r16

    rcall sleepnow

    ; finished long sleep, so flip LED
    rcall flipbit

    ret


sleepnow:

    ; see datasheet MCUCR, ADCSRA, BODCR

    ; sleep enable, power down mode
    ldi r16, 0b00110000
    out MCUCR, r16

    ; disable ADC
    ldi r16, 0b00010000
    out ADCSRA, r16

    ; disable interrupts to make sure the following
    ; timed sequence is not interrupted
    cli

    ; disable BOD - must be done in a timed sequence
    ; as follows, write 1 to BODS and BODSE then within
    ; four clock cycles write 1 to BODS and 0 to BODSE
    ; then within three clock cycles enable sleep
    ; page 33 on the datasheet

    ldi r16, 0b00000011
    ldi r17, 0b00000010
    out BODCR, r16
    out BODCR, r17

    sei

    sleep

    ; sleep disable
    ldi r16, 0b00000000
    out MCUCR, r16

    ret

flipbit:
    ; if PB4 is on, switch off and vice versa

    in r16, portb
    ldi r17, 0b00010000
    eor r16, r17
    out portb, r16

ret

; End of source code

I burned the fuses, compiled the code and uploaded the hex file to the ATTiny13a (see video below). After testing, I was ready to assemble the PCB back into the gutted solar light and flick it out to the garden - nice!

Now we wait for alien overlords to see the signal and come on down for a nice cup of tea and to say hello.






2 comments:

  1. Do you sell a parts kit with the chip programmed please but ai think it will cost to much as I am in the UK
    thanks Bob

    ReplyDelete
    Replies
    1. Pre-pandemic I supplied through https://www.tindie.com/stores/bovineck/, but at the moment the freight situation makes it unlikely, however if you leave me a message at the store I will let you know when it opens up again - hopefully very soon!

      Delete