i2c input / output board bv401 - home - byvac datasheet.pdf · byvac product specification and...

10
ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 1 of 10 BV401 I2C Input / Output Board Product specification and build instructions Jan 2006 v0.a ©ByVac 2006

Upload: nguyenkien

Post on 06-Mar-2018

234 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

BV401 I2C Input / Output Board

Product specification and build instructions

©ByVac Page 1 of 10

Jan 2006 v0.a

©ByVac 2006

Page 2: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

January 2006 2 of 10 www.byvac.com

Contents 1. Introduction................................................................................................................ 2 2. Features..................................................................................................................... 2 3. How It Works.............................................................................................................. 3 4. How It Works.............................................................................................................. 3

4.1. I2C........................................................................................................................ 3 4.2. Power .................................................................................................................... 4 4.3. Output ................................................................................................................... 4 4.4. Input ..................................................................................................................... 4

5. Building...................................................................................................................... 5 6. Testing....................................................................................................................... 5 7. Using ......................................................................................................................... 5

7.1. Relay Test .............................................................................................................. 5 7.2. Analogue Output ..................................................................................................... 5

8. Parts List.................................................................................................................... 6 8.1. Resistors .................................................................... Error! Bookmark not defined. 8.2. IC Sockets.................................................................. Error! Bookmark not defined. 8.3. LED’s ......................................................................... Error! Bookmark not defined. 8.4. Diodes ....................................................................... Error! Bookmark not defined. 8.5. Electrolytic Capacitors.................................................. Error! Bookmark not defined.

9. An I/O Project............................................................................................................. 7 9.1. Description............................................................................................................. 7 9.2. I2C........................................................................................................................ 7 9.3. Relay Output .......................................................................................................... 7 9.4. Motor Output .......................................................................................................... 7 9.5. Analogue Output ..................................................................................................... 8 9.6. Analogue Input ....................................................................................................... 9 9.7. Feedback System .................................................................................................... 9 9.8. Variables.............................................................................................................. 10 9.9. Further ................................................................................................................ 10

1. Introduction The BV401 is an input / output board designed for the I2C interface. It complements the other boards in the product range and because it uses I2C, does not take up many I/O lines. The four power outputs can drive 2 dc motors forward or reverse, or 1 stepper motor.

2. Features o Four high power outputs with

independent enable for driving 2 DC motors (forward and reverse) or 1 stepper motor. – 2 x 2 screw terminals

o Two relay outputs SPDT – 2 x 3 way screw terminals

o One analogue output o Four analogue inputs o Analogue i/o via 8 way polarised

connector o I2C fully addressable analogue range

90h to 97h, chip PCF8591 o I2C fully addressable digital range 70h

to 77h, chip PCF8574 o High power o/p chip L293 – 600mA per

channel

Page 3: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 3 of 10

o 6 way I2C socket for mating with the BV301

o 6 way connector for analogue in / out o 2 way connector and jumper for

external power o Dimensions 94 x 40mm o Weight 50g

3. How It Works The block diagram shows that the connection to BV301 is via K2, the BV301 can supply power +5V and the I2C master signals required. The board can also be used with any other I2C system. There are two relay outputs with SPDP switches and two motor drivers that are terminated with screw terminals. The 4 analogue inputs and one

analogue output uses a standard 6 way polarised connector.

4. How It Works 4.1. I2C

IC1 and its associated circuitry forms the output and IC3 is the analogue input. Both IC1 and IC3 are I2C devices. I2C is a serial protocol allowing various devices to be connected using only two wires. All I2C devices have an address to distinguish them form each other when using the same bus. IC1’s address is set by jumpers PA0 to PA2 and IC3’s address is set by AA0 to AA2. All devices come with a fixed base address that can be modified by these jumpers. IC1 for example has a base address of 70h but by default if all of the jumpers are removed this will be 7Eh.

Page 4: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 4 of 10

All I2C devices have a read and write address, bit 0 is used to indicate which: 0 is write and 1 is read so strictly speaking IC1 is 7Eh for write and 7Fh for read with all of the jumpers disconnected and 70h for write and 71h for read when all of the jumpers are in place. The address lines map to the following bits: Bit7

Bit6

Bit5

Bit4

Bit3

Bit2

Bit1

Bit0

0 1 1 1 A2 A1 A0 R/W

Using this project several boards can be used and each have their own unique address. Further information can be found in the data sheet for the PCF8574 and PCF8591.

4.2. Power Connector K2 provides +5V for the logic circuits and power for the motors via pins 5 and 6 respectively. If this connected to the BV301 then this board (within reason – see later) is capable of supplying this power. For very heavy loads or loads that may produce large current spikes, the small power supply on BV301 may not be up to the job. This of course all depends on what the BV301 is being powered with in the first place. To cater for such circumstances K2 and JP1 have been provided, diodes D1 and D2 simply protect the providing circuits. JP1 selects whether the motor supply should come form K2 or K3.

4.3. Output The PCF8574 is described as an input / output expander. This is because it is expanding the

I2C 2 wire bus into 8 I/O lines; a serial to parallel converter if you like. In this circuit it is only used for output. Lines P0 to P5 are taken to IC2, P6 and P7 drive the relays. At reset IC1 is an input device and has a small internal pull up current. This is sufficient to hold Q1 and Q2 off via R12 and R13. In this way at power up the relays are always off. This is the reason for using PNP transistors. IC2 is described as a ‘four channel driver with diodes’ and a look at the data sheet will reveal that it is capable of delivering 600mA per channel. This is an incredibly simple and low cost way of driving any inductive or otherwise load. Because of its configuration two motors can be driven forward or reverse. The device is configured as 2 x 2 channels and each channel pair can be enabled by driving the EN1 and EN2 inputs high. Although it has been envisaged that two DC motors will be controlled, any load can be applied to the output of this device. Given the correct software a stepper motor can also be driven. D3 and D4 are there to prevent any back – emf from being fed into the rest of the circuit, all inductive (ones with coils) loads need this diode protection.

4.4. Input The other half of the circuit is dedicated to analogue input and one analogue output. To simplify the circuit the analogue reference is the +5V supply which has been suitably smoothed by C2 and R7. All of the work is done by IC3 and this is connected to K3. The base address of IC3, with all the jumpers removed is 9Eh.

Page 5: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 5 of 10

5. Building Using the PCB building is very straight forward. Start with the lowest profile components first – IC sockets, resistors and finish with the highest ones; relays, connectors. See appendix A for tips on construction. Use the overlay to ensure the correct positioning and orientation of the components. Pay particular attention to the diodes, transistors and electrolytic capacitors that all must go in the correct way round. The red traces in the overlay show the top side of the board, notice the copper fill around the ground pins of IC2, this is there to help dissipate heat.

Double check all solder connections, diode and capacitor orientations. Before applying power see Testing below.

NOTE IC2 is soldered directly to the PCB (no socket), this is to help it dissipate heat. 6. Testing It is not possible to test this board fully without having a suitable I2C master interface. The BV301 will do nicely and it is assumed you have built this and tested the onboard I2C devices. Do not install the IC’s before switching on. With the IC’s removed connect up the BV301 to K2. This is a ‘straight’ connector pin 1 to pin1, pin2 to pin 2 etc. When connected, with a meter check that there is +5V on the correct pins for the IC’s. Also if appropriate check that there is power to pin 10 of IC2. There should be power on this if you have a power supply built on the BV310 and JP1 is in the correct position. If you are happy that the correct supply is being fed to the IC sockets, remove the power and install the IC’s. At switch on (plug K2 back in) nothing should happen, a few quick checks with

a meter will suffice for a preliminary verification: PIN Voltage IC2 – 3,8,13,18 +5V Emitter Q1 & Q2 +5V Base Q1 & Q2 +5V IC1 pin 14 (SCL), pin 15 (SDA) +5V The voltages at steady state are given above. The +5V figure may vary from 4.5V to 5.5V

7. Using The following uses TCB to test the board:

7.1. Relay Test Relay 2 is connected to bit 7 so setting this pin low will cause the relay to energise and you should be able to hear this, Try: CPOKE 126 127 CPOKE 126 255 This will turn relay 1 on and then off, for relay two try: CPOKE 126 191 CPOKE 126 255 You can test the out put to K2 and K3 using a meter. For more information on the CPOKE command refer either to the TCB manual or the various projects found on the ByVac web site.

7.2. Analogue Output

Page 6: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 6 of 10

To carry out a very simple test connect an LDR or other variable resistance to channel 1 of the A/D converter. For example between pins 1 and 6 of K3. If you don't have any variable resistors, choose two different resistors and slot them in one after the other -- and together, work out the maths. See the photograph for an example. IC3 has to be set up to read from channel 1 before any reading can take place. Also the reading is not valid until the second reading. All of this information is in the datasheet.

(9eH = 158 DECIMAL)

CPOKE 158 0 ' This sets channel 1 CPEEK 158 A ' First reading CPEEK 158 A ' Valid reading PRINT A It doesn't take much imagination to put lines 2,3 and 4 into a continuous loop and observe the effects of putting your hand over the LDR to cut out the light. It worked very well for the one I was using which has a dark resistance of about 80k. The above of course is just a test, you will find a full description of what this board can do in the How To section..

8. Parts List Capacitors Part Value Number C1,C3,C4,C6 0.1uF 4

C2,C5 100uF 16V - electrolytic 2

Resistors R12,R13 1k 2R1 - R6 10k 6R8 - R11 100k 4R7 390R 1Semiconductors IC1 PCF8574 1IC2 LN293 1IC3 PCF8591 1Q1 & Q2 BC557 2

D1 - D4 1N4004 4Connectors & Sockets PA0-2,AA0-2 Jumper pins 6JP1 1IC1-2 sockets DIL 16 2K1 2 way polarised 1K2, K3 6 way polarised 2

K4, K5 2 way screw terminal 2

K6, K7 3 way screw terminal 2

Miscl Y1, Y2 Relay 5V SPDT 2PCB BV401-PCB 1

H:\Zed\ASCII-Me\2006-documents\sub-Appendix A-build instructions.doc

Page 7: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 7 of 10

9. An I/O Project The following is repeated form the BV401 Project that can be found on the ByVac web site. It illustrates the use of the device in conjunction with Tiny Control Basic.

9.1. Description The BV401 is a comprehensive I/O board and can be used for many things. The basis of this project is to look at, and give program examples of what can be done. The project is split into parts that illustrate the different functions of the Bv401 and ends with a temperature feedback system. Note that there are individual circuit boards available that perform the same function as parts of the BV401. The BV402 relay board for example, the relevant circuits are: BV402 - Relay board * BV403 - Analogue comparator - This is not available on the BV401 BV404 - Digital output - This is not available on the BV401 BV405 - Motor controller board * BV406 - I2C board * The above marked * boards are almost exactly the same integrated circuits you would find on the BV401. The BV401 combines the 3 circuits together and makes them accessible by the I2C interface. The data sheets for the parts discusses are: PCF8574 PCF8591 L293

9.2. I2C The BV401 is an I2C device and will work with any I2C master device, it does not have to be another BV board. For convenience all of the examples will assume a BV3xx processor board is connected to the BV401.

This diagram, repeated from the BV401 project, illustrates the various parts of the BV401. The device has an analogue section and a digital section and both use industry standard IC’s. The analogue section has 4 analogue inputs and one output and the digital section is wired for an

output only device. This is connected to a motor controller and two relays. Each of the sections will be dealt with in turn with examples of how to use them. The set up used for the experiments given in this text is shown below.

9.3. Relay Output The I2C command for all the digital outputs is CPOKE <device address> <data> because the PCF8574 is a simple singe register device. With all of the jumpers disconnected (open) the device address is 7eh and this is what will be used for the examples. The relays are connected to bits 6 and 7 of the PCF8574. At switch on the port assumes a high (input) state. The BV401 is designed so that this is the off state of the relays. It follows then to switch the relays on the bits need to be taken low. Relay 1 requires 1011 1111 (BFh) Relay 2 requires 0111 1111 (7Fh)

Experiment:

1. Turn on relay 1, CPOKE &7e &bf you should hear the relay click

2. Turn it off CPOKE &7e &ff again the relay should be heard to click off

3. Turn on relay 2, CPOKE &7e &7f 4. Turn off relay 2, CPOKE &7e &ff

The above will verify the correct working of the relays. Note that they work off of the same +5V power supply that the IC’s use so power must be provided at the I2C input connector. This is done automatically via the 6 way connector if using the BV301.

9.4. Motor Output This is much more interesting. Again a standard L293 motor controller IC is used. The chip needs its own power supply via either K1 or K2. The power to the motor is smoothed by C4 and C5 but, depending on the motor used it can have an effect on the CPU if supplied by K2 to the point of crashing it at motor switch on.

Page 8: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 8 of 10

This is the reason for the option of a separate supply on K1 in which case jumper 1 must be adjusted accordingly. The interface is intended to drive motors but it doesn’t have to, it can drive anything you like within the specification of the chip. It is connected to the PCF8574 as follows: Bit 7

Bit 6

Bit 5

Bit 4

Bit 3

Bit 2

Bit 1

Bit 0

Relay 2

Relay 1

ENB

INB2

INB1

ENA

INA2

INA1

Out4

Out3

Out2

Out1

Bits 2 and 5 are enable lines and are active high. Out1 to Out4 are the screw terminal outputs intended for the motor connections. Bit 7 Bit

6Bit 5

Bit 4

Bit 3

Bit 2

Bit 1

Bit 0

Relay 2

Relay 1

ENB

INB2

INB1

ENA

INA2

INA1

Out4

Out3

Out2

Out1

Forward

1 1 0

Reverse

1 0 1

Brake 1 0 0Stop 0 X XAssuming that a motor is connected to Out1 and Out2 the above table shows the actions that the motor will take. Of course Forward and Reverse are a bit meaningless other than they are opposite to each other. This table translates the output into hex for convenience. Hex Bit 2 Bit 1 Bit 0

ENA INA2 INA1 Out2 Out1

Forward FEh 1 1 0Reverse FDh 1 0 1Brake FCh 1 0 0Brake FFh 1 1 1Stop FBh 0 X X

Experiment:

1. Optionally connect a separate power supply to K1 and adjust JP1 accordingly. This is so we don’t get any power problems at the CPU end.

2. Connect a small DC motor to K4 (M1), the voltage of course should be similar to the power supply. Note that if using

power supplied by BV301, this is the ‘raw’ unregulated power form the mains adaptor so could be in the region of 9 to 20V.

3. Make the motor go forward, CPOKE &7e &fe

4. Stop the motor CPOKE &7e &fc, this may or may not work depending on the motor, try also CPOKE &7e &ff. The idea behind this is to supply a shorting across the motor wires.

5. Make the motor go backward, CPOKE &7e &fd

6. Write a program to do this in TCB

The other motor output works in exactly the same way and so there is no point in repeating the experiment. A stepper motor can be connected to both motor outputs and driven by software.

9.5. Analogue Output Referring to the data sheet for the PCF8591, there is a control register that sets up the various options for analogue input and output. The pertinent bit of the control register for analogue output is bit 6, This enables the analogue output if it is set to 1. The device address, assuming that the jumpers are not present is 9Eh. Because the control register needs setting as well as the data to be output, CPUT must be used.

Experiment:

1. Connect a meter to the analogue output, pin 4 and ground, pin 1 of K3

2. Type CPUT &9e &40 0 This will write 40h to the control register ( bit 6 high) and then go on to write 0 as the analogue output. Observer the meter reading.

3. Type CPUT &9e &40 &ff Note that each time the control register needs writing to, the meter reading should now be around +5V.

4. Just for good measure try CPOKE &9e &40 &80 This should set the voltage at around 2.5V

The above shows how to output an analogue signal. Note that is probably better to keep the control register in a variable thus: k=&40, CPUT &9e k &ff The variable k can now be manipulated with AND and OR so as not to affect the original control bits. This is particularly important if analogue input is used alongside analogue output.

Page 9: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 9 of 10

9.6. Analogue Input There are many options for analogue input but for simplicity we will just look at obtaining data from channel 1. The control register needs setting up for this but it only needs to be done the one time, CPOKE will do this. For the purpose of this experiment I have connected an LDR (dark value about 80k) to pin 1 and 8 of connector k3. As there are 100k pull up resistors on the inputs I would expect to see about 2V on pin 1 and less than that in bright light.

Experiment:

1. Connect an LDR as described above, on my system this gives between 3.5V when I cover it with my hand and 1.9V in the light.

2. Type CPOKE &9e 0, this will write to the control register, turn off analogue output and select channel 1 analogue input.

3. Type CPEEK &9e a 4. Type CPEEK &9e b 5. Observe the value of A and B. Referring

to the data sheet the conversion result is not available until the second reading – don’t get caught out by this.

6. Change the light falling on the LDR 7. Type CPEEK &9e a 8. Type CPEEK &9e a 9. Observe the value of A this should have

changed. 10. On my system the values range from

about 100 in the light to 200 when covered.

9.7. Feedback System This is a complete project using 3 elements of the system. For this you will need a thermistor, a small lamp and a motor with a fan (propeller) attached. The thermistor is a small bead type, at room temperature the resistance is about 100k to 120K. When held by thumb and finger it rapidly reduces to about 80k to 85k. The lamp is a torch bulb, I had a 2.5V torch bulb and a 5V supply so I put a 12R resistor in series with it. For the motor I used an old 12V computer fan, this worked very well but it would not reverse, just as well this is not needed in this application. The idea of the system is to warm the thermistor with a lamp and when it reaches a certain temperature, switch the lamp off and cool it down with the fan. In this way the temperature is kept within limits. This could be applied to real situations and so forms an interesting experiment.

This is the circuit diagram of the set up used. The lamp is connected to relay 1, the fan to M1 and the thermistor to channel 1 analogue in. As we are on a more advanced project, I will assume that you have read the RTC Square wave output text (stupid assumption I know). Multi tasking extolled the virtues of writing code in a certain way, I will follow that here.

Thermistor bulb and fan with breadboard.

Page 10: I2C Input / Output Board BV401 - Home - ByVac DataSheet.pdf · ByVac Product Specification and Build Instructions I2C Input / Output Board BV401 ©ByVac Page 4 of 10 All I2C devices

ByVac Product Specification and Build Instructions

I2C Input / Output Board BV401

©ByVac Page 10 of 10

Thermistor touching lamp.

9.8. Variables A = Lamp on / off, 1 = on B = Motor on / off, 1 = on C = Thermistor temperature value, high = hot, low = cold D = Trigger value for thermistor E = keep track of the output value Here are the routines that the above variables use, or is that the other way round? Each routine is responsible for its own ‘domain’. The control routine has a hysteresis that prevents the lamp and motor from going on and off too quickly. This is fixed at 2. Lamp Routine 1000 1000 rem lamp if a=1 then e = e and &bf if a<>1 then e = e or &40 CPOKE &7e e return This routine will simply turn the lamp on or off depending on the variable A. If A is 1 then the lamp will turn on, anything else it will turn off. Note that variable E is used for the control register. Motor Routine 2000 2000 rem motor ‘ to turn motor off simply set enable bit high ‘ if motor going wrong way use &fa instead of &f9 if b=1 then e = e or &04 if b<>1 then e = e and &fb CPOKE &7e e return This is exactly the same as the lamp routine except it uses variable B

Thermistor Routine 30003000 rem thermistor CPEEK &9e c CPEEK &9e c return

Note here that the thermistor value is sampled twice, remember that the first sample is just the conversion process, see the data sheet. All this routine does is set variable C. Control Routine 4000 ‘ This controls the system ‘ 2 is a constant used for hysteresis 4000 rem control if c>d+2 then a=0:b=1 ‘ lamp off motor on if c<d then a=1:b=0 return The control routine is responsible for setting A and B determined by the value of C and D.

Main and Setup e=&fe ‘ initial output value CPOKE &9e 0 ‘ set channel 1 analogue i/p gosub 3000 print “Current temp =”, c input “set trigger value “, d 100 rem main loop gosub 1000 gosub 2000 gosub 3000 gosub 4000 goto 100 The main routine first sets E which effectively sets digital output start condition and also sets the control register for channel 1 analogue input. The first gosub 3000 is simply to indicate to the user the correct ‘ball park’ for determining the trigger value. The trigger value can be thought of as a temperature to set the system to. The main loop and in fact the way the program is written is as described in the Multi Tasking text.

This is a screen shot of the running program, I set my trigger value to 135 as shown.

9.9. Further The lamp could of just as easily be connected to the motor, M2 output, just as in this case the motor could have been connected to a relay. Again looking at the data sheet, two analogue channels could have been used in comparator mode comparing two different inputs.