PWM Question
Travis Best
Posts: 8
Is their away to change the value of LED1 To any output port I want through out the program? sorta like the example I have bellow but this wont work
Thanks For Any Help
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
LED VAR RC.0
BTN1 VAR RB.1
BTN2 VAR RB.2
BTN3 VAR RB.3
'
INTERRUPT NOPRESERVE 5000
'
ISR_Start:
PWM LED, 200,40
RETURNINT
' =========================================================================
Program start
start:
IF BTN1=0 then LED1
IF BTN2=0 then LED2
IF BTN3=0 then LED3
goto start
LED1:
LED = RC.1
goto start
LED2:
LED = RC.2
goto start
LED3:
LED = RC.3
goto start
Thanks For Any Help
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
LED VAR RC.0
BTN1 VAR RB.1
BTN2 VAR RB.2
BTN3 VAR RB.3
'
INTERRUPT NOPRESERVE 5000
'
ISR_Start:
PWM LED, 200,40
RETURNINT
' =========================================================================
Program start
start:
IF BTN1=0 then LED1
IF BTN2=0 then LED2
IF BTN3=0 then LED3
goto start
LED1:
LED = RC.1
goto start
LED2:
LED = RC.2
goto start
LED3:
LED = RC.3
goto start
Comments
One solution is to setup individual PWM controls for the three LEDs and then set the levels based on the button that gets pressed. It takes a bit of work (though I've done it for you...) and can, if you want, have all three running at the same time, and at different levels.
To change LED brightness change the values of level0, level1, and level2 -- 0 = off, 255 = full bright. Note that I changed the ISR rate to 10_000; 5000/256 (pwm steps) is 19.5 Hz and you can see this pulsing; at 10K the pwm frequency is 39 Hz and the eye's POV smooths this out.
Update: You can write the ISR in SX/B but it's easy to convert a program like this to assembly and be a little more efficient; the code attached has had the ISR converted to assembly.
Post Edited (JonnyMac) : 7/25/2007 10:19:01 PM GMT