Author Topic: Driving IC clocks  (Read 3799 times)

0 Members and 1 Guest are viewing this topic.

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Driving IC clocks
« on: December 13, 2017, 12:05:15 pm »
Hi All,

New commer to the EEVBlog forums here, but been watching Dave do his thing on YT for a number of years now... (Dave if you read these posts, Dude... you crack me up, your nuts... :-) but awesome with it )

Anyway.....

First a little background
---------------------------
I'm not wet behind the ears when it comes to EE but I'm not a die-hard pro either.  I first passed my computing and digital electronics degree in the early 1990's, but I unfortunately went on to work in Mobile/GSM communications, then ultimately stuck with computer software, which today accounts for about 98% of the work I do.

Recently, Iv'e decided to get back into embedded computing and digital electronics, and to say things have changed somewhat is a bit of an understatement :-)

Iv'e gotten myself some Arduino Megas, and a couple of RPi's and been trawling eBay/Banggood getting hold of some cheap IC's etc to experiment with (I prefer cheap because them I'm not so gutted if I release the magic smoke from them)

One of the job lots I picked up, was a tube of "Microchip 16F54"'s, seemed like a good buy, until I found out they didn't have an internal oscillator.

Now onto my question
-------------------------
Iv'e had a little success getting an RC network working, but it was very jittery, and not particularly stable.  The 16F54 is not a particularly powerful PIC, in fact it's basically one 8 BIt I/O port and one 4 BIt I/O port (Spec is here : https://www.jprelec.co.uk/pdffiles/pic16c57c.pdf ,a quick Goog will get you the full Data Sheet. ) , but I don't want to waste them, so I'm thinking about just using them as programmable I/O expanders.

However, I dont think I have the board space to create an RC for every chip (I have 25 of them on my desk at the mo) and I don't believe I can share an RC between multiple chips either.

I do note from the Data Sheet however, that Microchip mentions, it's easy to drive these devices off of a 1 wire clock produced by another device.

That got me thinking.....

I also have a DSPIC30F4011 DSP, that has an internal Oscillator and can apparently do 40Mhz but try as I might, even at a dramatically slowed down speed, and even using an RC with the same values, I just cannot get the DSPIC30F and it's clock out (or a rapidly changing digital pin) to clock to 16F54.

I also tried to see if I could clock it using a custom PWM frequency coming out of the Arduino Mega and failed on that too (Trying to calculate the correct values fro timers 2/3 or the Arduino to change the PWM frequency is mind bending to say the least...  The maths are.... well....  let's leave it there shall we :-)    )

Anyway, I guess what I'm asking is can I have some guidance here on

a) Putting together a proper RC network for multiple chips, and also some advice on crystals/resonators too
b) Clocking these devices from another source such as the DSPIC30F4011 and/or an Arduino

Iv'e also gotten some IC's from some old 70's/80's devices (Namely sound chips from computers in my childhood) and they too need clock lines to drive them, and well I guess I'm just not making a very good job of it all.  This old brain's forgotten most of the electronics theory it learned over 30 years ago :-)

Thanks in advance to all those that help.

And to those who celebrate it, happy holidays and seasons greetings.....

and Dave.....   Keep up the great work, keep making people laugh.  I saw the Xamarin video the other week, if anyone here wants software advice in .NET/C# then I'm your man.....

Shawty
Meh....
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Driving IC clocks
« Reply #1 on: December 13, 2017, 03:09:16 pm »
Long story short, the 80’s clock radios got the mains frequency from another winding around the mains transformer.

You can use some logic chip as a buffer to distribute clock signals,
and many example circuits out there to use a crystal for a micro.

Microchip still do free samples as far as I’m aware, so no need to worry over wasting some.
Grab something more up to date if you want to wait.
« Last Edit: December 13, 2017, 03:12:12 pm by @rt »
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #2 on: December 13, 2017, 03:39:05 pm »
Tks :-)

The old IC's I have are actually standard TTL Logic (Sound chips from a BBC Micro, and an AY-3-8013 from I believe a mega drive) so I figure I can clock them off a standard TTL Line??

As for the PIC's maybe your right, I should potentially just grab a tube of a more recent PIC16F series chip that has a built in oscillator, but as I say, I hate to waste stuff.

Have you ever tried to use an Arduino to generate a clock signal for another device, if so how did you achieve it?
Meh....
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Driving IC clocks
« Reply #3 on: December 13, 2017, 04:08:21 pm »
You can generate a clock for a pic with a 555, or whatever you want to throw at it.
or you can probably even lick your fingers and touch the clock pin.

No, I’ve used a pic to temporarily replace the TTL clock of another retro computer.. a Commodore Amiga,
so I could vary it’s master clock (within the small tolerance that the analogue video will still work).

Microchip won’t give you a free tube as samples, but you could get a pair of several varieties last time I did it.

If the Arduino has some hardware PWM, just use that to clock something.
If you need software just:

Code: [Select]
forever = 1;
while (forever == 1) {
if (output_pin != 0) {output_pin = 0;} else {output_pin = 1;}
} // forever

Or for an assembler platform just as a pic, just increment a single bit which will overflow and toggle itself.

 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Driving IC clocks
« Reply #4 on: December 13, 2017, 04:12:58 pm »
If you don’t care about anything modern, go for pic16F628 or 16F628A.
Compatibility with the 16F84/16F84A (the most popular in history), but with more memory, options, and peripherals.
... and also very close to what you already have.
 

Offline Maxlor

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: ch
Re: Driving IC clocks
« Reply #5 on: December 13, 2017, 05:17:51 pm »
I also have a DSPIC30F4011 DSP, that has an internal Oscillator and can apparently do 40Mhz but try as I might, even at a dramatically slowed down speed, and even using an RC with the same values, I just cannot get the DSPIC30F and it's clock out (or a rapidly changing digital pin) to clock to 16F54.

Did you remember to program the PIC for XT or HS mode using the configuration register? Maybe you left it in RC mode, in which case, driving it with an external clock won't work.
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #6 on: December 13, 2017, 05:44:15 pm »
Yup, that was the first thing I checked.

As well as that, I tried all the diff values.  The DSPIC30F is purring along quite happily pushing out a signal on it's clock out (Which Microchip repeatedly say is designed for what I'm attempting to do, but then neglect to go into any detail [I swear there marketing department write their datasheets...] ) but the 16F54 just never seems to pay any attention to it.

Likewise, when I feed a signal from the Arduino too, it just seems to ignore it.

Unfortunately, I don't have a scope, so I can't confirm that I'm getting the correct speed from the clock out, testing it using the PicKit3 in logic analyzer mode does seem to suggest I'm getting a square wave out however.
Meh....
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Driving IC clocks
« Reply #7 on: December 13, 2017, 06:24:03 pm »
What data sheet are you two reading? I’m looking at 16F54.

For RC clock config option, the clock input becomes a Schmidt trigger input, that’s all.
RC is the only clock config option that provides buffered clock output on CLKOUT (f / 4).

Marketing department? Begin reading at page 21 for a schematic detail of every possible clock option.

http://ww1.microchip.com/downloads/en/DeviceDoc/41213D.pdf
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #8 on: December 13, 2017, 07:08:52 pm »
Ah, I see where your getting mixed up at :-)

Ok...

It's the 16F54 that's to be the target of the clock signal, that I'm trying to generate.

I've tried to generate the clock from:

A DSPIC30F4011

and from:

An Arduino Mega , using custom frequencies on a PWM Pin.

The only time I got anything from the 16F54 was using an RC network, but it was by pure chance, the caps I used where tiny, so iv'e no idea what value they where/are and the resistors are all cheap Chinese ones, so trying to make out the colors on them without a high power microscope is a challenge.  Result is, I have no idea what the resistor values I used where either.

I want to try and clock the 16F54 from either the DSPIC30F or from the Arduino because I feel that's going to give me a more stable oscillation, but as of yet, I'm not having much success.

I'd happily go buy a whole load of new (Easier to read) components, if I knew that It was definitely going to allow me to run stuff reliably off of an RC network, but given that I have 25 of these things, I'm apprehensive as to whether I can run them all off of the same RC circuit, I don't believe I can.

So I'd like to explore driving the clock from another device, before I go component shopping, but I'm just not getting it right somewhere, and I'm amiss trying to figure out what I'm not doing correctly.

I'm sure the devices I'm using as generators are generating, because the measuring Iv'e done using my PicKit3 in Logic Analyzer mode, suggests I am, but the PicKit is not accurate enough to tell me my exact frequency, and I don't have access to a scope at present.

Hopefully that makes things a little clearer.

:-)
Meh....
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: Driving IC clocks
« Reply #9 on: December 13, 2017, 11:42:22 pm »
It should not be that difficult.  An external clock is applied to the clock input pin and the clock output pin is left disconnected or used as a clock source for other circuits.

If necessary, various input networks can be used to adapter a low or high amplitude clock source to the needed level.

 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #10 on: December 14, 2017, 10:37:11 am »
@David Hess, yes that's exactly what I thought, but I just can't seem to be able to make it work.

Hence why I'm wondering if anyone on here's done anything similar before now, and if so can you give me the inside track on it pls. :-)
Meh....
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Driving IC clocks
« Reply #11 on: December 14, 2017, 01:28:45 pm »
Yes, I haven’t misunderstood at all.
I’ve use a dsPic to drive a master clock for another computer, and perhaps there’d possibly be an issue with the voltage translation between the two, but I doubt it.

So what I have done.. you can clock a pic here in a room of electronics and energy saver lights with 10cm of wire floating from the clock pin hanging in the air.
If you made code to flash an LED, you could literally step that code by touching some pins as well as the clock with a wet finger.
I’m pretty sure I could take one out the yard and piss on it to get it to step through code.

From page 21 on the data sheet, your RC input is described.
In fact, I don’t see any data suggesting that the pic will output a clock for any other config setting than RC clock.

You mentioned you have no scope.
Why not write a small program to toggle an output pin at an audio frequency just to check it out?


« Last Edit: December 14, 2017, 01:30:29 pm by @rt »
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #12 on: December 14, 2017, 01:35:57 pm »
@rt - yup, that's what I'm on doing now :-)

I kinda hoped that I could manually clock it too, EG: with a button, so trying to see if anything happens on that front to.

Cheers
Meh....
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12855
Re: Driving IC clocks
« Reply #13 on: December 14, 2017, 02:10:58 pm »
You'll need to debounce the button or it will be very unpredictable.  Also, after you've debounced it, it will take four presses to execute a single instruction, so you'll go crazy trying to count your way through a simple program. (did I press that button 39 times or 40 times?)

IMHO its not worth the grief.   Get a PIC16F88 - it has a compatible pinout, a better instruction set and built-in debug silicon, so all you need to do is reserve its ICSP pins (i.e. don't put any external crap on those pins apart from a 10K pullup on /MCLR + connections to any Microchip debugger), and you can step through your code in the MPLAB IDE and have the PIC physically execute each instruction.   Its also got an internal oscillator, programmable in 2N multiple steps between 125KHz and 8MHz and is pretty forgiving what crystals it will run with if you need a more accurate clock frequency.

If you are dealing mostly with older PICs and are using an older Windows PC, you may do better with the legacy MPLAB v8.92 rather than MPLAB X.  Its a lot lighter and more stable on older machines but of course has ZERO support for newer devices released in the five years since its final version.   http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_IDE_8_92.zip
« Last Edit: December 14, 2017, 07:34:11 pm by Ian.M »
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #14 on: December 14, 2017, 03:23:15 pm »
Yea, that's the biggest issue I have with the PIC's I'm using, the fact they don't have a built in Oscillator.

Hind sight and all that though :-)

I also want to drive some SN76489's and an AY-3-8913 chips too, and like a lot of discrete logic from the same time period, they like many 74LS series devices also need a clock line pulsing on them.

As with the 16F54 the clock signals I'm attempting to generate just don't seem to be getting picked up by the devices, yet when I put the logic probe on the signal, I clearly am getting something out, and likewise if I tie an LED across the signal and sink it to ground with a 220ohm I get a very fast flicker through the LED, so there's defo a signal going through.

In the case of the sound chips, I'm wondering if maybe they are working, but the output is just too low for me to hear.  That said, I am pushing it through the amplifier on my PC, so I would have though that would have made something audible.

I think I have a tube of CD4017's (Decade counters) somewhere, I wonder if I could chuck something together with those to act as a testing circuit... hmmmm

As for MP-Lab-X not at all worried about that, I have the latest version installed, and working with my PicKit3 programmer

I'm using the PicKit3 as a logic analyzer at the moment though :-)
« Last Edit: December 14, 2017, 03:24:55 pm by shawty »
Meh....
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Driving IC clocks
« Reply #15 on: December 14, 2017, 04:37:41 pm »
You’d only need to connect LEDs to any two outputs of a counter to know the clock is cycling.
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #16 on: December 14, 2017, 11:15:25 pm »
Yea, Gonna try it at the weekend.

Right now however, my clients don't seem to understand the phrase "At 5pm on Friday I break for my Christmas Holidays"

Or maybe they do, and are being deliberate about trying to get the last ounce of blood out of me......

:-)
Meh....
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: Driving IC clocks
« Reply #17 on: December 15, 2017, 02:10:36 am »
@David Hess, yes that's exactly what I thought, but I just can't seem to be able to make it work.

Hence why I'm wondering if anyone on here's done anything similar before now, and if so can you give me the inside track on it pls. :-)

I have done it with PICs and never had a problem.  As I recall, the oscillator mode was largely irrelevant although Microchip gives recommendations.

Maybe take a step back and test the chips with a known oscillator configuration first?  Maybe they are bad or were damaged at some point.
 

Online NorthGuy

  • Super Contributor
  • ***
  • Posts: 3143
  • Country: ca
Re: Driving IC clocks
« Reply #18 on: December 15, 2017, 04:54:33 am »
One of the job lots I picked up, was a tube of "Microchip 16F54"'s, seemed like a good buy, until I found out they didn't have an internal oscillator.

If you want a good buy, go to http://www.microchipdirect.com where you can find hundreds of modern PIC models, which are either immensely more powerful or dramatically cheaper that this old stuff you buy on eBay. Shipping is only about $10 and there's no minimum order. They all will have internal oscillators which are much more accurate than the external RC oscillators of the last millennium. You also will avoid lots of problems because Microchip fixed lots of things over the years.

May be you feel you have already invested into all chips, but you know what they say: "don't put good money after bad".

 

Offline xaxaxa

  • Regular Contributor
  • *
  • Posts: 248
  • Country: ca
Re: Driving IC clocks
« Reply #19 on: December 15, 2017, 09:50:11 am »
I don't know why no one mentioned powered crystal oscillators; you simply supply power and it will output a clock signal.

These are fairly cheap on aliexpress if you search e.g. "crystal oscillator 3.3V".

To drive multiple chips from the same clock simply use an inverter, e.g. nc7s04 or 74hc14. You can likely drive several chips from a single inverter depending on the frequency.

 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks
« Reply #20 on: December 16, 2017, 02:32:57 pm »
Been playing around today, and just managed to get one of the sound chips to make a noise.

Given that this particular chip needs a stable clock to drive it's oscillators, then getting it to power up and make a constant droning noise, tells me it's osc circuits are working, which means my clock must be working.

Iv'e generated the clock signal using pin 10 on an Arduino Mega ADK, basically by custom programming the timer chips so I get custom frequencies on the PWM outputs.

All I need to do now is to understand the maths behind it all, and that will hopefully allow me to more or less generate and frequencies I need too.

@xaxaxa - yea I hear ya there, but this close to Xmas, I'll not get them delivered in time here in the UK, and once my xmas break is over, it's back to work and I'll not get time to play any further. :-(  I have however just gone through some of the boards and bit's in my junk box last night, and found (and liberated) a 9.3Mhz and a 20Mhz crystal.  The 20 should work on the PIC16F54 as it's upper frequency is 20Mhz, but the sound chip (Well the SN at least) only has a max freq of 4mhz so i'll stick to using the arduino for now.

Cheers
Shawty
Meh....
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Driving IC clocks (My closing post)
« Reply #21 on: December 23, 2017, 03:49:43 pm »
Ok, so after what seems like an absolute age, I actually made this work.

The trick to getting a stable clock from the Arduino (In my case a Mega ADK) depends entirely on the pin you choose.

The timers are only connected to specific pins, and as your pushing the hardware outside of it's normal PWN functionality, then it's also highly dependent on the signal path from the AVR to the output pin, and which components it goes through.

However, in my case I found that I could get a 4Mhz square wave off of pin 10, using the following few lines of code.

Code: [Select]
#define CLOCK 10

void setupFourMhzTimer()
{
  pinMode(CLOCK, OUTPUT);
  TCCR2A = ((1 << WGM21) | (1 << COM2A0)); //0x23;
  TCCR2B = (1 << CS20); //0x09;
 
  OCR2A  = 0x02;
  TIMSK2 = 0x00;
 
  OCR2B  = 0x01;
}

What we are essentially doing here is turning off all of the pre-scaler stuff, as well as the output compare, then just connecting the timer directly to the base MCU frequency with a division.

I'm not going to pretend I know exactly what all the bits do because I don't :-)

What I do know, is it's the 0x01 assigned into OCR2B that's the important one, as that tells the timer to use a divide by 4, which on a 16Mhz device like my Mega, gives a 4Mhz square wave.

I did also get some crystal oscillators, and I got them hooked up, so I can get a stable clock that way on both the sound chips AND the PIC Microcontrollers.

With some fiddling I also get a very basic RC circuit working too, very simple, just +5v into a 10K resistor, then a cremeric capacitor in series, then to ground, and a center tap off of the point between the Resistor and Capacitor to the clock pin on the PIC.

Iv'e no idea what the value of the capacitor is, it came out of a £4 grab bag from the local branch of Maplins it's marked [VM-101K Y1 500~ X1 750~ 1203] I think anyway, the writing is tiny and is difficult to make out, even with a high power magnifier.  However by my calculations of timing a 1 sec loop in code on the PIC, I reckon i was getting about 830000Hz so it was good enough to test with.

Finally, as for the PIC16F54 chips them selves, well rather than waste them, Iv'e found a really good use for them.

As others in this thread have noted, the 16F54 is an old PIC now, and to be fair I didn't realize that when I ordered them, they just looked like an interesting part to experiment with.

They do however have 12 I/O pins and a timer on them, and Iv'e realized that there good enough to make into various 74LS like logic devices, however, I'll open another thread for that, as Iv'e written a load of different firmware's for the chips to turn them into usable logic chips and a few other goodies.




Meh....
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16607
  • Country: us
  • DavidH
Re: Driving IC clocks (My closing post)
« Reply #22 on: December 23, 2017, 06:48:29 pm »
As others in this thread have noted, the 16F54 is an old PIC now, and to be fair I didn't realize that when I ordered them, they just looked like an interesting part to experiment with.

They do however have 12 I/O pins and a timer on them, and Iv'e realized that there good enough to make into various 74LS like logic devices, however, I'll open another thread for that, as Iv'e written a load of different firmware's for the chips to turn them into usable logic chips and a few other goodies.

They could make useful smart I/O expanders including using just one to drive a 2 or 4 digit multiplexed display.  With a 32kHz crystal, they could be used as battery backed up real time clocks (15uA) with a few bytes of battery backed up storage.
 

Offline shawtyTopic starter

  • Regular Contributor
  • *
  • Posts: 90
  • Country: gb
Re: Driving IC clocks (My closing post)
« Reply #23 on: December 23, 2017, 11:28:13 pm »
As others in this thread have noted, the 16F54 is an old PIC now, and to be fair I didn't realize that when I ordered them, they just looked like an interesting part to experiment with.

They do however have 12 I/O pins and a timer on them, and Iv'e realized that there good enough to make into various 74LS like logic devices, however, I'll open another thread for that, as Iv'e written a load of different firmware's for the chips to turn them into usable logic chips and a few other goodies.

They could make useful smart I/O expanders including using just one to drive a 2 or 4 digit multiplexed display.  With a 32kHz crystal, they could be used as battery backed up real time clocks (15uA) with a few bytes of battery backed up storage.

Great Idea :-)

* shawty adds another one to the list.

I'll be putting all these mini firm-wares up on GitHub for everyone to use once I'm done.  I'm just trying to debug a keypad scanner, to scan the switch set-up of a control board I salvaged from an old Sky-HD+ box.  "The Ring Control" for those who know what I'm on about ...
Meh....
 

Offline BrianHG

  • Super Contributor
  • ***
  • Posts: 7727
  • Country: ca
Re: Driving IC clocks
« Reply #24 on: December 24, 2017, 09:41:21 am »
Are you trying to force the CLK input of a PIC16C/F54 when it's set to RC mode?
This doesn't work, or, if it does, you are just lucky due to the series resistance and drive level of your source clock.  (I'm not saying you cant do it...)
To guarantee a functional clock feed to the PIC16F54 clk-in pin, you need to set it's config bits to XT or HS as if you were using a crystal.  Leave the clk-out unconnected, or use it to feed another device.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf