??? 08/06/09 09:33 Read: times |
#168211 - good catch Responding to: ???'s previous message |
Chico Magalhães said:
But I think this last Maarteen code cant do full time low output... or I'm wrong? Yes, you're right. The check for CTR should be moved to the front. The result will be that all PWM values need an offset of 1: 1: 0/255 (with a small glitch) 2: 1/255 ... 255: 254/255 0(256): 255/255 ;Demonstration only. Timer setup is your problem. push PSW ;Save Program Status Word mov PSW, #08 ;Select Register bank 1 djnz CTR, nxtr0 mov CTR, #255 ;Reload CTR counter mov r0,PWM0 ;Reload registers with PWM values mov r1,PWM1 ....... mov P2,#255 ;Turn all bits on again nxtr0: djnz r0,nxtr1 ;Decrement and test r0 for zero clr P2.0 ;If it is, turn off the bit nxtr1: djnz r1,nxtr2 ;Decrement and test r1 for zero clr P2.1 ;If it is, turn off the bit nxtr2: djnz r2,nxtr3 ;Decrement and test r2 for zero clr P2.2 ;If it is, turn off the bit nxtr3: ................ ENDi: pop PSW ;Restore Program Status Word retiSince the accumulator isn't even used you need not save and restore it. And if you dislike the glitch and/or shifted timing, you can use a byte in bit-addressable memory for shadowing. ;Demonstration only. Timer setup is your problem. push PSW ;Save Program Status Word mov PSW, #08 ;Select Register bank 1 djnz CTR, nxtr0 mov CTR, #255 ;Reload CTR counter mov r0,PWM0 ;Reload registers with PWM values mov r1,PWM1 ....... mov BITS,#255 ;Turn all bits on again nxtr0: djnz r0,nxtr1 ;Decrement and test r0 for zero clr BITS.0 ;If it is, turn off the bit nxtr1: djnz r1,nxtr2 ;Decrement and test r1 for zero clr BITS.1 ;If it is, turn off the bit nxtr2: djnz r2,nxtr3 ;Decrement and test r2 for zero clr BITS.2 ;If it is, turn off the bit nxtr3: ................ ENDi: mov P2, BITS ;Output the bits synchronous pop PSW ;Restore Program Status Word reti |
Topic | Author | Date |
Simple PWM to drive led | 01/01/70 00:00 | |
Loop lasts too long! | 01/01/70 00:00 | |
I put the delay... | 01/01/70 00:00 | |
Did you see? | 01/01/70 00:00 | |
didnt noticed! | 01/01/70 00:00 | |
Ok, try the following... | 01/01/70 00:00 | |
the JMP | 01/01/70 00:00 | |
I thought this was your intention... | 01/01/70 00:00 | |
Another try | 01/01/70 00:00 | |
is possible to filter the pwm output... | 01/01/70 00:00 | |
PWM from a Timer interrupt? | 01/01/70 00:00 | |
questions | 01/01/70 00:00 | |
best code until now | 01/01/70 00:00 | |
read replies | 01/01/70 00:00 | |
will lower refresh rate | 01/01/70 00:00 | |
Time to switch... | 01/01/70 00:00 | |
Wrong. | 01/01/70 00:00 | |
my code is doing what I want | 01/01/70 00:00 | |
TIming | 01/01/70 00:00 | |
FOR NOW!!!! | 01/01/70 00:00 | |
The old story... | 01/01/70 00:00 | |
DJNZ | 01/01/70 00:00 | |
Dec | 01/01/70 00:00 | |
Do nothing? | 01/01/70 00:00 | |
Speed | 01/01/70 00:00 | |
slowdown | 01/01/70 00:00 | |
Chico | 01/01/70 00:00 | |
Not yet... | 01/01/70 00:00 | |
good catch | 01/01/70 00:00 |