Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How does CCP1 work in compare mode?

Status
Not open for further replies.

kvrajasekar

Junior Member level 3
Joined
Sep 18, 2008
Messages
28
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,517
Hi,

I am using 16f72 ccp1 in compare mode.

I dont know how it works,I initialised TIMER1 as counter and CCP1 as compare mode.

preparing microchip manual i did the following.

1.loaded CCPR1L=0x30
CCPR1H=0x02
2.timer1 :
TMR1L=0x28mTMR1H=0x45

I wantt to set output on compare match.How can i do this.please help me.



-Regards,
raja.
 

ccp in compare mode
 

Re: ccp in compare mode

Hi,

Thanks for the reply.

I want ccp in compare mode.I am trying to generate sine pwm,can i use ccp compare mode to generate sine pwm?
 

Re: ccp in compare mode

Hi,
Recently I work with compare mode. This module work very good and is easy.
how it works:
- First you have to set the compare mode how the intterupt will be set. For example set for high on match and a value will put in ccp registers.
-The timer1 is compare agaist the CCPR1H and CCPR1L registers. When the a match was found then the CCP1IF is set. Then you can decide what to do (like a change on low on match) set again the ccp registers and the cycle repeat.

An practical example(I use the Hi-tec compiler 9.6):

void interrupt isr(void)
{
uint16_t value = 0;

if(CCP1IE && CCP1IF)
{
CCP_Mode_CtrlBits(CCP_Mode_Off);// Turn CCP off (as fast as possible)
FlagIntCCP1IF(OFF); //reset the ccp flag
Timer1Control(OFF); //stop timer1
Timer1RegisterReset(); //reset timer1 registers

switch(CCP_State)
{
case LowOnMatch:
CCPR1H = HIGH_BYTE(Registers.LowOnMatchValue); //load the new time
CCPR1L = LOW_BYTE(Registers.LowOnMatchValue);
CCP_Mode_CtrlBits(CCP_Mode_CompareHighOnMatch); //set for high on match
CCP_State = HighOnMatch; //go to next state
break;
case HighOnMatch:
CCPR1H = HIGH_BYTE(Registers.HighOnMatchValue); //load the new time
CCPR1L = LOW_BYTE(Registers.HighOnMatchValue);
CCP_Mode_CtrlBits(CCP_Mode_CompareLowOnMatch); //set for low on match
CCP_State = LowOnMatch; //go to next state
break;
};
Timer1Control(ON); //start timer1
}
}


I hope this will help you.

Greetings,
ADi
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top