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.

[SOLVED] ccp capture interrupt flag bit problem

Status
Not open for further replies.

mnyama

Newbie level 4
Joined
Feb 23, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,333

hellow folks out there,sory for my bad english, i'm hving problem with ccp interrupt flag bit, my aim was just to demonstrate the ccp capture interrupt service routine by complimenting the leds being connected at portd, once the flag bit is set, i am using two intterruptys in mikroc, one for timer1 overflow interrupt flag bit, and other for ccp capture flag bit, the interrupt for timer1 overflow works fine,since once the flag bit is set, the leds D1(PORTD.F0) toggles, but the other intterupt (CCp capture interrupt), seems to have problem, it seems like ccp flag bit is not working, could anybody having an idea, i will be very happy, here is the snippet code :-:)-(, attached here is a snippet code + image of simulated circuit


Code:
unsigned char cnt=0;
unsigned char cpf=0;
void interrupt()
{
if(PIR1.CCP1IF==1)
  {
  cpf++;
  PIR1.CCP1IF=0;
  CCPR1H=0;
  CCPR1L=0;
  }
  else if(PIR1.TMR1IF==1)
{
  cnt++; //increment cnt
  PIR1.TMR1IF=0; //clear flag bit
  TMR1H=0;
  TMR1L=0;
  }


  }
void main() {                                                           a

ANSELH =0; //all pins configured as digital
ANSEL=0;
C1ON_bit=0; //switch off all comparators
C2ON_bit=0;
PORTC.F2=1; //ccp1 pin configured as input
TRISD =0; //port c initialize as the output
INTCON = 0b11000000;  // Enable interrupt (bits GIE and PEIE)
PIE1=0b00000101; //except for the TMR1IE&CCP1IE bits
//PIR1=0x00; //clear the IF bit to zero
T1CON=0b0000001; // timer ON, prescaler 1:4, not syschronized
CCP1CON=0b00000101; //capture everyrising edge

PORTD.F0=1;
PORTD.F2=1;
cnt = 0;                    // Reset variable cnt
cpf=0;                      //ccp variable


while(1){
 if(cnt==10)
 {

  cnt=0; //clear cnt count
  PORTD.F0=~PORTD.F0;
   }

   if(cpf==65)
   {
    cpf=0;
    PORTD.F2=~PORTD.F2;
   }
  }

}

ccp.PNG
 

Instead of that Signal Generator use this.

SignalGenerator.PNG

And see if it work or not.
 
  • Like
Reactions: mnyama

    mnyama

    Points: 2
    Helpful Answer Positive Rating
Thank you very much mr Xpress_embedo, thank you very much brother, the simulation worked just fine, when i did as you said, but one more thing just for curiousity, as i changed the signal generator with the clock source, i didnt c any option, on the panel to change amplitude of the pulses being generated from the clock,but, i saw an option for changing the frequency being generated, how can i be sure, of the amplitude level of the signal being generated,and can you plz tel me what might be the cause to the failure for the previous simulation with the signal genarator being attached?
here is the attachement for successful simulation

- - - Updated - - -

C1.PNGc2.PNGc3.PNG
 

For changing Amplitude also, select
GENERATOR MODE-> PULSE
And set amplitude, frequency, duty cycle etc as per your needs.

I am not able to attach image.

how can i be sure, of the amplitude level of the signal being generated

In Proteus Blue means Logic Low and Red Means Logic High, that will be sufficient i think.

what might be the cause to the failure for the previous simulation with the signal genarator being attached?
here is the attachement for successful simulation
I dont know why, this happen with me few months back thats why i know it doesn't work in this case.
May be someone else on edaboard will help you with this topic.
 

CCP period mesurement problem again

Sory guyz, am back again, it is 1:06 am, i am here,in the middle of night,no clping, plz help me , am stuck somewhere i dont know, i have re-constructed the codes again, this time am getting totally wrong answer, for example, sending pulse of 10000Hz, the LCD displays 89,141,362 microseconds, i was expecting to get a count of about 100 microseconds, since am using 4Mhz crystal oscillator, which will give input to the timer (internal oscilation to the timer of about Fosc/4=1Mhz giving a ticking time of about 1Us), am much confused guyz, help me, here are the codes

Code:
//lcd configuration
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
//end of lcd configuration
 unsigned long t1,t2,t3,T,tp=0;
 unsigned char cpf,cnt=0; //variables as count
 char txt[12];
 
 void interrupt()
 {
  if(PIR1.CCP1IF==1)
  { 
  PIR1.CCP1IF=0; //clear flag bit
  cpf++; //record the ccp flag bit
  }
  else if(PIR1.TMR1IF==1)
  {
   PIR1.TMR1IF=0; //clear the flag bit
   cnt++; //record the t1 overflows
  }

 
 }
 
void main() {
// Configure AN pins as digital I/O
ANSEL = 0x00;
ANSELH = 0x00;

// Disable comparators
 C1ON_bit = 0;
 C2ON_bit = 0;
  //configuring  PORTD is output
 TRISD = 0;
 PORTD =0;
  //setting the RC2/CCP1 pin as input
 PORTC.F2=1;
INTCON = 0b11000000;  // Enable interrupt (bits GIE and PEIE)
PIE1=0b00000101; //except for the TMR1IE&CCP1IE bits
T1CON = 0b00000001; /*T1 on,sychronised,prescaler value 1:1 */
CCP1CON=0b00000111; //capture every 16th rising edge
//PIR1 = 0b00000000;                          // Clear all interrupt flags
TMR1H=0; //initialize the TMR1H&TMR1L
TMR1L=0;

Lcd_Init();                 // Initialize LCD
Lcd_Cmd(_LCD_CLEAR);        // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF);   // Cursor off
Lcd_Chr(2,15,'O'); //write the  word....
Lcd_Chr(2,16,'N'); //..... ON forever
Lcd_Out(1,1,"Welcome");
delay_ms(100);
Lcd_Cmd(_LCD_CLEAR);

if(cpf==1) //wait here for the first ccp flag bit
{
  t1=TMR1H*256+TMR1L; //store the value of time of first captured rising edge
}
else if(cpf==2)  //wait here for the second ccp flag bit
cpf=0; //clear the cpf counter
T1CON.TMR1ON=0; //stop the timer
{
 if(cnt>0)  //if T1 has overflowed
 {
  t2=TMR1H*256+TMR1L+cnt*65536; //store value of T1---> t2
 }
 else
 {
  t2=TMR1H*256+TMR1L; //store value of T1--->t2 when no overflows
 }
}
T=t2-t1; //subtracts 1st captured value from 2nd captured value to get time
         //elapsed between two consecutive rising edges
t3=T/16; //divide the time obtained above by 16 to get time per pulse (period)
         //due to ccp prescaler value of 1:16
LongToStr(t3,txt); //convert variable t3---> string before sending it to LCD
Lcd_Out(1,1,txt); //send the results to LCD
 Lcd_Out_Cp("Us");//display symbol Us (microsecond) to the lcd at the current cursor
                //position
TMR1H,TMR1L=0; //clear the timer to zero for next round trip
T1CON.TMR1ON=1; //switch on the timer again

}
here is the simulation resulted from 10Khz pulse

duuh.PNG
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top