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

using CCP to create 1KHz signal
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jseidmann



Joined: 04 Nov 2004
Posts: 67

View user's profile Send private message Send e-mail

using CCP to create 1KHz signal
PostPosted: Fri Mar 17, 2006 1:31 pm     Reply with quote

Hi everyone,

In the past I have used the CCP to create a 1KHZ square wave and it worked very well. On my hardware I have a socket and I changed from an 18F252 to a 18F2620 chip for more ROM/RAM. However, I now find that the 1KHz signal that used to be sent is no longer being sent.

Below is some of the pertinent code:

setup_timer_1(T1_INTERNAL);
setup_ccp1(CCP_COMPARE_RESET_TIMER);
setup_ccp2(CCP_COMPARE_INT_AND_TOGGLE);

CCP_1 = 2000;
CCP_2 = 0;

My question is why this no longer works? There is no area in my code to execute something during timer1 execution, but it was handled using the above lines. (I inherited the code from someone else). Does anyone have any idea what I can change to get this to work? Thanks!

p.s. I traced back an earlier problem I posted about to this in the hardware for those of you that saw my previous post.

Thanks!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 17, 2006 2:29 pm     Reply with quote

As I always say, post a very small test program that can be dropped
into MPLAB and compiled without errors. Post your version of the
of the compiler.
jseidmann



Joined: 04 Nov 2004
Posts: 67

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 21, 2006 6:47 am     Reply with quote

Below is the code that works (generate a 1.1KHZ signal on a PIC18F252):

Code:
#include <18F252.h>
#DEVICE *=16 ADC=10
#OPT 9
#include <ctype.h>
#include <stdlib.h>
#include <math.h>

//#define CASCOMM             // CAS communication protocol

// Set up programmer.
#FUSES  HS,WDT16,PUT,BROWNOUT, PROTECT,NOLVP,NOCPD,NOWRT

// Set up M/C clock speed (used for delay loops).

#use delay (clock = 20000000)

// Specify fast I/O with all I/O pins.

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)


void main ()

{
   set_tris_a(0b00001111);
    set_tris_b(0b00000000);
    set_tris_c(0b10010000);



   setup_adc_ports(RA0_RA1_ANALOG_RA3_REF); //!!!!!!!!!
   //setup_adc_ports( AN0_TO_AN1 | VSS_VREF ); //!!!!!!!!!

   setup_adc(ADC_CLOCK_DIV_32);
   set_adc_channel(0);

    setup_timer_1(T1_INTERNAL);                  // Divide by 1.
    setup_ccp1(CCP_COMPARE_RESET_TIMER);        // Set Timer1 Period
    setup_ccp2(CCP_COMPARE_INT_AND_TOGGLE);     // Toggle CCP2 Output

    CCP_1 = 2200;
    CCP_2 = 0;                                  // Set high time limit
   while(1);
}



I then change the library to the 18F2620 and also change one line (marked with a "!!!!!!" because it wont compile on the 18F2620), and run it and NO 1.1KHZ signal is created on Pin C1. Below is the code:

Code:
#include <18F2620.h>
#DEVICE *=16 ADC=10
#OPT 9
#include <ctype.h>
#include <stdlib.h>
#include <math.h>

//#define CASCOMM             // CAS communication protocol

// Set up programmer.
#FUSES  HS,WDT16,PUT,BROWNOUT, PROTECT,NOLVP,NOCPD,NOWRT

// Set up M/C clock speed (used for delay loops).

#use delay (clock = 20000000)

// Specify fast I/O with all I/O pins.

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)


void main ()

{
   set_tris_a(0b00001111);
    set_tris_b(0b00000000);
    set_tris_c(0b10010000);



   //setup_adc_ports(RA0_RA1_ANALOG_RA3_REF); //!!!!!!!!!
   setup_adc_ports( AN0_TO_AN1 | VSS_VREF ); //!!!!!!!!!

   setup_adc(ADC_CLOCK_DIV_32);
   set_adc_channel(0);

    setup_timer_1(T1_INTERNAL);                  // Divide by 1.
    setup_ccp1(CCP_COMPARE_RESET_TIMER);        // Set Timer1 Period
    setup_ccp2(CCP_COMPARE_INT_AND_TOGGLE);     // Toggle CCP2 Output

    CCP_1 = 2200;
    CCP_2 = 0;                                  // Set high time limit
   while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 21, 2006 12:37 pm     Reply with quote

I tested it with PCH vs. 3.245 with an 18F452 and works. I don't have
a 18F2620 to test. The .LST file looks OK for the the 18F2620.

You didn't post your compiler version.


My suggestion is to strip the program completely down.
Turn off all the extra stuff that you had on, like the Watchdog
and code protection. Then see if it works. If it doesn't work
then post your compiler version. Example:
Code:
#include <18F2610.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOPROTECT,NOLVP,CCP2C1
#use delay(clock=20000000)
//=================================
void main()
{
setup_timer_1(T1_INTERNAL); 
setup_ccp2(CCP_COMPARE_INT_AND_TOGGLE);
CCP_2 = 0; 

while(1);
}
 
jseidmann



Joined: 04 Nov 2004
Posts: 67

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 21, 2006 1:02 pm     Reply with quote

PCM,

My compiler version is 3.236. I tried the following code and it worked for 18F252 and not for 18F2620. I tried 2 different 18F2620 PIC's to see if the chip failed, but no luck. The code is below:

Code:
#include <18F2620.h>
#FUSES  HS,WDT16,PUT,BROWNOUT, PROTECT,NOLVP,NOCPD,NOWRT
#use delay (clock = 20000000)
void main ()
{
    setup_timer_1(T1_INTERNAL);                  // Divide by 1.
    setup_ccp1(CCP_COMPARE_RESET_TIMER);        // Set Timer1 Period
    setup_ccp2(CCP_COMPARE_INT_AND_TOGGLE);     // Toggle CCP2 Output

    CCP_1 = 2200;
    CCP_2 = 0;                                  // Set high time limit
   while(1);
}


When changing from the 18F252 to 18F2620 I just changed the include file to <18F2620> and nothing else. Same problem, the signal is generated using the 18F252 and not the 18F2620.

Any suggestions?
newguy



Joined: 24 Jun 2004
Posts: 1903

View user's profile Send private message

PostPosted: Tue Mar 21, 2006 1:05 pm     Reply with quote

How is the extended instruction fuse configured? Try putting NOXINST in the fuses line - I got bit by that once.
jseidmann



Joined: 04 Nov 2004
Posts: 67

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 21, 2006 1:18 pm     Reply with quote

newguy,

after you suggested it, I tried it and unfortunately it did not help. If you have any further ideas though, i'd be glad to hear it.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 21, 2006 2:40 pm     Reply with quote

The code for vs. 3.236 matches that for 3.245. I'm not sure what the
problem is. I don't have a 18F2620 to test, so I don't think I can do
any more.
jseidmann



Joined: 04 Nov 2004
Posts: 67

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 23, 2006 9:36 am     Reply with quote

Does anybody have a PIC18F2620 where they could test out the code that I posted above and see if they can get the 1.1KHz signal? I"m kind of at a loss at what the problem is. Also, if anyone else has suggestions, I am more than glad to try it out.

Thanks!
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Thu Mar 23, 2006 9:56 am     Reply with quote

If you like, I could simulate it in Proteus. However, I couldn't do that until later tonight or the weekend. I would have to compile it in version 3.242 (I think that's what I have)
jseidmann



Joined: 04 Nov 2004
Posts: 67

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 23, 2006 10:14 am     Reply with quote

rberek,

I would appreciate that very much. I think version 3.242 would be fine to use it with. If you let me know the results, I would greatly appreciate it. If it comes out with a simulated 1.1KHz signal, I will give CCS a call and try to figure out whats wrong.

Thanks
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Thu Mar 23, 2006 11:04 am     Reply with quote

OK, I'll let you know.
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Thu Mar 23, 2006 5:21 pm     Reply with quote

Proteus is showing a 1.11 kHz signal coming out of pin12 (CCP2B) of the 18F2620, using your code.
jseidmann



Joined: 04 Nov 2004
Posts: 67

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 24, 2006 7:49 am     Reply with quote

Thank you rberek,

I am at a loss as to what the problem could be. I will e-mail the code to CCS tech support and see if they can get it working. If anyone out there has a PIC18F2620 in use and doesnt mind runing this code to see if it works, I would really appreciate it. I will also post CCS's response to my e-mail once i get it.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 24, 2006 11:36 am     Reply with quote

Your assumption is that if the simulator shows an output, then the
problem must be in the compiler. I would think the opposite.
If it runs in the simulator, then that the problem is more likely to
be in hardware, not in the code. Here is a Proteus simulator page:
http://www.labcenter.co.uk/index.html?/products/pic16.htm

--------------------
Questions:
1. What external circuit is connected to pin C1 on your PIC ?

2. How are you measuring the signal that comes out of pin C1 ?
Are you using an oscilloscope ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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