Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Connecting 2 microcontrollers in parallel

Status
Not open for further replies.

SundusHamideh

Newbie level 3
Joined
Dec 9, 2015
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
39
Hey All,
I was asked to do the following task:
I should connect two pics of type 16F84A in parallel, usart isn't allowed
This embedded system has two microcontrollers; MC1 and MC2. These two microcontrollers operate as follows:
1) MC1 is connected to three switches and one pushbutton, and is running at 10 KHz.
The switches are read every 1 second and communicated to MC2 using PORTA. The time to read the switches is generated using Timer 0 module interrupt. The pushbutton that is connected to RB0 is used to control whether MC1 sends the value that is read from the three switches or not. Effectively, when the system is started, MC1 sends the switches value by default. However, upon the arrival of the first external interrupt, MC1 will always send 3 to MC2, regardless of the switches value.This situation continues until the arrival of the next external interrupt where MC1 goes back to sending whatever it reads from the three switches. In other words,MC1 toggles this state between successive external interrupts.

2) MC2 is also running at 10 KHz and is connected to a switch and 6 LEDs that are arranged in a ring. MC2 continuously receives the value of the switches from MC1.
The received value determines the number of LEDs that are flashed every 0.25 seconds. If the received value is 0 or 7, then there is no flashing and all LEDs are off. The switch that is connected to MC2 determines whether MC2 should flash the LEDs or not. Effectively, when the value that is read from the switch is logic high, there is no flashing and all LEDs are on regardless of the values received from MC1.
Otherwise, the LEDs are flashed according to the received value.
Note: MC2 does not use any source of interrupts, i.e. all operations are performed using polling.

The program must be written using assembly language,not c or any other language !
 

It would be better if you had done a sketch graphing what you want in blocks, rather than describing it textually. Anyway, I was not able to find a proper question in this thread.
 

Well I need the help to write the code for each microcontroller !
Here's the design :
Untitled.png
 

If I read it properly:

On the first PIC, RB0 (the external interrupt input) is used to alternate between sending '3' (presumably 011 binary) and three bits representing the state of the three switches.

On the second PIC, RA0 is used to decide whether the LEDs flash or not and the number received from the first PIC decides how many of the LEDS are lit.

Communcation is down a single wire from RA4 on the first PIC to RA4 on the second one.

Only numbers from 001 to 110 (1 to 6 decimal) are valid, numbers 000 and 111 turn all LEDs off (I think 000 would anyway!).

If my interpretation is right, you need some kind of serial protocol to frame the bits as they arrive in the second PIC, otherwise the two end will lose sync with each other. A reserved bit pattern, maybe 111 can be used for that purpose.

Incidentally, you can not connect the OSC1 and OSC2 pins like that, for 10KHz operation you really need to use RC mode with an identical value resistor and capacitor on each PIC. 100 Ohms is also rather low for the switch pull-down resistors, there is no point in passing 5mA through them when the pin only needs 1uA, change them to 10K. Also add decoupling capacitors across the VSS and VDD pins of both PICs or they will not work reliably.

Brian.
 

Oh Okay , but how about starting up my code ?
I've zero knowledge of how to write the code for the other pic that received the data sent to it by the 3 switches :\
 

Polling inputs while using a 10 Khz clock??
Should be OK, both ends are running at the same speed and it doesn't need compatibility with other comms standards.

My first best guess would be to use a transistion from 111 to 000 as the 'zero reference' then read the next 3 bits as data at slow speed. 10KHz clock means 2,500 instructions per second on a 16F84 so there is plenty of time for slow data to be read in and processed. The other requirements are only applicable to one end or the other so they are easy to implement.

SundusHamideh, which assembler do you want to use and do you have any experience of these devices already?

Brian.
 

I work on MPLAB
MPASM assembler (mpasmwin.exe) v5.30.01
 

It's outdated but still a good choice.

Sundus, what you need to do next is plan the flow of the software. A flow chart is a good way to do that, programming is more to do with understanding what you want to achieve than actually writing the instructions. The basic steps are:

Sending end (MC1)
1. Initialize the PIC. Work out which pins are inputs and which are outputs, then program the port direction bits accordingly.
2. Decide whether to use interrupts or polling to check the push button on RB0. I suggest interupts but you can use either method.
3. You need a one second timer to read the switches, work out the value you need to load into TMR0 to generate the 1 second period. You may need to do it in two steps, if TMR0 is too fast to produce 1 second directly, use 0.1 seconds and count the interrupts up to 10 before checking the switches.
4. Decide how you are going to synchronize the data flow between MC1 and MC2. You need a way to tell MC2 which bit is arriving next. The usual method is to reserve a particular bit pattern as a 'start signal', there are many ways to do this but the simplest is probably to use the reserved bit pattern 111.
5. Work out how to send the bits through RA4, the shift functions will be useful for that.

Receiving end (MC2)
1. Initialize the PIC. Work out which pins are inputs and which are outputs, then program the port direction bits accordingly.
2. Work out how to time the 0.25 seconds flash interval.
3. Work out how to recognize the start signal and count in the following three bits of data. Hint: Use shift instructions again.
4. Convert the number in the data to the pattern of LEDs on the port pins.

Obviously, the data sent by MC1 has to be received by MC2 and you are sending it along a single wire. Normally we use a UART to do this because it does all the synchronizing for us but your task it to do it without one. Because there is only one wire, you have to send the bits one at a time (serially), that means you have to decide how many bits per second you want to send and make sure the receiving end picks them up at the same speed. Think of it like a conveyor belt, it items are placed on it at a fixed rate, they arrive in the same sequence and at the same rate. If you try to pick items off it too fast or too slow, you risk missing them. There is a trick you can use if you are careful in the planning stages - you already generate timing intervals with TMR0, if you make the interrupts every 0.1S you can use it to send the bits at 0.1S intervals and also divide it by 10 to get the 1 second switch reading interval. On MC2 you can do the same but divide it by 25 to get the flash interval.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top