View previous topic :: View next topic |
Author |
Message |
uNO
Joined: 18 Nov 2005 Posts: 10
|
36Khz Square Wave on 16f628A |
Posted: Fri Sep 01, 2006 10:58 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 01, 2006 11:26 am |
|
|
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)
{
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
uNO
Joined: 18 Nov 2005 Posts: 10
|
Still not Working. |
Posted: Sat Sep 02, 2006 4:02 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Sat Sep 02, 2006 4:30 pm |
|
|
The NE555, can drive several hundred mA (typically 200mA). The PIC only 25mA. Try running the PIC without your load...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Sep 02, 2006 8:21 pm |
|
|
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
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? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Sep 03, 2006 7:30 am |
|
|
Thanks PCM, that was the information I was looking for. |
|
![](templates/subSilver/images/spacer.gif) |
uNO
Joined: 18 Nov 2005 Posts: 10
|
Still In troubles |
Posted: Mon Sep 04, 2006 1:36 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 04, 2006 1:50 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
uNO
Joined: 18 Nov 2005 Posts: 10
|
Finally It works |
Posted: Tue Sep 05, 2006 1:05 pm |
|
|
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 ! |
|
![](templates/subSilver/images/spacer.gif) |
|