Skip to content

Commit

Permalink
low power version (integrates commits of @scott-42)
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Jul 24, 2011
1 parent 862e5c0 commit 340d7e2
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 50 deletions.
136 changes: 96 additions & 40 deletions Firmware/cuff.asm
Expand Up @@ -7,58 +7,114 @@
.cseg

.org 0x0000
rjmp RESET
rjmp RESET
.org 0x0008
rjmp WDT

.def temp = R16 ; general purpose temp
.def idx = R17 ; sine table indexer
.def delaycnt1 = R18 ; counter for 1ms delay loop
.def delayms = R19 ; keeps track of how many ms left in delay
.def temp = R16 ; general purpose temp
.def idx = R17 ; sine table indexer
.def delaycnt1 = R18 ; counter for 1ms delay loop
.def delayms = R19 ; keeps track of how many ms left in delay

RESET:
sbi DDRB, LED ; LED output
sbi PORTB, LED ; LED off
sbi DDRB, LED ; LED output
sbi PORTB, LED ; LED off

; setting all pullups on unused pins (for power savings)
; would having them all be outputs use less power?
ldi temp, (1<<PUEB3)|(1<<PUEB2)|(1<<PUEB1)
out PUEB, temp

; changing clock prescale to slow down the processing power
; (for power savings)
ldi temp, 0xD8 ; write signature
out CCP, temp
; scale to divide by 256. So 8Mhz -> 312.5KHz
ldi temp, (1<<CLKPS3)|(0<<CLKPS2)|(0<<CLKPS1)|(0<<CLKPS0)
out CLKPSR, temp
; set up fast PWM output timer WGM[3:0] = 0101
; COM0A1 = 1, COM0A0 = 0 or 1
ldi temp, 0xC1 ; Fast PWM (PB2 output)
out TCCR0A, temp
ldi temp, 0x81 ; fastest clock
out TCCR0B, temp

; we dont use the top of the counter since its only 8 bit
ldi temp, 0
out OCR0AH, temp

; setup watchdog
ldi temp, 0xD8 ; write signature
out CCP, temp
; set watchdog in interrupt mode and 4k cycles
ldi temp, (0<<WDE)|(1<<WDIE)|(1<<WDP0)
out WDTCSR, temp

; enable sleep mode
ldi temp, (1<<SE) ; by default the mode is 000 Idle
out SMCR, temp

sei ; enable global interrupts
ldi idx, 0
LOOP:
; This is start of Code in Tiny10 (0x4000)
ldi ZH, high(SINETAB*2) + 0x40
ldi ZL, low (SINETAB*2) ; init Z-pointer to storage bytes

; set up fast PWM output timer WGM[3:0] = 0101
; COM0A1 = 1, COM0A0 = 0 or 1
ldi temp, 0xC1 ; Fast PWM (PB2 output)
out TCCR0A, temp
ldi temp, 0x81 ; fastest clock
out TCCR0B, temp
add ZL, idx
inc idx

; we dont use the top of the counter since its only 8 bit
ldi temp, 0
out OCR0AH, temp
ld temp, Z ; load next led brightness
cpi temp, 0 ; last entry?
brne NORELOAD
ldi idx, 0 ; rewind to the beginning of the table
NORELOAD:
out OCR0AL, temp ; Shove the brightness into the PWM driver

ldi idx, 0
LOOP:
ldi ZH,high(SINETAB*2) + 0x40 ; This is start of Code in Tiny10 (0x4000)
ldi ZL, low (SINETAB*2) ; init Z-pointer to storage bytes
; reset the watchdog timer to full value and sleep until it pops an interrupt

add ZL, idx
inc idx
; unfortunately we want to sleep 6k cycles to match the timing so sleep twice!
ldi temp, 0xD8 ; write signature
out CCP, temp
; set watchdog in interrupt mode and 2k cycles
ldi temp, (0<<WDE)|(1<<WDIE)
out WDTCSR, temp

ld temp, Z ; load next led brightness
cpi temp, 0 ; last entry?
brne NORELOAD
ldi idx, 0 ; rewind to the beginning of the table
NORELOAD:
wdr
sleep

ldi temp, 0xD8 ; write signature
out CCP, temp
; set watchdog in interrupt mode and 4k cycles
ldi temp, (0<<WDE)|(1<<WDIE)|(1<<WDP0)
out WDTCSR, temp

wdr
sleep


rjmp LOOP

out OCR0AL, temp ; Shove the brightness into the PWM driver

; delay!
ldi delayms, DELAYTIME ; delay 10 ms
DELAY:
ldi delaycnt1, 0xFF
DELAY1MS: ; this loop takes about 1ms (with 1 MHz clock)
dec delaycnt1 ; 1 clock
cpi delaycnt1, 0 ; 1 clock
brne DELAY1MS ; 2 clocks (on avg)
dec delayms
cpi delayms, 0
brne DELAY
; delay!
; ldi delayms, DELAYTIME ; delay 10 ms
;DELAY:
; ldi delaycnt1, 0xFF
;DELAY1MS: ; this loop takes about 1ms (with 1 MHz clock)
; dec delaycnt1 ; 1 clock
; cpi delaycnt1, 0 ; 1 clock
; brne DELAY1MS ; 2 clocks (on avg)
; dec delayms
; cpi delayms, 0
; brne DELAY
; rjmp LOOP

rjmp LOOP

; this is a do nothing interrupt handler for the watchdog interrupt
WDT:
reti

SINETAB:
.db 1, 1, 2, 3, 5, 8, 11, 15, 20, 25, 30, 36, 43, 49, 56, 64, 72, 80, 88, 97, 105, 114, 123, 132, 141, 150, 158, 167, 175, 183, 191, 199, 206, 212, 219, 225, 230, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 230, 225, 219, 212, 206, 199, 191, 183, 175, 167, 158, 150, 141, 132, 123, 114, 105, 97, 88, 80, 72, 64, 56, 49, 43, 36, 30, 25, 20, 15, 11, 8, 5, 3, 2, 1, 0
Expand Down
23 changes: 13 additions & 10 deletions Firmware/cuff.hex
@@ -1,12 +1,15 @@
:020000020000FC
:1000000000C0089A109A01EC0EBD01E80DBD00E099
:1000100007BD10E0F0E4E8E3E10F13950081003044
:1000200009F410E006BD32E32FEF2A952030E9F7FE
:100030003A953030C9F7EECF0101020305080B0FE6
:1000400014191E242B3138404850586169727B8442
:100050008D969EA7AFB7BFC7CED4DBE1E6EBF0F439
:10006000F7FAFCFDFEFFFEFDFCFAF7F4F0EBE6E12B
:10007000DBD4CEC7BFB7AFA79E968D847B72696174
:100080005850484038312B241E19140F0B08050313
:040090000201000069
:0200000008C036
:100010002CC0089A109A0EE003B908ED0CBF08E056
:1000200006BF01EC0EBD01E80DBD00E007BD08ED07
:100030000CBF01E401BF01E00ABF789410E0F0E4D6
:10004000ECE6E10F13950081003009F410E006BDE5
:1000500008ED0CBF00E401BFA895889508ED0CBF22
:1000600001E401BFA8958895EACF18950101020324
:1000700005080B0F14191E242B31384048505861C5
:1000800069727B848D969EA7AFB7BFC7CED4DBE1E4
:10009000E6EBF0F4F7FAFCFDFEFFFEFDFCFAF7F4E8
:1000A000F0EBE6E1DBD4CEC7BFB7AFA79E968D8459
:1000B0007B7269615850484038312B241E19140F47
:0800C0000B080503020100001A
:00000001FF

0 comments on commit 340d7e2

Please sign in to comment.