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.

2 PIC16F84A using only 1 Xtal..?

Status
Not open for further replies.

AntRoFiZ

New Member
Hi, I was wondering.. is it possible to use 2 PIC16F84A with only 1 crystal oscillator..? If it is possible then how do I do it..? Connect it the usual way to 1 PIC and then connect both of the OSC input of the 2 PIC in parallel..?

I am thinking of doing a ultrasonic range finder.. From reading the posts in the forum, i understand that i need to modulate it to a certain frequency such as 40KHz so that other frequency of sound wont interfere with it..

I plan to use 4MHz crystal and in order to generate 40KHz, the time period should be 100us rite..?

Below is the code snippet for BoostC (SourceBoost) written in C. The transmitter of the Ultrasonic is connected to RB0.
Code:
set_bit(portb,1);
delay_10us(5);
clear_bit(portb,1);
delay_10us(5);

Is the code correct..?


How about the receiver part..?
How do I cause the receiver to receive 40Khz..? Is it the part of the component (as in the receiver can only receive 40Khz or is it the PIC16F84A part? If it is the PIC then how do I program the PIC..?
 
There are lots of such circuits already on the net, and you certainly don't need two PIC's to do it. Where you're getting confused is the receiver, the 40KHz is received by a transducer, amplified, then rectified, giving a DC voltage output, which varies with the strength of the returned signal. You usually use a comparator to detect when it's above a certain level, and generate a logic level output that connects to the PIC.

So the sequence of events goes like this:

1) Generate a short burst of 40KHz.
2) Delay a short while, to allow the receiver to recover from the transmitted burst.
3) Start a counter.
4) Check for a received pulse, and stop the counter once it appears.
5) The distance is represented by the value in the counter.
6) The counter should have an over-flow value, which means a received pulse has not being detected (distance too far).

It's all VERY easily done with a single PIC, and using two would only make it more difficult.
 
Umm.. sorry.. my mistake.. i should have made it clearer in my previous post..
Only one PIC is used for ultrasonic distance measurement.
The other PIC is used for other things.. Instead of spending more money for crystal etc, if I can use 1 crystal for 2 PIC then that would save the cost..
As for why 2 PIC16F84A..? Well, thats because I already have them and do not need to buy 16F877..

As for the transducer (receiver), how can i be sure that other freq beside 40KHz will not be received by it..? I mean, it would defeat the purpose if I send out 40KHz but the receiver is able to receive other freq then the measurement will not b right..
 
Ultrasonic transducers work on a VERY precise frequency, and you need to ensure you have a matched pair for them to work correctly. You can always provide some filtering in the amplifier stages if you want to though, it can only help! - but basically the receive transducer rejects everything else itself.

To use one crystal, connect it to one PIC as usual - then connect it's oscillator OUTPUT pin to the oscillator INPUT pin of the other PIC, set the second PIC to use an external oscillator.
 
You mean for the primary PIC, I do not need to set the PIC to use external oscillator but for the second PIC i need..?
I set the PIC to use external oscillator by programming..?


If I want to use 1 PIC to do both ultrasonic distance measurement as well as infrared proximity detection, can I use 40KHz for both..? I mean, transmitting the ultrasonic signal and the IR at the same time. Will it still work if I use 40KHz for the IR instead of 38KHz..? As for the IR receiver, how do I protect it from stray IR signal that is not 40KHz..?
 
AntRoFiZ said:
You mean for the primary PIC, I do not need to set the PIC to use external oscillator but for the second PIC i need..?
I set the PIC to use external oscillator by programming..?

Yes to both!, to set the oscillator type use the config fuse settings.

If I want to use 1 PIC to do both ultrasonic distance measurement as well as infrared proximity detection, can I use 40KHz for both..? I mean, transmitting the ultrasonic signal and the IR at the same time. Will it still work if I use 40KHz for the IR instead of 38KHz..? As for the IR receiver, how do I protect it from stray IR signal that is not 40KHz..?

Yes 40KHz will work fine for IR, the receivers work well over quite a wide range (unlike ultrasonic ones). The IR receiver will have limited sensitivity once you get too far from it's passband - but any IR remote signal will probably pass straight through.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top