Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Problem with external oscillator (PIC16F628A)

Status
Not open for further replies.

nomdomokunnom

New Member
Hi guys, I'm new to using microcontrollers so I'm probably missing something obvious here, but I'm planning on trying to use a PIC16F628A to start experimenting with USB communication, but I haven't used an external oscillator before so I thought I'd give it a try. I've connected a 12MHz crystal oscillator between pins 15 and 16 (OSC1 and OSC2), and connected both pins to ground via 22pF capacitors as recommended in a diagram I found online, but my simple test program isn't working (it worked when using the internal oscillator). Anyone have any ideas what's wrong?

I have the circuit set up in a breadboard, with LEDs between Vdd and PA1 and PB4 respectively, and I'm compiling my program with BoostC++ compiler and programming it using a pickit2.

When using the internal oscillator, the port A LED stayed on while the port B LED flicked on and off, as expected; with the external oscillator, neither LED ever lit.

My source code:

Code:
#include <system.h>
//#include "USB1.h"

#pragma DATA 0x2007, _BODEN_ON & _CP_OFF & _DATA_CP_OFF & _PWRTE_ON & _WDT_OFF & _LVP_OFF & _MCLRE_ON & _XT_OSC

/*
class USBConnection
{

};
*/

void main()
 {
 clear_bit(trisa,1);
 clear_bit(trisb,4);
 
 clear_bit(porta,1);
 set_bit(portb,4);
 
 while(true)
  {
  clear_bit(portb,4);
  for(int i=0;i<5000;i++);
  set_bit(portb,4);
  for(i=0;i<5000;i++);
  }
 }

Thanks in advance for any help.
 
Last edited:
Thanks, that did it; unfortunately I only have a pretty basic grasp of how the oscillator works and had no idea what the XT meant, I just copied it from a bit of sample code. Googletime, methinks.

EDIT: Ah, and google tells me HS means high speed, which 12MHz seems to qualify for. Thanks again.
 
Last edited:
Well, I have the same problem, except that my HS fuse is already set correctly. I notice that if I tap the resonator lightly with my finger I can get it to start (but not run consistently). I guess there is a capacitance or resistance issue at the resonator. Any suggestions about adding some extra resistance or capacitance to fix this, and if so, where would be best to avoid unnecessary power consumption? Thanks.
 
Is it on a plug in breadboard? If so remove the resonator/xtal caps altogether.

Also please check you have tied MCLR high to 5v, usually with a 1k resistor is best for most breadboard apps. If you have not tied MCLR properly you can get a lot of weird startup issues.

Also check both XT and HS modes, some xtals seem to prefer the wrong mode.
 
somewhat solved

Thanks for the XT suggestion! That seems to do the trick, as does a 1M or so resistor (i.e. my finger, which was the simplest way to check for now;) held across the resonator outside leads. Perhaps XT mode just adds a resistor on top of HS mode along the same lines as I did?
My question then becomes about the power consumption. With XT mode does the microcontroller use more power? With the resistor I guess it would also, and so which solution would be best in that case? Thanks.
 
actually, to continue my thread above. I had the pins wrong and the resonator worked in XT mode (one pin was on Vdd, interesting that it worked!) With correct pins for resonator, I am back to same problem of it only works when I touch it (just on one side now) in either XT or HS mode. !M ohm across the crystal didn't do it, not did adding a 22pf cap between the lead and ground. Any other suggestions?
 
Status
Not open for further replies.

Latest threads

Back
Top