Rules | Recent posts | topic RSS | Search | Register  | Log in

ccp in compare mode

 
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers
Author Message
kvrajasekar



Joined: 18 Sep 2008
Posts: 12


Post05 Oct 2008 18:34   ccp in compare mode

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.
Back to top
MAK-1



Joined: 26 Jun 2008
Posts: 51
Helped: 3


Post07 Oct 2008 8:49   ccp in compare mode

http://www.edaboard.com/ftopic329731.html
Back to top
kvrajasekar



Joined: 18 Sep 2008
Posts: 12


Post07 Oct 2008 10:20   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?
Back to top
adidav



Joined: 19 Apr 2006
Posts: 15
Helped: 1
Location: Romania


Post08 Oct 2008 6:50   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



Sorry, but you need login in to view this attachment

Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers
Page 1 of 1 All times are GMT + 1 Hour


Abuse
Administrator
Moderators
topic RSS 
sitemap