A Clock with the Basic Stamp II




EPIC Program en route

Before i had gotten back from winter break, i had bought a few crystals. Oscillator crystals i mean. Two 32.768kHz for 99 cents, and a 4MHz for 99 cents. After all, i ordered an EPIC programmer and two 16F877 chips before leaving for school, so i'd need crystals for them when they got here. I meant to make the clock and thermometer on one 16Fxx series chip when they got here, but i couldn't wait (and the PIC assembly will probably take longer to write. Anyways, the EPIC programmer kit is scheduled for arrival on monday. I can't wait.

Anyways, the only thing i needed to do to have a clock was have the basic stamp chip wait in a loop till it sensed a clock signal, add 1 to a counter, display the new time, and wait again. Simple right?

Building a Crystal Oscillator

I figure, i can build a precision clock signal out of the 32.768kHz xtal, and step it down with a 14-bit binary counter.

Well, after some experimentation, i managed to get it oscilating. I tried various combinations of small ceramic capacitors, as well as 74HCT14 vs 74HCT04 chips, and after about an hour, i got it oscillating. Just a xtal, the shmidts trigger inverter, and two caps. I was probably overdriving it. Oh well. I'm still learning :)

                 R2                    .----------------+---.
         .-----\/\/\/\----.            >                >   |
         |                |            > R1          R2 >   |
         |      |\        |            >      |\        >   |
         |      | \       |            |      | \       |   |
         +------|  >o-----+            .------|Z >o-----.   |
         |      | /       |            |      | /       |   |
         |      |/        >            |      |/        |   |
         |                >  R1        |                |   |
         |                >            |                |  === C3
         |       X1       |            |       X1       |   |
         +------|[]|------+            +------|[]|------+   |
         |                |            |                |   |
     C1 ===              === C2    C1 ===           C2 ===  |
         |                |            |                |   |
         '-------+--------'            '-------+--------+---'        
                 |                             |
               -----                         -----
                ---                           ---
                 -                             -

Most diagrams look like the one on the left. Mine ended up like the one on the right. R1 and R2 were of 1M ohm apeice, and i think c1 and c2 were both 49 pF caps. If i removed c3, it would work fine. However, on startup it would oscillate at about 15.2kHz until you tapped it a few times. Turns our that without r1 and r2, the resistors and c1 would form an RC oscillator of about half the xtal frequency. I replaced r1 and r2 with one 10M ohm, and took out c3. Bingo. I then added r1 of 10k ohms when i found out you can crack a crystal by overdriving it.

I guess with 10M ohm, the shmidts trigger loses its shmidts-iness (which makes sense if you think about it... it always biases the sened input away from center, meaning that you'll never reach the null zone.. or at least i think that's how it works).

Stepping down to managable speeds

Another inverter is connected from the output of the oscillator inverter, and this output goes to the 14 bit binary counter. 74HCT4040. This steps the frequency down from 32kHz to 2 Hz. I have this output hooked to a 10k ohm resistor and going along a wire to the basic stamp board, to pin 15.

The basic stamp increments the 1/4 second counter on every rising and falling edge. Custom characters are used on the display with this value to have a rotating hand that has 4 positions. The input routine takes in RS232 data to set the time, and then you can let it run on its own without computer aid.

Calibration

After finishing it, i let it run for about 12 hours and found it to be off by about 4 seconds, or 1 click (1/4) second every 1.5 hours (or 21600 clicks), so i have another timer word that increments every click and will add an extra click whenever it rolls over. Since the oscillatore is precise but not accurate, similar to the temperature sensor, the error can easily be adjusted for.


     1 click error
   -----------------  = 0.00463 % error   or    46.3 ppm
     21600 clicks

pictures: The clock in operation

schematic: Schematics