![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
joshkeys
Joined: 16 Aug 2005 Posts: 37 Location: Fredericton,NB
|
Pic 12f675 oscillations |
Posted: Thu Dec 07, 2006 5:49 pm |
|
|
Hi,
I wrote a few weeks ago about problems with 38khz oscillations via op amps.. Well now I am using a PIC 12f675 to produce the oscillations, via turning pin GP2 on and off. It runs via the code below
Code: |
#int_RTCC
RTCC_isr()
{
if (input(pin_a2)==0){
output_bit(pin_a2,1);
}
else{
output_bit(pin_a2,0);}
set_timer0(169);
}
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
set_timer0(170);
while(1){
}
} |
As you can see, i just turn the pin on and off.. it works out to nearly 38Khz exactly.. the problem is if the pin draws more then nearly 1 milliamp of current, the oscillations are screwed up.. it seems to go high fine, then when it goes low, it only stays low for about 1us , and then goes high again until about 1us before it should actually go high, in which it goes low and then back high again 1us later.. hence creating double the frequency of 76khz nearly..
A better description is it seems that when the pin is said to output(0), it momentairly goes low, then seems to get pulled high again until just before it should go to output(1), in which case it drops to a logic low, then back to high.
I have tried using a pull down resistor and it does not help. What i was trying to do was connect the output to the gate of a BJT, and on the collector have a resistor and infrared LED connected in series to Vcc, and the emmitter tied to ground, therefore getting the LED to emit 38khz bursts. But if the output of pin GP2 is tied to a resistor then to the gate, it will have this crazy problems unless the resistance is such that the current is less then 1 milliamp approximatley..
ANy suggestions? or explanations?
Thanks,
Josh
P.s. I am using IDE version 3.215 and PCH version 3.217 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 07, 2006 6:24 pm |
|
|
All you want to do is toggle an output pin. Don't read the pin to
determine its status. Instead, maintain a static variable inside the isr
(or a Global variable outside the isr), and toggle that variable.
Then your code will operate based on pure logic, and not be
dependent upon reading a hardware pin that may be loaded down. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Dec 07, 2006 8:20 pm |
|
|
Also, the default is standard_io which the read makes the pin an input which is undesirable for your purpose |
|
![](templates/subSilver/images/spacer.gif) |
joshkeys
Joined: 16 Aug 2005 Posts: 37 Location: Fredericton,NB
|
Thanks |
Posted: Thu Dec 07, 2006 8:32 pm |
|
|
I changed it to a variable and it worked fine. Thanks for the suggestion!
Josh |
|
![](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
|