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

36Khz Square Wave on 16f628A

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



Joined: 18 Nov 2005
Posts: 10

View user's profile Send private message

36Khz Square Wave on 16f628A
PostPosted: Fri Sep 01, 2006 10:58 am     Reply with quote

I'm trying to obtain a 36khz square wave with a duty cycle of 50% on a Pic 16f628A clocked by an external crystal at 10Mhz.

This is the code that I'm Using

Code:

#include <16F628A.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP ,NOMCLR
#use delay(clock = 10000000)
void main()
{
   setup_ccp1(CCP_PWM); 
   set_timer0(0);
   setup_timer_2(T2_DIV_BY_1, 68, 1);
   set_pwm1_duty(34);

   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
while(1)
{

}

}


If I simulate with Proteus it give me 36Khz but when I try on a circuiit at home ... It doesn't works.

I need the 36 Khz to turn on and off an Ir Led for a proximity detector, I made a circuit with ne555 and it works greatly, Why it doesn't work with pic ? I'm quite sure that I made a mistake in the code. Please help me.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 01, 2006 11:26 am     Reply with quote

You don't have an interrupt service routine for the RTCC.
You're not even using the RTCC. You're using PWM.
Delete the two lines shown in bold below:
Quote:

#include <16F628A.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP ,NOMCLR
#use delay(clock = 10000000)
void main()
{
setup_ccp1(CCP_PWM);
set_timer0(0);
setup_timer_2(T2_DIV_BY_1, 68, 1);
set_pwm1_duty(34);

enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

while(1)
{

}

}
uNO



Joined: 18 Nov 2005
Posts: 10

View user's profile Send private message

Still not Working.
PostPosted: Sat Sep 02, 2006 4:02 pm     Reply with quote

I've Tryed to remove the wrong lines of code but it is still not Working. The cause cannot be the circuit considering that with the square wave generated by the ne555 it works fine. At this point I'm quite sure that I'm making one ore more mistake in the code, but I can't figure where. Please help me.
Ttelmah
Guest







PostPosted: Sat Sep 02, 2006 4:30 pm     Reply with quote

The NE555, can drive several hundred mA (typically 200mA). The PIC only 25mA. Try running the PIC without your load...

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Sep 02, 2006 8:21 pm     Reply with quote

The result of calling set_pwm1_duty differs depending on the parameter type you pass to it, an int8 or int16. I find this very confusing; parameter overloading is an object oriented feature, not something you expect in a C-compiler.

I tried to understand the different results of calling
Code:
set_pwm1_duty(34);

or
Code:
set_pwm1_duty(34L);

The generated code is different but I didn't quiet get it. Maybe someone else can tell me which version is giving the expected result of a 50% duty-cycle?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Sep 02, 2006 11:23 pm     Reply with quote

See near the end of this thread. I was looking for one of my old
explanations and I discovered Ttelmah has got a better one:
http://www.ccsinfo.com/forum/viewtopic.php?t=24055
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Sep 03, 2006 7:30 am     Reply with quote

Thanks PCM, that was the information I was looking for.
uNO



Joined: 18 Nov 2005
Posts: 10

View user's profile Send private message

Still In troubles
PostPosted: Mon Sep 04, 2006 1:36 pm     Reply with quote

Thank you for your interest. The current to turn the Led On isn't flowing in the pic but on a transistor so the Mistake cannot be in the excessive current on the pic. The sensor works good with the Remote control of the Tv So the mistake cannot be in the receiver module. I've no more ideas.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 04, 2006 1:50 pm     Reply with quote

Post your compiler version.

To find the version, look at the top of the .LST file in your project folder.
The version will be a 4-digit number such as 3.191, 3.236, 3.249, etc.
uNO



Joined: 18 Nov 2005
Posts: 10

View user's profile Send private message

Finally It works
PostPosted: Tue Sep 05, 2006 1:05 pm     Reply with quote

Without no more Ideas i started to replace all of the component on my testing circuit and replacing the crystal all started to work properly. I don't have great experience in building circuit but it's the first time that I see something like this.
Thank you all !
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