![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
CCP1 interrupt not working... |
Posted: Sun May 20, 2007 11:26 pm |
|
|
Dear Sir,
here i am using 16f913, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534.
for ic programming i am using MPLAB ICD2.so MCLR is external.
in this i am sensing freq. for 337Hz using ccp1 interrupt.
In CCP1 interrupt only i am incrementing(sec_counter++) counter.and in main() function i am compare
that value with counter & increment the another counter(number++).
In lcd_putc function i am displaying the incremented value i.e. number value.
It shows only 0,when i disconneced from MPLAB ICD2,and applid to my setup nothing is displayed on glass lcd.
Also i want to disply in 0.0 format,
so previousely i made changes in printf();function is,
Code: | printf(lcd_putc,"\f%5.1w",number);
&
byte const Digit_Map[10] = {0xFD,0x61,0xDB,0xF3,0x67,0xB7,0xBF,0xE1,0xFF,0xF7};
|
but it was showing garbage values.
BTW if i decleared sec_counter++ in main() it works fine.
but not in CCP1 interrupt.May be CCP1 not generating interrupt.
so plz tell where i did mistek. following is my short code.
Code: | #include<16F913.h>
#fuses INTRC_IO,NOWDT,PUT,/*****/MCLR,PROTECT,NOCPD,NOBROWNOUT,NOPROTECT,NOIESO,NOFCMEN
#use delay(clock=8000000) // internal clk 8 MHz.
/////////////////////////////////////////////////////////////////////////////////////////
// LCD Configuration //
/////////////////////////////////////////////////////////////////////////////////////////
// Digit segments A B C D E F G DP
// b7 b6 b5 b4 b3 b2 b1 b0
#define DIGIT1 COM3+6, COM2+6, COM0+6, COM1+6, COM0+5, COM3+5, COM2+5, COM1+5 // DISPALYS FROM RIGHT SIDE
#define DIGIT2 COM3+7, COM2+7, COM0+7, COM1+7, COM0+4, COM3+4, COM2+4 // DISPALYS FROM RIGHT SIDE
#define DIGIT3 COM3+8, COM2+8, COM0+8, COM1+8, COM0+3, COM3+3, COM2+3 // DISPALYS FROM RIGHT SIDE
#define DIGIT4 COM3+9, COM2+9, COM0+9, COM1+9, COM0+2, COM3+2, COM2+2 // DISPALYS FROM RIGHT SIDE
#define DIGIT5 COM3+11, COM2+11, COM0+11, COM1+11, COM0+1, COM3+1, COM2+1 // DISPALYS FROM RIGHT SIDE
#define DIGIT6 COM3+12, COM2+12, COM0+12, COM1+12, COM0+0, COM3+0, COM2+0 // DISPALYS FROM RIGHT SIDE
#define VLCD_ENABLE 0x10
#define BLANK 0
void init_CPU();
//character 0 1 2 3 4 5 6 7 8 9
byte const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
byte lcd_pos ;
static unsigned int16 sec_counter = 0;
#int_ccp1
void ccp1_isr(void)
{
sec_counter++;
}
void lcd_putc(char c)
{
byte segments;
if(c=='\f')
lcd_pos=0;
else {
if((c>='0')&&(c<='9'))
segments=Digit_Map[c-'0'];
else
segments=BLANK;
switch(lcd_pos)
{
case 1: lcd_symbol(segments,DIGIT6); break; // fill 1s place
case 2: lcd_symbol(segments,DIGIT5); break; // fill 10s place
case 3: lcd_symbol(segments,DIGIT4); break; // fill 100s place
case 4 : lcd_symbol(segments,DIGIT3); break; // fill 1000s place
case 5 : lcd_symbol(segments,DIGIT2); break; // fill 10000splace
case 6 : lcd_symbol(segments,DIGIT1); break; // fill 10000s place
}
}
lcd_pos++;
}
void main()
{
long number = 0;
init_CPU();
while(TRUE)
{
printf(lcd_putc,"\f%6lu",number);
if(sec_counter == 10000)
{ sec_counter = 0;
if(number++==100000)
number=0;
}
}
}
void init_CPU()
{
/************** PORT SETTINGS ****************/
PORT_B_PULLUPS(0XC0);
SET_TRIS_A(0X80);
SET_TRIS_B(0XC0);
SET_TRIS_C(0X27);
SET_TRIS_E(0X08);
/*************** LCD SETTINGS ********************/
SETUP_LCD( LCD_MUX14 | LCD_INTRC |VLCD_ENABLE , 2);
/**************** COMPARATOR SETTINGS ***************/
SETUP_COMPARATOR(NC_NC_NC_NC);
/**************** INTERRUPT SETTINGS *****************/
ENABLE_INTERRUPTS(GLOBAL);
// ENABLE_INTERRUPTS(INT_TIMER1); //enable timer1 interrupt
/***************************************************************/
set_timer1(0);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
setup_ccp1(CCP_CAPTURE_RE); //Capture on rising edge
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
} |
_________________ Thank You,
With Best Regards,
Deepak. |
|
![](templates/subSilver/images/spacer.gif) |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
CCP1 interrupt not working... |
Posted: Mon May 21, 2007 9:20 pm |
|
|
can any body help me to solve my above posted query ? _________________ Thank You,
With Best Regards,
Deepak. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 21, 2007 9:37 pm |
|
|
Explain what you're doing with the CCP1 interrupt. Normally, the
CCP1 interrupt is used to read the CCP1 register after it captures the
value of Timer1 on two sequential positive edges at the CCP1 pin.
Then by subtracting the first CCP1 value from the 2nd one, you can
determine the number of Timer1 clocks between two sequential edges
of the input waveform. From that value, you can calculate the period
and the frequency of the waveform. There are examples of this method
posted on the forum.
You're not doing that. The reason no one has replied is because we
don't know what you're doing, or why. |
|
![](templates/subSilver/images/spacer.gif) |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
CCP1 interrupt not working... |
Posted: Mon May 21, 2007 11:03 pm |
|
|
thanks for replying sir,
ok,here is the detail description.
To RC5/T1CKI/CCP1/SEG10 (pin no.16 of 16f913) i have connected freq. generator(Square wave).
Here i am want to measure time interval between two rising pulses, to calculate i/p freq.
if the i/p frequency is >= 337Hz .i have to increment "sec_counter".
if the sec_counter incremented 334 times i.e. 1 sec. i have to increment "number".
And that incremented "number" value i have to display on glass lcd(in 5.1 digit format).
Also i want know how to display digits in 5.1 format.
here is my modified code.
Code: | #include<16F913.h>
#fuses INTRC_IO,NOWDT,PUT,/*****/MCLR,PROTECT,NOCPD,NOBROWNOUT,NOPROTECT,NOIESO,NOFCMEN //external MCLR bcz of MPLAB ICD2
#use delay(clock=8000000)
/////////////////////////////////////////////////////////////////////////////////////////
// LCD Configuration //
/////////////////////////////////////////////////////////////////////////////////////////
// Digit segments A B C D E F G DP
// b7 b6 b5 b4 b3 b2 b1 b0
#define DIGIT1 COM3+6, COM2+6, COM0+6, COM1+6, COM0+5, COM3+5, COM2+5, COM1+5 // DISPALYS FROM RIGHT SIDE
#define DIGIT2 COM3+7, COM2+7, COM0+7, COM1+7, COM0+4, COM3+4, COM2+4 // DISPALYS FROM RIGHT SIDE
#define DIGIT3 COM3+8, COM2+8, COM0+8, COM1+8, COM0+3, COM3+3, COM2+3 // DISPALYS FROM RIGHT SIDE
#define DIGIT4 COM3+9, COM2+9, COM0+9, COM1+9, COM0+2, COM3+2, COM2+2 // DISPALYS FROM RIGHT SIDE
#define DIGIT5 COM3+11, COM2+11, COM0+11, COM1+11, COM0+1, COM3+1, COM2+1 // DISPALYS FROM RIGHT SIDE
#define DIGIT6 COM3+12, COM2+12, COM0+12, COM1+12, COM0+0, COM3+0, COM2+0 // DISPALYS FROM RIGHT SIDE
#define VLCD_ENABLE 0x10
#define BLANK 0
void init_CPU();
//character 0 1 2 3 4 5 6 7 8 9
byte const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6};
byte lcd_pos ;
int16 isr_ccp_delta;
unsigned int16 sec_counter;
void lcd_putc(char c)
{
byte segments;
if(c=='\f')
lcd_pos=0;
else {
if((c>='0')&&(c<='9'))
segments=Digit_Map[c-'0'];
else
segments=BLANK;
switch(lcd_pos)
{
case 1: lcd_symbol(segments,DIGIT6); break; // fill 1s place
case 2: lcd_symbol(segments,DIGIT5); break; // fill 10s place
case 3: lcd_symbol(segments,DIGIT4); break; // fill 100s place
case 4 : lcd_symbol(segments,DIGIT3); break; // fill 1000s place
case 5 : lcd_symbol(segments,DIGIT2); break; // fill 10000splace
case 6 : lcd_symbol(segments,DIGIT1); break; // fill 10000s place
}
}
lcd_pos++;
}
#int_ccp1
void ccp1_isr(void)
{
int16 current_ccp;
static int16 old_ccp = 0;
// Read CCP1 register
current_ccp = CCP_1;
isr_ccp_delta = current_ccp - old_ccp;
old_ccp = current_ccp;
}
void main()
{
int16 current_ccp_delta;
int16 frequency;
long number = 0;
sec_counter = 0;
init_CPU();
while(TRUE)
{
printf(lcd_putc,"\f%6lu",number); // how to display a decimal point.
disable_interrupts(GLOBAL);
current_ccp_delta = isr_ccp_delta;
enable_interrupts(GLOBAL);
// internal freq is 8Mhz, So timer1 clock is 2 MHz ,if i/p freq. is 337 Hz
//period is about 2997 usec.prescelar is 1:1 for timer1.
frequency = (int16)(2000000L / current_ccp_delta);
if(frequency >= 337 )
{
sec_counter++;
if(sec_counter == 334 ) // to increment "number" after 1 sec.
{
sec_counter = 0;
if(number++==100000) // 5.1 digit display counter.
number=0;
}
}
}
}
void init_CPU()
{
/************** PORT SETTINGS ****************/
PORT_B_PULLUPS(0XC0); // RB7 & RB6 i/p for programming devices.
SET_TRIS_A(0X80); //
SET_TRIS_B(0XC0);
SET_TRIS_C(0X27); //VLCD 1,2,3 i/p
SET_TRIS_E(0X08); // RE3 i/p for programming the device.
/*************** LCD SETTINGS ********************/
SETUP_LCD( LCD_MUX14 | LCD_INTRC |VLCD_ENABLE , 2);
/**************** COMPARATOR SETTINGS ***************/
SETUP_COMPARATOR(NC_NC_NC_NC);
/**************** INTERRUPT SETTINGS *****************/
ENABLE_INTERRUPTS(GLOBAL);
// ENABLE_INTERRUPTS(INT_TIMER1); //enable timer1 interrupt
/***************************************************************/
// Setup Timer1 and CCP1 for Capture mode so that
// we can measure the input signal's frequency.
set_timer1(0);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_ccp1(CCP_CAPTURE_RE); //Capture on rising edge
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
}
|
If u need further information plz let me know.
awaiting for ur reply. _________________ Thank You,
With Best Regards,
Deepak. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 21, 2007 11:26 pm |
|
|
You must test and debug your code. I'm not going to do it for you. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|