Microchip PIC Networks Amrit Bandy Ben Funk Neil
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 Tx μP 1 μP 2 Rx Rx µP: 16 F 88 by Microchip • Features • Built in A/D Conversion Module • Universal Asynchronous Transmit and Receive using Tx and Rx ports. (Serial communication controlled by programmer)
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 Node. Clock to Node B while Node B receives it and updates its own Node. Clock
Timer Synchronization Algorithm Node A: 1. Setup Tx Port for RS 232 Transmission and Rx port for RS 232 Reception using Universal Asynchronous Reception and Transmission 2. Check for hardware switch-If “on” goto 5 else 3 3. Transmit packet comprising AB in hex (frame sync byte to intelligently qualify data packet to follow), followed by the Node. Clock 4. Goto 2 (only one or two iterations needed) 5. Transmit Node. Clock value to Real Terminal on Computer and print value on screen. Step 5 is to test the node synchronization
Timer Synchronization Algorithm Node B: 1. Setup Tx Port for RS 232 Transmission and Rx port for RS 232 Reception using Universal Asynchronous Reception and Transmission 2. Check for hardware switch-If “on” goto 7 else 3 3. Receive first byte, if it is not equal to ABh repeat 3. 4. Clear and start Node. Clock 5. Receive second byte (clock of node A), add to Node. Clock to update Node. Clock 6. Goto 2 7. Transmit Node. Clock value to Real Terminal on Computer and print value on screen. Step 7 is to test the node synchronization
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
Data Transmission Algorithm 1. 2. 3. Synchronize timer to node A If PIC_id=COMM_id goto 3 (transmit) else 7 (receive) Read A/D voltage(10 significant bits) into two 8 -bit registers, right justified 4. Transmit packet: ABh, Node. Clock, highbyte(data), lowbyte(data) 5. Update COMM_id to allow next node to transmit 6. Wait for slot to expire, goto 2 7. Receive first byte, if it is not equal to ABh goto 7. 8. Clear and start timer 9. Receive second byte, add to Node. Clock to update Node. Clock 10. Receive highbyte (data) followed by lowbyte (data), and store information for the node which is transmitting 11. Compare voltages for all nodes, light LED if self is highest 12. Update COMM_id, Wait for slot to expire, goto 2
Step 3: Extend Wired Setup to 3 nodes • Issue: 16 F 88 has only one Rx port! • Solution: Use AND gate to choose correct line, since the transmitting line is high while receiving. Tx Rx µP 1 Tx Rx µP 2 Tx Rx µP 3
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 Slot 1 Tx Rx Out 0 1 1 1 Slot 2 Slot 3 Node. A Tx Rx Rx Node. B Rx Tx Rx Node. C Rx Rx Tx
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
Testing Steps 1 -4 • Setup: 3 PIC 16 F 88 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. 2 Kbps • Transmit/Receive Slots : 200 ms with 20 MHz clock • Results: Both the wired and the wireless models work for 3 nodes.
- Slides: 11