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.

Crystal shenanigans part II

Status
Not open for further replies.

ahydra

New Member
Thanks to all who helped me try to fix my crystal circuit before (see here). I said it was fixed but unfortunately this is not quite the case.

Current circuit diagram:

Code:
  |-<32768>-----|
  |             |
  --[10M]-[220k]-     
  |      |      |                
  --|>o--|      |
  |      |      |
 (18)    v     (18)
  |     out     |
  0V            0V

Legend: <32768> = crystal, [ ] = resistor, ( ) = capacitor
|>o = NOT gate (1/6 of a 4069)

All junctions are connections

I've replaced the original 33pf capacitors with 18pf (in accordance with a formula I found on a webpage about crystals). The output is first buffered through another NOT gate and then connected to my PIC. I also connected it to a pair of 4040s (to divide-by-2 twelve times and then 3 more times, flashing an LED at what should be 1Hz) to check the frequency and it looks OK.

The problem is that, on starting up the circuit, the PIC is failing to pick up the signal. I can actually "fix" it though by quickly powercycling the circuit (the thing is powered from a wallwart via a voltage regulator, if I pull the connection out and put it back in within about 1 second the circuit works properly).

Any longer than 1sec of powerdown and the "fix" does not work. I am puzzled as to why this powercycling fix would work at all when the 4040s can pick up the signal just fine - whether the PIC sees the signal or not, the output from the 4040s is always 1Hz and it doesn't ever stop flashing the LED.

I've tried changing the crystal in case the first one was faulty, but this didn't fix the problem. In case the PIC was causing too much load on the circuit, I also tried starting the crystal circuit first then the PIC after a few seconds but this also didn't work.

I'm guessing the problem is just a small difference in voltage - the 4040s require < 0.3VDD for a logic 0 and > 0.7VDD for a logic 1. The PIC is less sensitive however and needs < 0.2VDD, > 0.8VDD. So if the voltage is between 0.2 and 0.3 for "off" and/or between 0.7 and 0.8 for "on", it would cause the above symptoms.

Any ideas how can I achieve a working circuit every time, not just after a quick powercycle?

Thanks,

ahydra
 
PICs have a built in oscillator that works with 32kHz crystals. Some have a second 32kHz oscillator on TIMER1.

Yep, 16F887 does - but I tried to use this, as follows:

I configured Timer1 with 0x37 (Gate Invert bit off, gate disabled, prescaler of 8, LP oscillator enabled, source = external, timer1 enabled) and wired it up like this between pin 15 (T1OSO) and pin 16 (T1OSI):

Code:
#15---[220k]--|-------|---(33)---0V
             [1M]    [X]
#16-----------|-------|---(33)---0V

[X] = crystal

...and it doesn't work. There is no voltage at all anywhere in the above circuit. :( (I checked the connections, they are all OK)

Strange, because earlier I did manage to get some voltage (circuit still didn't work properly though).

ahydra
 
Last edited:
Hmm those small watch crystals sometimes need lower caps like 12.5pF

Also get rid of all the resistors, I've built the Dragonfly kits and they work great with those wee crystals. Check the manual it includes schematic & source code for a RTC.
 
Removed the resistors (as per Dragonfly schematic) and changed caps to 18pf, the smallest ones I have - still no luck. I think something must be more fundamentally wrong since there is no voltage at all coming from pins 15 or 16.

Edit: OMG. Put me down for 7 idiot points for not realising that it should be 0x3F (bit 3 needs to be enabled)! That is a pretty good reason why there is no voltage... I will test this later this evening (i.e. in about 15 hrs).

ahydra
 
Last edited:
I had similar problem ... most of the 32768 crystals I saw have load capacitance of 6pF so if you connect more then 12pF capacitors - it will not work. You added 18pF and that is just too much. Find smaller caps (6pF or 10pF) and it should work...

With regards to resistors, I as a rule do not use them in 3V circuits and use then in 5V circuits, have no idea why I do it (probably someone told me and I just accepted it or ..)... but in general, in 3V circuits it works ok without resistors...
 
I had similar problem ... most of the 32768 crystals I saw have load capacitance of 6pF so if you connect more then 12pF capacitors - it will not work. You added 18pF and that is just too much. Find smaller caps (6pF or 10pF) and it should work...

These ones have a load capacitance of 12.5pf. Using the formula

Cload = (C1C2/C1+C2) + Cstray

with a Cstray of 5pf, putting C1 = C2 gives me C1 = C2 = 15pf.

I have a feeling the problem may be more to do with the fact my program doesn't switch the external crystal oscillator on. ^^ Will test new program later on tonight...

ahydra
 
Last edited:
Can you post that part of your code?

Code:
  MOVLW 0x37
  MOVWF T1CON				; prescaler of 8, timer in counting mode, gate disabled, LP oscillator enabled

That was the original. I now put a small delay to allow the crystal to start up:

Code:
  MOVLW 0x08
  MOVWF T1CON				; start up crystal circuit 
(enable LP oscillator)

...

crystalstartdelay
  BTFSS PIR1, 1				; test timer2 interrupt
  GOTO crystalstartdelay
  INCFSZ c1, 1
  GOTO crystalstartdelay
  INCF c2, 1
  MOVLW 0x02
  SUBWF c2, 0
  BTFSS STATUS, Z
  GOTO crystalstartdelay
  
  MOVLW 0x3F
  MOVWF T1CON				; prescaler of 8, timer in counting mode, gate disabled, LP oscillator enabled

(Timer2 interrupts happen every 1ms)

Notice the 0x3F instead of the wrong 0x37. The circuit seems to work (using 18pf caps and the 220K resistor but not the 1M).

Now to fix several other bugs and hopefully I will be able to veroboard this thing. Anyone know of a proper way to connect power adaptor plugs (the things you get on the end of wallwarts)? At the moment I am just using a small pin thingy and a crocodile clip (the pin goes into the adaptor plug, and the crocodile clip provides the 0V connection on the outside of the plug)

ahydra

ps. Above code has a bug - anyone spot it? :) (I have fixed it already.)
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top