Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

11
Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman

Transcript of Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Page 1: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Microchip PIC Networks

Amrit Bandy, Ben Funk

Neil Goldsman

Page 2: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

2-Node Wired Set-up• PICs hooked up with wire connections• PICs are small micro-controllers made by Microchip

Tx

μP1 μP2

Tx

RxRx

µP: 16F88 by Microchip

•Features

•Built in A/D Conversion Module

•Universal Asynchronous Transmit and Receive using Tx and Rx ports. (Serial communication controlled by programmer)

Page 3: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Step 1: Establish Network via Clock Synchronization

• Node Clock Definition:– Built-in 8-bit timer, counts up from 0 to 255,

sets off an interrupt upon overflow. Prescalar of up to 256 available.

– Node Clock (our timer) updates every time the interrupt occurs (part of code)

• Synchronization of Clocks– Node A transmits its NodeClock to Node B while

Node B receives it and updates its own NodeClock

Page 4: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Timer Synchronization Algorithm

Node A:1. Setup Tx Port for RS232 Transmission and Rx port for

RS232 Reception using Universal Asynchronous Reception and Transmission

2. Check for hardware switch-If “on” goto 5 else 33. Transmit packet comprising AB in hex (frame sync

byte to intelligently qualify data packet to follow), followed by the NodeClock

4. Goto 2 (only one or two iterations needed)5. Transmit NodeClock value to Real Terminal on

Computer and print value on screen.Step 5 is to test the node synchronization

Page 5: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Timer Synchronization Algorithm

Node B:1. Setup Tx Port for RS232 Transmission and Rx port for

RS232 Reception using Universal Asynchronous Reception and Transmission

2. Check for hardware switch-If “on” goto 7 else 33. Receive first byte, if it is not equal to ABh repeat 3. 4. Clear and start NodeClock5. Receive second byte (clock of node A), add to

NodeClock to update NodeClock6. Goto 27. Transmit NodeClock value to Real Terminal on

Computer and print value on screen.Step 7 is to test the node synchronization

Page 6: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Step 2: Data Transmission After Synchronization

• Voltages represent sensor node reading• Each node compares its own voltage with voltage

received from the other node and an LED is lit on the node with the highest voltage

• Procedure:– Assign PIC_id for each node and COMM_id for the node that is

transmitting– Establish Network by synchronizing clocks– Transmission and Reception are carried out in equal slots

(TDMA)– Transmitting slot includes reading A/D data and transmitting

packet– Reception slot includes receiving packet, comparing voltages of

all the nodes, and lighting LED– Update COMM_id to give next node a chance to transmit data

Page 7: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Data Transmission Algorithm

1. Synchronize timer to node A2. If PIC_id=COMM_id goto 3 (transmit) else 7 (receive)3. Read A/D voltage(10 significant bits) into two 8-bit registers, right

justified 4. Transmit packet: ABh, NodeClock, highbyte(data), lowbyte(data)5. Update COMM_id to allow next node to transmit6. Wait for slot to expire, goto 27. Receive first byte, if it is not equal to ABh goto 7.8. Clear and start timer9. Receive second byte, add to NodeClock to update NodeClock10. Receive highbyte (data) followed by lowbyte (data), and store

information for the node which is transmitting11. Compare voltages for all nodes, light LED if self is highest12. Update COMM_id, Wait for slot to expire, goto 2

Page 8: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Step 3: Extend Wired Setup to 3 nodes

• Issue: 16F88 has only one Rx port!• Solution: Use AND gate to choose correct line,

since the transmitting line is high while receiving.

Tx Rx

µP1

Tx Rx

µP2

Tx Rx

µP3

Page 9: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

3-Node Wired Setup Using AND Gates

• Why AND gates?• Transmitting line is high

while receiving• Truth Table shows that

the AND gate reproduces the Tx signal

Tx Rx Out

0 1 0

1 1 1

Slot1 Slot2 Slot3

NodeA Tx Rx Rx

NodeB Rx Tx Rx

NodeC Rx Rx Tx

Page 10: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Step 4: Remove the Wires – Employ Transceivers

• Transceiver used: TR-916-SC-P by Linx Technologies

• TXEN pin to enable Transmit• RXEN pin to enable Receive• Can only transmit or receive at a time• Algorithm remains the same except

– Allow enough time for transceiver to start-up– Enable TXEN, disable RXEN for transmit– Enable RXEN, disable TXEN for receive

Page 11: Microchip PIC Networks Amrit Bandy, Ben Funk Neil Goldsman.

Testing Steps 1-4

• Setup: 3 PIC 16F88 microcontrollers connected to potentiometers. Nodes B&C synchronize themselves to Node A, transmit their own voltages , receive that of the others, compare and indicate who is the highest using an LED.

• Baud Rate: 19.2Kbps• Transmit/Receive Slots : 200ms with 20MHz

clock• Results: Both the wired and the wireless models

work for 3 nodes.