![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Linxroot
Joined: 16 May 2011 Posts: 17
|
problem with capture #INT_CCP1 PIC16F877A |
Posted: Mon May 16, 2011 11:30 am |
|
|
I have some experience with PIC16F877A and CCS, but never used CCP interrupt. I used the code below, but does not work! Proteus 7.6 and tested on hardware as well and nothing!
Code: |
#include <16f877A.h>
#use delay(clock=4000000)
#fuses XT, NOPROTECT
#INT_CCP1
void isr_ccp1()
{
output_high(pin_d0);
}
void main()
{
setup_timer_1 (T1_INTERNAL);
setup_ccp1(CCP_CAPTURE_RE);
enable_interrupts(global);
enable_interrupts(INT_CCP1);
while(TRUE)
{
output_high(pin_d1);
delay_ms(100);
output_low(pin_d1);
delay_ms(100);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 16, 2011 12:57 pm |
|
|
Describe the input signal that you have on Pin C2. What's the frequency
of the signal, and what are the high and low level voltages ? Is it a
rectangular waveform or is it a sinewave ?
Also, what's your compiler version ? |
|
![](templates/subSilver/images/spacer.gif) |
Linxroot
Joined: 16 May 2011 Posts: 17
|
|
Posted: Tue May 17, 2011 7:38 am |
|
|
PCM programmer wrote: | Describe the input signal that you have on Pin C2. What's the frequency
of the signal, and what are the high and low level voltages ? Is it a
rectangular waveform or is it a sinewave ?
Also, what's your compiler version ? |
I am using clock generator 50Hz in ISIS Proteus and in the hardware I AM using a square wave generator 50 Hz. (0-5Volts).
I also tested conecting the RC2 to VDD through a switch, but nothing happens, also tested a 5k6 resistor to pull up and connected to VSS through RC2 through a switch but neither worked. Everything has been tested on Proteus and in the Hardware too.
PCW 4.0.0.206 Proteus 7.6 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Linxroot
Joined: 16 May 2011 Posts: 17
|
|
Posted: Thu May 19, 2011 11:28 am |
|
|
My Compiler version is:
CCS PCM C Compiler, Version 4.013, 28193 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 19, 2011 12:54 pm |
|
|
That's an old and very buggy version. I don't have it, so there is no way
for me to look at the .LST file to see any problems. |
|
![](templates/subSilver/images/spacer.gif) |
Linxroot
Joined: 16 May 2011 Posts: 17
|
|
Posted: Fri May 20, 2011 3:09 pm |
|
|
PCM programmer wrote: | That's an old and very buggy version. I don't have it, so there is no way
for me to look at the .LST file to see any problems. |
CCS PCM C Compiler, Version 4.013, 28193 20-mai-11 18:02
Filename: C:\x\teste port.lst
ROM used: 128 words (2%)
Largest free fragment is 2048
RAM used: 16 (4%) at main() level
17 (5%) worst case
Stack: 2 worst case (1 in main + 1 for interrupts)
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 053
0003: NOP
0004: MOVWF 7F
0005: SWAPF 03,W
0006: CLRF 03
0007: MOVWF 21
0008: MOVF 0A,W
0009: MOVWF 20
000A: CLRF 0A
000B: MOVF 04,W
000C: MOVWF 22
000D: MOVF 77,W
000E: MOVWF 23
000F: MOVF 78,W
0010: MOVWF 24
0011: MOVF 79,W
0012: MOVWF 25
0013: MOVF 7A,W
0014: MOVWF 26
0015: MOVF 7B,W
0016: MOVWF 27
0017: BCF 03.7
0018: BCF 03.5
0019: MOVLW 8C
001A: MOVWF 04
001B: BTFSS 00.2
001C: GOTO 01F
001D: BTFSC 0C.2
001E: GOTO 032
001F: MOVF 22,W
0020: MOVWF 04
0021: MOVF 23,W
0022: MOVWF 77
0023: MOVF 24,W
0024: MOVWF 78
0025: MOVF 25,W
0026: MOVWF 79
0027: MOVF 26,W
0028: MOVWF 7A
0029: MOVF 27,W
002A: MOVWF 7B
002B: MOVF 20,W
002C: MOVWF 0A
002D: SWAPF 21,W
002E: MOVWF 03
002F: SWAPF 7F,F
0030: SWAPF 7F,W
0031: RETFIE
0032: BCF 0A.3
0033: BCF 0A.4
0034: GOTO 035
.................... #include <16f877A.h>
.................... //////// Standard Header file for the PIC16F877A device ////////////////
.................... #device PIC16F877A
.................... #list
....................
.................... #use delay(clock=4000000)
*
003E: MOVLW 2A
003F: MOVWF 04
0040: BCF 03.7
0041: MOVF 00,W
0042: BTFSC 03.2
0043: GOTO 052
0044: MOVLW 01
0045: MOVWF 78
0046: CLRF 77
0047: DECFSZ 77,F
0048: GOTO 047
0049: DECFSZ 78,F
004A: GOTO 046
004B: MOVLW 4A
004C: MOVWF 77
004D: DECFSZ 77,F
004E: GOTO 04D
004F: GOTO 050
0050: DECFSZ 00,F
0051: GOTO 044
0052: RETLW 00
.................... #fuses XT, NOPROTECT
....................
.................... int count=0;
*
005E: BCF 03.5
005F: CLRF 28
....................
.................... #INT_CCP1
.................... void isr_ccp1()
.................... {
.................... count++;
*
0035: INCF 28,F
.................... output_high(pin_d0);
0036: BSF 03.5
0037: BCF 08.0
0038: BCF 03.5
0039: BSF 08.0
.................... }
....................
....................
003A: BCF 0C.2
003B: BCF 0A.3
003C: BCF 0A.4
003D: GOTO 01F
.................... void main()
.................... {
*
0053: CLRF 04
0054: BCF 03.7
0055: MOVLW 1F
0056: ANDWF 03,F
0057: BSF 03.5
0058: BSF 1F.0
0059: BSF 1F.1
005A: BSF 1F.2
005B: BCF 1F.3
005C: MOVLW 07
005D: MOVWF 1C
.................... setup_timer_1 (T1_INTERNAL);
*
0062: MOVLW 85
0063: MOVWF 10
.................... setup_ccp1(CCP_CAPTURE_RE);
*
0060: MOVLW FF
0061: MOVWF 29
*
0064: BSF 29.2
0065: MOVF 29,W
0066: BSF 03.5
0067: MOVWF 07
0068: BCF 03.5
0069: CLRF 17
006A: MOVLW 05
006B: MOVWF 17
.................... enable_interrupts(global);
006C: MOVLW C0
006D: IORWF 0B,F
.................... enable_interrupts(INT_CCP1);
006E: BSF 03.5
006F: BSF 0C.2
....................
.................... while(TRUE)
.................... {
.................... output_high(pin_d1);
0070: BCF 08.1
0071: BCF 03.5
0072: BSF 08.1
.................... delay_ms(100);
0073: MOVLW 64
0074: MOVWF 2A
0075: CALL 03E
.................... output_low(pin_d1);
0076: BSF 03.5
0077: BCF 08.1
0078: BCF 03.5
0079: BCF 08.1
.................... delay_ms(100);
007A: MOVLW 64
007B: MOVWF 2A
007C: CALL 03E
.................... }
007D: BSF 03.5
007E: GOTO 070
.................... }
007F: SLEEP
Configuration Fuses:
Word 1: 3F71 XT NOWDT PUT NODEBUG NOPROTECT BROWNOUT NOLVP NOCPD NOWRT
Which version do you use PCM? Would you build for me in the Proteus test? I've tried everything but does not work! I'll try changing the version of the compiler, as you said it has many bugs, could be it! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 20, 2011 5:39 pm |
|
|
I compared the .LST file code to vs. 4.014 and it's the same. So then I
compiled your code with vs. 4.014 and tested it in hardware. It works.
I added the changes shown in bold below, to make it easier to see that
Pin D0 was initially low, and then after it gets the interrupt, it goes high.
Quote: |
#include <16f877A.h>
#use delay(clock=4000000)
#fuses XT, NOPROTECT
int count=0;
#INT_CCP1
void isr_ccp1()
{
count++;
output_high(PIN_D0);
}
void main()
{
output_low(PIN_D0); // Initialize Pin D0 to a low level
delay_ms(2000); // 2 second delay
setup_timer_1 (T1_INTERNAL);
setup_ccp1(CCP_CAPTURE_RE);
enable_interrupts(global);
enable_interrupts(INT_CCP1);
while(TRUE)
{
output_high(pin_d1);
delay_ms(100);
output_low(pin_d1);
delay_ms(100);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Linxroot
Joined: 16 May 2011 Posts: 17
|
problem with capture #INT_CCP1 PIC16F877A (Solved) |
Posted: Sun May 22, 2011 5:09 pm |
|
|
PCM programmer wrote: | I compared the .LST file code to vs. 4.014 and it's the same. So then I
compiled your code with vs. 4.014 and tested it in hardware. It works.
I added the changes shown in bold below, to make it easier to see that
Pin D0 was initially low, and then after it gets the interrupt, it goes high.
Quote: |
#include <16f877A.h>
#use delay(clock=4000000)
#fuses XT, NOPROTECT
int count=0;
#INT_CCP1
void isr_ccp1()
{
count++;
output_high(PIN_D0);
}
void main()
{
output_low(PIN_D0); // Initialize Pin D0 to a low level
delay_ms(2000); // 2 second delay
setup_timer_1 (T1_INTERNAL);
setup_ccp1(CCP_CAPTURE_RE);
enable_interrupts(global);
enable_interrupts(INT_CCP1);
while(TRUE)
{
output_high(pin_d1);
delay_ms(100);
output_low(pin_d1);
delay_ms(100);
}
} |
|
If you tested and it worked then it was only a few possibilities:
Compiler;
Chip Programmer;
Proteus;
My Hardware;
As you said the compiled version I used was full of bugs,
then installed the v4.068 and tested the HEX in Proteus, but nothing! It did not work
then went to the test on Hardware then yes, it works!!!!!
At last! But the Proteus 7.6 not worked, but I had
read about problems of interruptions simulation in Proteus. The important thing is the hardware and worked great! Thank you for your help!
To summarize:
Problem number 1 - Bug in compiler v4.013
(a marker of interruption did not appear in the register as the PIC Simulator);
Problem number 2 - The Proteus was not able to simulate the interrupt (for some reason maybe a bug).
Again thanks for the help! |
|
![](templates/subSilver/images/spacer.gif) |
yixzon
Joined: 14 Jun 2011 Posts: 5
|
linxroot |
Posted: Tue Jun 14, 2011 7:57 pm |
|
|
hey body, please can u send me ur simulation in proteous and the code u use to compilate, i have to do a project and it may help me thanks!!
my email is clarpopo@hotmail.com |
|
![](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
|