Problem with SX48 Timer1|2
I am having problems running the following code
It appears to run correctly when I do not run the Brake and speed subroutines in the main loop. My goal is to independantly run two devices at different frequencies and have the ability to change the freq of one while changing the pulse width of the other, all while the main loop is running. What am I missing?
thanks in advance
George
DEVICE SX48,OSCHS1
FREQ 50_000_000
F var word
Brake_pin pin Rb.6 output
MTR_speed pin Rc.2 output
brake sub
speed sub
Program Start
Start:
TIMER1 PRESCALE,5 ' 1:32 prescaler
TIMER2 PRESCALE,5 ' 1:32 prescaler
low rb.1
F=1836
Brake
F=7000
speed
main:
F=1836 'pulse width control
Brake
F=7000 'freq control
speed
pulsout rb.1, 5
pauseus 50
goto main
Brake:
TIMER1 pwm,F,65000
return
speed:
TIMER2 pwm,50,F
return
It appears to run correctly when I do not run the Brake and speed subroutines in the main loop. My goal is to independantly run two devices at different frequencies and have the ability to change the freq of one while changing the pulse width of the other, all while the main loop is running. What am I missing?
thanks in advance
George
Comments
You are calling Brake and Speed every 100 microseconds.
Only call Brake and Speed if the value of "F" changes.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My goal is to live forever...Or die trying.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
I intended to write the code in that way I just didn't get there yet. I tried what you suggested but from a different approach I added a pause command in the main loop and increased its value until the PWM frequencies appeared. It appears to be directly tied to the slower of the 2 signals, which makes sense. I have never seen a reset time referenced anywhere for the Timerx PWM command do you know of a reference that I am missing? Should this be added to the help file in some way?
thanks for your help
George
The reason the timer must be reset is because the timer triggers when it hits the R1 or R2 value.
For example:
· Let's say you had R1 set to 200 and the timer is currently at 110.
· Now let's say the new PWM value sets R1 to 100. Since the timer is already past 100, it will have to continue all the way to 65535 and roll over, then when it reaches 100 it will toggle the output pin. This would cause a huge glitch in the PWM output.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
My goal is to live forever...Or die trying.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·