Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with turning PWM on and off

Status
Not open for further replies.

raitl

New Member
This is the part of my code that deals with the IR obstacle detection:

Code:
loop:
 call  IR_test
 call  go_forward
 goto  loop

;*******My subroutines*******

PWM_Enable:
 bsf  CCP1CON, 3
 bsf  CCP1CON, 2
return

PWM_Disable:
 bcf  CCP1CON, 3
 bcf  CCP1CON, 2
return

IR_test:
 call  PWM_Enable
 btfss  PORTA,0
 goto  IR_obstacle
 call  PWM_Disable
return

IR_obstacle:
 call PWM_Disable
 STEPS .10
 goto  Turn_right
return

And the problem is, that it won't toggle PWM. If I add call PWM_Enable before the loop: section, then it works but in that case PWM is always enabled which I do not want... I'd appreciate it if you could point me where the problem might be.
 
raitl said:
This is the part of my code that deals with the IR obstacle detection:

Code:
loop:
 call  IR_test
 call  go_forward
 goto  loop

;*******My subroutines*******

PWM_Enable:
 bsf  CCP1CON, 3
 bsf  CCP1CON, 2
return

PWM_Disable:
 bcf  CCP1CON, 3
 bcf  CCP1CON, 2
return

IR_test:
 call  PWM_Enable
 btfss  PORTA,0
 goto  IR_obstacle
 call  PWM_Disable
return

IR_obstacle:
 call PWM_Disable
 STEPS .10
 goto  Turn_right
return

And the problem is, that it won't toggle PWM. If I add call PWM_Enable before the loop: section, then it works but in that case PWM is always enabled which I do not want... I'd appreciate it if you could point me where the problem might be.

I don't really see what you are trying to do, but from the small section of code you posted it looks like PWM is turned OFF almost all the time, and only ever turned ON for a few microseconds.
 
I don't really see what you are trying to do, but from the small section of code you posted it looks like PWM is turned OFF almost all the time, and only ever turned ON for a few microseconds.

that's correct. It's supposed to turn on PWM, then check if there is an obstacle in front of the IR transmitter and then act accordingly. But now that I think of it... the IR light "wave" might be too short to be successfully detected... I'll throw a delay in there and see what happens.
 
Yup! That's where the problem was :) Thanks
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top