PDA

View Full Version : quick question



Srigopal007
- 1st December 2004, 23:59
I konw that the On-Board PWM can be performed in the background, and that when you are not using the PWM module the duty cycle freeezes until you come back to it in code. Here is what I need to konw.. Where does the CCPx registers get stored adn how can I retrive the data for the duty cycle for the PWM mode. Basically what I am asking is lets say I am using the ON-Board CCP1 (PWM MODE) and I freeze it in the main loop. Now in a different subroutine I want to continue this, How can I do that. I have tried many options but with not success.

here is what I have tried:
I have saved the value of the duty variable before jumping out of the main loop .. now in the subroutine I set the duty = SAVED value of the duty cycle before I jumped out. I get that the CCP value is full ON. How do i fix this problem?

any help on this topic would be greatly appreciated. thanks

srigopal

mister_e
- 2nd December 2004, 01:31
hi srig,
can you post the code you have try with the PIC you are using?

Bruce
- 2nd December 2004, 01:45
The PWM period is specified by writing to the PR2 register. PWM frequency is defined as 1 / [PWM period].

The PWM duty cycle is specified by writing to the CCPR1L register and to the CCP1CON bits 5 & 4.

Whatever values you place in these registers stays there until you put something else there or a hardware reset clears everything back to the power-up defaults.

CCP1CON = 12 turns on PWM
CCP1CON = 0 turns it off

All you need to do is write to CCP1CON to turn hardware PWM on/off. It's going to come back on at the same frequency & duty cycle you had it setup for originally, and stay there until you write different values to the control registers or a hardware reset.