schematic breakdown
TRANSCRIPT
-
8/11/2019 Schematic Breakdown
1/15
-
8/11/2019 Schematic Breakdown
2/15
the raspberry pi in the range of 0-10V the voltages will be present out of A1 or A2
(please note these analogue outputs are not suitable for applications that require hard
real time analogue outputs). The two relays are rated to 240VAC 10A and can switch
electrical signals on and off the connector for the relays is on the upper right. You
need to connect 12V to the board in order for them to work. The JTAG header is used
to program and debug the Pic chip. Any microchip programmer that supports thePIC16F1519 (common ones are PIC kit 2 or PIC Kit3) will work. The RS232 header
is on the board above the JTAG and has TX RX and GND I explain the physical layer
protocol details further on in this document. The RS485 connector is on the bottom
terminal and has three connections B+ gnd and B- I show you how to connect this
and explain the details of how it works later on in the document.
Input Protection
PIO1 goes to the connector on the outside of the board pin 1 and IO1 goes to the
processor on the pic chip. When you are not using a pin it is safest to set it up as a
digital output and set it high. R30 is a pull a resistor which pulls high when it is not
used. The diodes are used for voltage protection for the processor pins D20 clamps
any voltage below 0.6V to 0.6V and D18 clamps any voltage above 5.6V to 5.6V.
R33 is used to limit the current to the processor pin. C18 is used to remove any high
frequency noise spikes such as switching of relays on the board.
-
8/11/2019 Schematic Breakdown
3/15
Real time clockTo keep the price of the Raspberry Pi down the developers left out some of the
essentials one of those is the real time clock. At the moment the raspberry pi gets it
time over the Ethernet from updating the time automatically from the global network
time protocol server, but this means that when the Ethernet is unplugged the
Raspberry Pi loses its time until the Ethernet is plugged back in again,That why weadded a real time clock to the PIC Pi I will explain here how it works
The wiring X1 is a common crystal that is readily available it is not polarized and
wire it to x1, and x2, B1 is a 3V battery and wired to Vbat and GND This is so that
when the power goes out to the pic the Real time clock still has power and keeps the
time so that on the next power up you will still have the correct time. SCL is the serial
clock for the I2c bus and connects to pin5 on the raspberry pi connector as shown in
picture 2, SDA is the serial data for the i2c bus and connects to pin 3 n
the raspberry pi connector, You can also wire pin 2 form the raspberry pi to 5V and
GND to pin 6. I will add a tutorial on how to get the real time clock running on the
website in the future.
-
8/11/2019 Schematic Breakdown
4/15
RelaysAs show in the diagram below the Relays can be in two states where the 1C and 2C
are the common terminals. In state 1 the relays are not energized 1C is connected to
1A and 2C is connected to 2A you might like to think of this as the off state. In State
2 the relays are energised and 1C is connected to 1B and 2C is connected to 2B.
State 1 State 2
The C05 is the relay terminal that you see above. I will go into the circuit diagram
detail here. D31 and D32 are flyback diodes because the relays are an inductive load
and when they are switched can give a voltage spike so they diode get rid of this spike.
C29 and C30 are also use to smooth any voltage spikes. Q1 and Q2 are NPNtransistors and are used in this circuit to switch the relays on and off. When there is a
logic level low on the base of the transistor the transistor acts as an open circuit not
letting any current flow from the collector to the emitter therefore not energizing the
relays. When there is a logic level high the transistors are saturated act as closed
circuit where current flows freely from the collector to the emitter energising the
relays. C31 and C32 are used to make sure that noise doesnt affect the state of the
transistors affecting the state of the relays.
-
8/11/2019 Schematic Breakdown
5/15
Analog OutputsThe analog outputs are on the bottom right of the board and range from 0-10V.I go into detail of how the op amps work here they are both identical so I will explain the
first one only. I have to explain how a PWM signal works first a PWM is actual a
square wave made up of digital outputs with logic levels 0V and 5V and a period. A
period is made up of % of high time and % of low time which can range from 0-100%meaning the signal can be high (5V) for the period or low (0V) for the whole period.
In the software I have set the period to be very fast every approximately every 200 ms.
Below is an example of 3 PWM square waves with 10%, 40% and 90% high time.
Connecting the PWM1 signal from the PIC to R17 an C14 (which act together as a
low pass filter) we can generate a Analog Output that ranges from 0 5V on to Pin 3
of our Op Amp. R17 and C14 turn the percentage of on time in to a dc voltage. The
10% PWM square wave would give a DC voltage 10% of 5V =0.5V, 40% square
wave would give 40% of 5V = 2V, 90% would give a dc voltage of 4.5V and you get
the drift. But our application requires Analog outputs from 0V-10V you say thats
what the OP amps are for to amplify the 0V-5V to analog outputs to 0V-10V. The op
amp circuit is a common one found in any electronics text book and is called a Non-
inverting amplifier. How it works is by changing the output voltage (pin1) so that the
voltage created by our pic chip on pin 3 matches the voltage on Pin 2 the inverting
input. Note how the Voltage on the output Pin passes back to Pin 2 through a voltage
divider. The formula for calculating the output voltage is
+=
22
211
R
RVinVout .
This output voltage then passed to the PIC Pi terminal on A.OUT 1 via a 100R
resistor which is used to limit the current A1 supplies.
-
8/11/2019 Schematic Breakdown
6/15
-
8/11/2019 Schematic Breakdown
7/15
The Raspberry Pi to PIC Pi communications I2C bus
The I2C Bus is just three wires, SCL, SDA and GND. SCL is the clock line. It is used
to synchronize all data transfers over the I2C bus. SDA is the data line. Both devices
on the bus need to also be connected to GND. Both SCL and SDA lines are "open
drain" drivers. What this means is that the chip can drive its output low, but it cannot
drive it high. For the line to be able to go high you must provide pull-up resistors to
the 3v3 supply. Thats why there is a resistor from the SCL line to the 3v3 line and
another from the SDA line to the 3v3 line. You only need one set of pull-up resistors
for the whole I2C bus, not for each device, as illustrated above:
On the I2C bus the Raspberry Pi is the master and in this case we have multiple slaves
the PIC PI and the Real time Clock. The Raspberry Pi Master is the device that drivesthe SCL clock line. The PIC PI and Real time clock can only respond to requests from
the master. The slaves can transfer data over the I2C bus, but that transfer is always
controlled by the Raspberry Pi master.
When the Raspberry Pi Master wishes to talk to one of the slaves it begins by issuing
a start sequence on the I2C bus. A start sequence is one of two special sequences
defined for the I2C bus, the other being the stop sequence. The start sequence and
stop sequence are special in that these are the only places where the SDA (data line) is
allowed to change while the SCL (clock line) is high. When data is being transferred,
SDA must remain stable and not change whilst SCL is high. The start and stop
sequences mark the beginning and end of a transaction with the slave device.Figure 1
-
8/11/2019 Schematic Breakdown
8/15
Data is transferred in sequences of 8 bits. The bits are placed on the SDA line starting
with the MSB (Most Significant Bit). The SCL line is then pulsed high, then low.
Remember that the chip cannot really drive the line high, it simply "lets go" of it and
the resistor actually pulls it high. For every 8 bits transferred, the device receiving the
data sends back an acknowledge bit, so there are actually 9 SCL clock pulses to
transfer each 8 bit byte of data. If the receiving device sends back a low ACK bit, thenit has received the data and is ready to accept another byte. If it sends back a high then
it is indicating it cannot accept any further data and the master should terminate the
transfer by sending a stop sequence.
I2C addresses are normally 7 bits. When sending out the 7 bit address, we still always
send 8 bits. The extra bit is used to inform the slave if the master is writing to it or
reading from it. If the bit is zero the master is writing to the slave. If the bit is 1 the
master is reading from the slave. The 7 bit address is placed in the upper 7 bits of the
byte and the Read/Write (R/W) bit is in the LSB (Least Significant Bit). The PIC PI
chip address is at 0x10 and the real time clock address is at 0x68.
How the Raspberry Pi master sends a byte to a device
1. Send a start sequence as shown in figure 1
2. Send the I2C address of the slave with the R/W bit low (even address) ie 0x10
for the PIC Pi chip
3. Send the internal register number you want to write to ie the PIC Pi chip has an
array of 0-100 addresses that you can write to.
4. Send the data byte
5. [Optionally, send any further data bytes]
6. Send the stop sequence.
How to read a byte out of a device
1. Send a start sequence
2. Send 0x10 ( I2C address of the PIC PI chip with the R/W bit low (even address)
3. Send 0x01 (the first internal address of the PIC PI Chip array)
4. Send a start sequence again (repeated start)
5. Send 0x11 ( I2C address of the PIC PI chip with the R/W bit high (odd address)
6. Read data byte from PIC PI
7. Send the stop sequence.
-
8/11/2019 Schematic Breakdown
9/15
RS232
-
8/11/2019 Schematic Breakdown
10/15
I am just going to explain the hardware here if you want to know how to configure the
software check the Python API. RS232 is a common communication protocol
invented to make wires less susceptible to interface from electrical noise. RS232 is
only a point to point protocol meaning that there are only two end devices that can
communicate with each other over the bus. Computer Busses can be divided into two
main categories asynchronous or synchronous. Synchronous busses require a physicalwire that transfers a clock signal to be linked between the two devices asynchronous
-
8/11/2019 Schematic Breakdown
11/15
busses dont require a physical clock wire. RS232 is a Asynchronous bus which
means doesnt require a clock but it means that the timing has to be configured ( in
software ) on the devices of each end of the wires. RS232 uses serial communication
meaning that a wire only transmits data in one direction and to achieve bidirectional
( full duplex) transfer of information you need 2 wires one to transmit one to receive
data plus GND hence the RS232-RX and RS232-TX from the Raspberry Pi. In theserial communications the data is normally 8 bits no parity 1 start bit 1 stop bit. 8 bits
of data is used because with 8 bits you can represent all the characters in the ASCII
table. Parity is a form of error checking that is not commonly used. The Raspberry Pi
doesnt have the hardware to transmit and receive the voltage levels required for
RS232 that why we added a MAX3226 to the PIC Pi in the above diagram.
In the above diagram you can see the how the voltage level are converted from the
Raspberry Pis UART to the PIC Pis RS232 so that you can communicate with
another end device communicating using the RS232 physical protocol. Note that the
wires are twisted between the PIC Pi and the External RS232 Port in the first diagram.
RS485
RS485 is a common physical layer communication protocol. It is half duplex which
means it can only transmit data in one direction at a time. It is a good choice for long
distance serial communication since it has differential signals which cancel out the
majority of electromagnetic disturbances picked up if there is a long wire. It can also
network devices in a daisy chain topology unlike RS232.
To communicate with an external device you can use the simple software functions
rs485rx()and rs485tx(byte)but the hardware to get the signal from the Raspberry Pi
to the external device gets a little bit tricky but dont worry ill explain it here.
To send RS485 signals to communicate with an external device from the Raspberry Pi
connected to the PIC PI we start by communicating to PIC Chip over the I2C bus
from the Raspberry Pi. The PIC communicates with the MAX485 chip using its
UART and a control line. The MAX485 chip converts the data into the RS485Voltage levels which are wired to the PIC PI terminals. To connect a external device
-
8/11/2019 Schematic Breakdown
12/15
to communicate with the PIC Pi over the RS485 wire B+B+ and B-B- and
GNDGND ( can work with out GND but the best practice is to use GND) .
Receiving RS485 data from an External Device
Below is table taken from the MAX485 datasheet that shows how theMAX485 chip converts RS485 voltage levels from an external device on
lines A (B+) and B (B-) in to TTL voltage levels sent to the PIC Chip. To
make the MAX485 chip enter receiving mode the PIC drives EN485 low
sending REand DElow as shown in the table below. If A-B => 0.2V
then ROis set to 1. If the A B
-
8/11/2019 Schematic Breakdown
13/15
Voltage LevelsLogic Table taken form MAX485 datasheet
-
8/11/2019 Schematic Breakdown
14/15
-
8/11/2019 Schematic Breakdown
15/15