View previous topic :: View next topic |
Author |
Message |
mojsa2000
Joined: 18 May 2010 Posts: 78
|
problem in CCP (capture mode) |
Posted: Tue May 18, 2010 2:32 am |
|
|
I want to measure a pulse wave's period(T) that its duty cycle is variable. For this, I used a capture mode on CCP.
There is my source code (CCS C compiler). But when I run it in Proteus, unfortunately the CCP interrupt doesn't work (MCU doesn't detect an interrupt on its input). I've connected a digital pulse to PIN_C2 by a pullup resistor in Proteus.
What is my faults?
Code: |
#include<16f887.h>
#use delay(clock=4000000)
#include <lcd.c>
#int_TIMER1
#int_CCP1 //capture mode interrupt
#define use_lcd_portd true //set port D to use LCD
//declared variables
static unsigned long old_rise,new_rise;
unsigned char period;
unsigned int flag_counter,multiple;
void TIMER1_isr(void) //timer1 interrupt
{
flag_counter++; //this is a counter for timer1 overflows
clear_interrupt(int_timer1);// clear timer1 interrupt's flag
}
void CCP1_isr(void)
{
multiple=flag_counter;
flag_counter=0;
old_rise=new_rise;
new_rise=ccp_1;
period=((new_rise)-(old_rise)+(256*(multiple+1)))*8u;
clear_interrupt(int_ccp1); //clear ccp1 flag to run for next edge
}
void main()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_CCP1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); //set timer1 in 8us resolution
setup_ccp1(CCP_CAPTURE_FE);
set_tris_c(0xff); //CCP1 pin is declared as a input
lcd_init();
while(1){
lcd_gotoxy(1,2);
printf(lcd_putc,"%u s", period);
delay_us(50);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Tue May 18, 2010 2:07 pm |
|
|
I'm so appreciate for your attention. But I want to find my program's bugs if is possible. I think the program routine is true but there are bugs that I can't find them. Please help me. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 18, 2010 2:24 pm |
|
|
Quote: | #include<16f887.h>
#use delay(clock=4000000)
#include <lcd.c>
#int_TIMER1
#int_CCP1 //capture mode interrupt |
One problem is that you have stuck these interrupt routine declarations
up in the front part of the program. That is not correct. They must
be placed in front of the routine that they are used for.
Look at any of the programs in the links that I gave you, and you will
see where to put the #int_xxx statements.
Look in the .LST file for your program, after you compile it.
You will see that when you put the #int_xxx lines "up in the air" like
you have done, that the compiler does not generate any ASM code for
the interrupt routines:
Code: | ....................
.................... void TIMER1_isr(void) //timer1 interrupt
.................... {
.................... flag_counter++; //this is a counter for timer1 overflows
.................... clear_interrupt(int_timer1);// clear timer1 interrupt's flag
.................... }
....................
.................... void CCP1_isr(void)
.................... {
.................... multiple=flag_counter;
.................... flag_counter=0;
.................... old_rise=new_rise;
.................... new_rise=ccp_1;
.................... period=((new_rise)-(old_rise)+(256*(multiple+1)))*8u;
.................... clear_interrupt(int_ccp1); //clear ccp1 flag to run for next edge
.................... }
....................
........ |
Put the #int_xxx lines in the correct place, as shown below, and compile
it. You will notice a change in the .LST file.
Quote: |
#int_timer1
void TIMER1_isr(void) //timer1 interrupt
{
flag_counter++; //this is a counter for timer1 overflows
clear_interrupt(int_timer1);// clear timer1 interrupt's flag
}
#int_ccp1
void CCP1_isr(void)
{
multiple=flag_counter;
flag_counter=0;
old_rise=new_rise;
new_rise=ccp_1;
period=((new_rise)-(old_rise)+(256*(multiple+1)))*8u;
clear_interrupt(int_ccp1); //clear ccp1 flag to run for next edge
} |
|
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Wed May 19, 2010 1:48 pm |
|
|
Dear PCM Programmer
Thank you. I found my bugs in CCS programming because of your help.
But I had a big problem too. My problem was in my Proteus.
Its version is 7.6 and I didn't know that has a big fault in PICs.
I found files and fixed it.
The files are:
LCDPIXEL.dll
pic16.dll
READOUT.dll
Anyway thank you. |
|
|
vsmguy
Joined: 13 Jan 2007 Posts: 91
|
|
Posted: Tue Jul 06, 2010 4:30 pm |
|
|
You fixed an error in Proteus where the CCP Interrupt was not firing regardless of transitions at that pin?
How did you solve that? |
|
|
allr
Joined: 28 Sep 2006 Posts: 4
|
Re: problem in CCP (capture mode) |
Posted: Wed Jul 07, 2010 1:51 am |
|
|
A question,
What happens when "new_rise" value are < that "old_rise" valued because an overflow of the Timer1 has happened?
mojsa2000 wrote: | ... period=(new_rise)-(old_rise)... |
Thanks
Last edited by allr on Wed Jul 07, 2010 9:04 am; edited 1 time in total |
|
|
vsmguy
Joined: 13 Jan 2007 Posts: 91
|
Re: problem in CCP (capture mode) |
Posted: Wed Jul 07, 2010 8:29 am |
|
|
allr wrote: | A question,
What happens when "new_rise" value are < that "old_rise" valued because an overflow of the Timer1 has happened?
mojsa2000 wrote: | ... period=(new_rise)-(old_rise)... |
Thanks |
He has handled it in TIMER1_isr. Look closely. |
|
|
gmua
Joined: 07 Feb 2011 Posts: 11
|
|
Posted: Mon Mar 14, 2011 2:05 pm |
|
|
mojsa2000 wrote: | But I had a big problem too. My problem was in my Proteus.
Its version is 7.6 and I didn't know that has a big fault in PICs.
I found files and fixed it.
The files are:
LCDPIXEL.dll
pic16.dll
READOUT.dll
|
Hello mojsa2000, where did you find those files? I'm having similar problems with int_ccp1 in Proteus 7.6 SP0, but it works fine in version 7.4 SP3 |
|
|
desert eagle
Joined: 27 Sep 2013 Posts: 7 Location: Frankfurt, Germany
|
Re: problem in CCP (capture mode) |
Posted: Fri Oct 04, 2013 6:36 am |
|
|
Hi there!! I have tried to use the above explanation and example to measure the average period of a wave and I want to use this 'period' value as the period of my output pulse. For that, I am writing this period value to a timer and when the timer overflows after this 'period', the ISR for the timer generates a pulse. but its not working. I am using PIC24FV32KA301. Can anyone help in this regard. _________________ Asghar |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Fri Oct 04, 2013 8:35 am |
|
|
REAL hardware or Proteus ?
If inside real hardware, easy.. if Proteus, not possible
hth
jay |
|
|
desert eagle
Joined: 27 Sep 2013 Posts: 7 Location: Frankfurt, Germany
|
|
Posted: Fri Oct 04, 2013 8:47 am |
|
|
Real Hardware. Not proteus. _________________ Asghar |
|
|
desert eagle
Joined: 27 Sep 2013 Posts: 7 Location: Frankfurt, Germany
|
|
Posted: Mon Oct 07, 2013 12:40 am |
|
|
Anyone who can help in this regard? at least give some suggestion of how its possible _________________ Asghar |
|
|
|