CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Extremely weird CCP behavior

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tnay



Joined: 11 Feb 2007
Posts: 4

View user's profile Send private message

Extremely weird CCP behavior
PostPosted: Wed May 20, 2009 10:40 am     Reply with quote

Hello everyone,

I have been troubleshooting this problem for hours. I have encounter a very unique problem here. I try to shrink down the code and problem as much as possible. My CCS version is 3.219.

Here's what I need.

I want to call CCP compare on certain given timing, and change pin status. Whenever a match occured, it would first change the pin status, then a value is assigned to CCP_1 for next match. As of this discussion, which pin status to change is not important, but I like to bring your attention to the timing. Say I have 3 value, so generally it goes like this:

First match = value A
Second match = value B
Third match = value C
Repeat.

Here is what happen.
This particular code work for most A, B and C combination, limited to 16-bit. However, there are several occasion where it does not work. For example:
When A = 200, B = 3130;
When A = 250, B = 2363;

Instead of giving me a perfect match (+/- 1), it consistently give out B+60, become like this:

A = 200, B = 3190;
A = 250, B = 2423;

It will only happen when the above value is in this particular sequence and order. I can't figure out any relation between them. The problem seems to only affect PIC18, and not PIC16.

Here is the code that didn't work

Code:

#int_CCP1

CCP1_isr()
{
if(set)
{
   output_C(temp);
   CCP_1 = PWM[count];
   temp = 0x08;
   count++;
   if (count == 2)
      set = 0;
   
}

else
{
   output_C(temp);
   CCP_1 = 10000 - PWM[1] - PWM[2];
   temp = 0x00;
   set = 1;
   count = 0;
}

}

void main()
{
set_tris_c(0x00);
output_C(0x00);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);      // timer1 enabled, instruction clock /8
setup_ccp1(CCP_COMPARE_RESET_TIMER);      // set CCP1 to cause an interrupt on match
enable_interrupts(INT_CCP1);            // unmask compare1 match interrupt
enable_interrupts(global);               // enable all unmasked interrupts

while(1)
;
}



But funny enough, the following code works, every time. the different is that I bring up the temp variable before calling CCP.

Code:
#int_CCP1

CCP1_isr()
{
if(set)
{
   temp = 0x00;
   output_C(temp);
   CCP_1 = PWM[count];
   count++;
   if (count == 2)
      set = 0;
   
}

else
{
   temp = 0x08;
   output_C(temp);
   CCP_1 = 10000 - PWM[1] - PWM[2];
   set = 1;
   count = 0;
}

}

void main()
{
set_tris_c(0x00);
output_C(0x00);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);      // timer1 enabled, instruction clock /8
setup_ccp1(CCP_COMPARE_RESET_TIMER);      // set CCP1 to cause an interrupt on match
enable_interrupts(INT_CCP1);            // unmask compare1 match interrupt
enable_interrupts(global);               // enable all unmasked interrupts

while(1)
;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 20, 2009 11:08 am     Reply with quote

Post a complete test program. Add the lines that are missing, such
as the #include for the PIC, #fuses, #use delay(), and all variable
declarations.
Guest








PostPosted: Thu May 21, 2009 4:08 am     Reply with quote

Sorry for that, I exclude those with the intention of reducing the code length. Totally forget about how others are to run it without the heading.

Anyway, here goes:
Code:
#include <18FXXXX.h>
#fuses HS,NOWDT,NOLVP
#use delay(clock=10000000)

long PWM[2] = {250, 2363};
int temp;
int set = 0;
int count = 0;


Please replace the 18FXXXX with any PIC18F. I tried a few, neither of them don't work. You can also try the 16FXXXX, it works on them though.

The delay is not the focus of this discussion, but the instruction cycle. So any clock speed with do.

Thanks.[/code]
tnay



Joined: 11 Feb 2007
Posts: 4

View user's profile Send private message

PostPosted: Thu May 21, 2009 4:12 am     Reply with quote

Opps. That was me. Forget to sign-in Embarassed Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 21, 2009 10:28 am     Reply with quote

I can't test it without a specific PIC. Post a PIC that it fails with,
and post one that it works with.

Is this a Proteus project ?
tnay



Joined: 11 Feb 2007
Posts: 4

View user's profile Send private message

PostPosted: Sat May 23, 2009 3:41 am     Reply with quote

Try any PIC16F and PIC18F that support CCP. I'm using PIC16F877A and PIC18F458 here. I'm not familiar with Proteus.

I tested the timing using MPLAB SIM. Tested on my prototype circuit, and uses another PIC to capture the timing. It consistently happen around that particular value (+/- 3). Any value of outside that range, be it smaller or larger value, it just disappear.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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