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 CCS Technical Support

Pic 12f675 oscillations

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



Joined: 16 Aug 2005
Posts: 37
Location: Fredericton,NB

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

Pic 12f675 oscillations
PostPosted: Thu Dec 07, 2006 5:49 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 07, 2006 6:24 pm     Reply with quote

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.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Dec 07, 2006 8:20 pm     Reply with quote

Also, the default is standard_io which the read makes the pin an input which is undesirable for your purpose
joshkeys



Joined: 16 Aug 2005
Posts: 37
Location: Fredericton,NB

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

Thanks
PostPosted: Thu Dec 07, 2006 8:32 pm     Reply with quote

I changed it to a variable and it worked fine. Thanks for the suggestion!

Josh
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