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.

Can we use PIC to provide clock to another PIC?

Status
Not open for further replies.
Can we use PIC to provide clock signal for another PIC? the clock signal generated by 1st PIC may not have the duty cycle of 50%.
 

Attachments

  • pic_clock.png
    pic_clock.png
    58.5 KB · Views: 988
Thats not really practical. Since yoµu are feeding the second pic trough a GPIO pin you'll have to toggle it in software.

So for the second pic to run at any decent speed the first one wouldnt have any time to spare because it needs to toggle the pin all the time...

So, if the first pic runs at 20Mhz, that would be 5MIPS, The shortest possible square wave loop would output a freq. of 833Khz max.

This would make the second pic do only instructions at 200Khz while the first one hasn't got ANY time to spare
 
you could potentially do it with the hardware PWM module that some PICs have onboard. If you set it up for 50% duty cycle, it should work fine... although you'll have to check the datasheet to see what kind of a frequency range the PWM module is capable of with a given oscillator... I imagine it will be much lower than the oscillator frequency though, which may or may not be a problem for your application. However, since it's a hardware module, it will run independently of your main program.

however, the real question is WHY? I can't think of very many applications where you'd want to do this...
 
The hardware PWM (wich the 16F84 on the scematic doesnt have) is limited to Khz speeds, again divided by 4, this would make the second pic run very slow...

Why don't you just use a TTL crystal and run both pic's of it?
 
What if i don;t care about how slow the 2nd PIC will be.

The 1st PIC only send a pulse after finish certain part or meet certain condition. So the pulse will be sent at irregular interval.
 
It has to run to be able to do something...

if the first pic does a tight loop (running at 20Mhz!) then the second pic will only do 200Khz...

so if the first pic is busy, then the second one will run hardly at all...

If speed isnt that important why not use a RC oscillator ?
 
Yes, one PIC can provide clock for other PIC(s), but as said before it IS NOT practical. Both PICs can share the crystal oscilator, and you can use PIC1's output to RB0 to start PIC2's required sequence.
 
It seems like it should work... I can't see why you'd want to... but that's not my place to judge :lol:

However, don't forget that a PIC executes instructions at 1/4 of the clock rate, so if you intend to execute one instruction you have to send 4 clock pulses. not sure if that's relevant to what you're doing or not.
 
You can feed 2 PICs off the same xtal though. It would limit them to both having the same freq.
 
Oznog said:
You can feed 2 PICs off the same xtal though. It would limit them to both having the same freq.
I gues that it's better then have them running at 20Mhz to 200Khz ratio :lol:
 
Of course you can do it. But the question is, why would you want to do it? Is there any benefit you can get from it?
 
You've NEVER actually given any reason for why you WANT to do this?, or explained why you're using the 16F84? - a PIC which was rendered obselete many years ago!.

The replacement for the 16F84 is the 16F628, it has an internal 4MHz oscillator - which would obviate the need for a crystal on at least your second PIC, and also on your first (as long as you don't require crystal accuracy?).

Or why not just use a larger PIC?, you haven't given any reason for wanting to use two small obselete devices, instead of one current one?.
 
The only reason I can see for clocking the 2nd PIC with the 1st PIC is if a larger bit size is required for a piece of data (16-bit as opposed to 8-bit), but even then, I wouldn't use a PIC to clock another PIC. Instead, I would have a universal clock that drives them both at the same time. AND, the advantage is that you have more number of bits available at any given time.
 
Oh, sorry, too tired, i fall asleep :)

Actually I am trying to interface a SMART card. As we know, smart card contains a uC as well. Some one even use PIC to emulate the smart card.

The smart card has one IO pin and one ClK pin.

I connected the ClK pin like the one shown.

Initially, every time i send a bit, i will send a clock pulse (PIN_CLK = 1, then PIN_CLK=0). But this doesn't work. Maybe because the CLK is not 50% duty cycle.

The start up sequence for Smart card is stated in iso 7816-3, in the section ISO7816 3.2.b - Reset of the card
https://www.cardwerk.com/smartcards/smartcard_standard_ISO7816-3.aspx

I send the pulses however, The IO pin always high.


That's make me thinking of using another XTAL for the smart card. The problem is, if I use another XTAL, the timing become hard to follow as I am using CCS PIC-C.

I found a smart card Interface IC driver, writen in C. I guess this is possible to use PIC-C to write the driver.
http://www.gemplus.com/products/gemcore_chipset/resources/reader_driver.html

I am using NCN6001 from ON SEMI. Initially I wish to use Gemplus IC, since they have a C driver. but unfortunately, they ignored my request for IC and eval board :)
 
The fault.png shows my initial connection to smart card. PIC supplies clock and rst signal to the card, and use 1 IO pin to communicate between the smart card.

In the real connection, I use NCN6001 smartcard reader IC in between PIC and smart card. NCN6001 is a voltage level shifter and also it can divide the clock signal to 1/2 or 1/4 by flip-flop. This can provide a 50 % duty cycle to the smart card. smart card requires 40-60%. I purposely didn't include the NCN6001 because I dont want to make the schematic messy.

Initially, since we supply the clock signal to smart card IC, I do it in Synchronous way. Every time i want to transfer a data, I set the IO bit and then follow by a clock pulse (fault.png). I thought the operation of smart card is depend on the pos edge of the clock signal. But it doesn't work. (the target smart card is using Async Transmission)

Then I check again with the reference design. the reference design is using 68HC908 as uC. the smart card and uC share the XTAL of 19.6608MHz. so I modify my schematic (card share clock.png).

The way we program uC is serial programming. It makes us easy to code Synchronous transmission. For Async transmission, It will not that intuitive to code that. As the matter of fact, I am having problem with that. The reason is, I never use PIC assembly language before, i use CCS PIC-C to code it at the very beginning.

I modified the connection as shown in "card share clock.png". I only have 8MHz Ceramic Resonator at hand.

I hope can find the technique to code Async Transmission, preferably in C (I know this is not the proper way to code uC without the strong Assembly basic). I guess RS232 is kind of Async Transmission protocol, so if any one can provide RS232 protocol in C would be nice. CCS PIC-C has a built-in rs232 function, I use it all the while, and I don't know what's happen in the background.
 

Attachments

  • card_share_clock.png
    card_share_clock.png
    8.5 KB · Views: 323
  • fault.png
    fault.png
    6.8 KB · Views: 307
You should be connecting to the CLK_OUT pin, NOT the CLK_IN pin, remember - you're coming OUT of the PIC and going IN to the card processor.

Depending on the load imposed by the card, you may have to insert a buffer between them - obviously it depends entirely on the card processor.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top