Hi All,
Can someone tell me what step I have missed in initializing one of the 16bit
timers to output on PB5?
-------------------------- code snippet ----------------------------------
marker _pwm_
hex
\ Register defines
37 constant DDRB
4a constant OCR1A
4f constant TCCR1A
4e constant TCCR1B
4c constant TCNT1
4b constant ICR1
57 constant TIMSK
\ bit defines
DDRB 5 portpin: PB5
\ Two useful words
\ or! ors value to contents of RAM address
: or! ( n addr -- ) dup c@ rot or swap c! ;
\ high! is like ! but writes high byte first!
: high! ( n addr -- ) over 8 rshift over 1+ c! c! ;
\ init 16 bit timer1
: +pwm ( n -- ) \ takes a starting freq parameter
PB5 high \ Set OC1A/PB5 for output
0 TCCR1B c! \ stop pwm
dup OCR1A high! \ set TOP
1 rshift ICR1 high! \ duty = 50%
81 TCCR1A c! \ set phase & freq correct mode, OCR1A TOP
12 TCCR1B c! \ divide clk by 8, start pwm
;
----------------------------- end code snippet -----------------------------
The LED that is on that pwm output either lights or is off depending on the
parameter fed to +pwm. I cannot get the light to flash, even with higher
pre-scale settings than shown above. (I don't have access to a scope at the
moment to check if anything at all is happening ..)
Thanks,
Bernie
|