Docstoc

USB IO Board (Microchip usb port drive)

Document Sample
USB IO Board (Microchip usb port drive) Powered By Docstoc
					USB I/O Board (Microchip usb port drive)

http://dev.emcelettronica.com/print/51874

Your Electronics Open Source
(http://dev.emcelettronica.com)
Home > Blog > Emanuele's blog > Contenuti

USB I/O Board (Microchip usb port drive)
By Emanuele Created 09/08/2008 - 09:00

Technology I/O Microchip microcontroller relay USB usb port Board Description

You can power the board by USB bus. The USB can supply 500mA, so there is enough power to drive relays and displays. The microcontroller has a USB port on board . You can drive up to 8 relays and read the status of 8 optocoupler. You can use this inputs for switches, push buttons, or to have a feed back to see if the relays have been effectively switched. The communication protocol between PC and board is very simple, for example, sending the character "6" on the virtual RS232 the first relay will turn on and the board will replay with an "I" character, this response is an acknowledge and makes you sure that the command arrived and was correctly executed.

HW description The board is made of: PCB; microcontroller Microchip (18f2455 -see the Datasheet) with 32 Kb off flash memory, 256 byte of Eeprom memory and controller USB; Optocoupler for input (TPL4N25-4). USB Connector
1 din 5 08.09.2008 18:48

USB I/O Board (Microchip usb port drive)

http://dev.emcelettronica.com/print/51874

Relays. We can mount two type of relay, one with maximum 30Vcc (or 125Vac) or another with 230Vac, 2A contact. Schematics

Fig. 1

Fig. 2

Firmware description The board firmware receives a command from the PC (using the get function) elaborate the command (by ProcessIO function) and executes the command(toggle the relay or read the input). This is and example of the source code of the firmware:
void main(void) { /* A7 A6 A5 A4 A3 A2 A1 A0 */ /* 1 1 1 1 1 1 0 0 */ LATA &= 0x0; TRISA &= 0xFC; /* configure port A of uC */ /* B7 B6 B5 B4 B3 B2 B1 B0 */ /* 1 1 1 1 1 1 1 1 */ LATB &= 0x0; TRISB &= 0xFF; /* configure port B of uC */ /* C7 C6 C5 C4 C3 C2 C1 C0 */ /* 0 0 1 1 1 1 0 0 */ LATC &= 0x0; TRISC &= 0x3C; /* configure porta C of uC */ InitializeSystem(); mLED_1_Off(); MSB_num_restart = ReadEEPROM(0x20); LSB_num_restart = RedEEPROM(0x21); if ((MSB_num_restart == 0xFF)&(LSB_num_restart == 0xFF)){ /* blank eeprom */

2 din 5

08.09.2008 18:48

USB I/O Board (Microchip usb port drive)

http://dev.emcelettronica.com/print/51874

MSB_num_restart = 0 ; LSB_num_restart = 0 ; WriteEEPROM ( 0x20, 0); WriteEEPROM ( 0x21, 0); } else { if (LSB_num_restart == 0xFF){ MSB_num_restart = MSB_num_restart +1; WriteEEPROM ( 0x20, MSB_num_restart); WriteEEPROM ( 0x21, 0); LSB_num_restart = 0; } else { LSB_num_restart = LSB_num_restart +1; WriteEEPROM ( 0x21, LSB_num_restart); } } EnablePullups(); /* enable pull-up on PORTB */ while(1) { USBTasks(); /* USB Tasks */ ProcessIO(); /* See user\user.c & .h */ } } void ProcessIO(void) { if((usb_device_state < CONFIGURED_STATE)||(UCONbits.SUSPND==1)) return; if(getsUSBUSART(input_buffer,1)){ ... if(input_buffer[0] == '6') /* 0x36 */ { if(mUSBUSARTIsTxTrfReady()){ mRele_1_On(); /* turn on relay number 1*/ putrsUSBUSART("I"); /* acknoledge */ } } ... } }

The ProcessIO() function waits for a command. On this example when the board receives the "6" character on virtual RS232 (the USB) the first relay will turn on and answer with "I" character. You can also read how many time the board has been turned on, this counter is saved on the eeprom memory inside the PIC microcontroller. Software description Here is an example of software written with Visual Basic. From left ToolBox import the "SerialPort" control. We will use 3 functions of this control, which are: Open, Write, Read Let's start opening the serial port, with SerialPort.Open. The SerialPort.Open needs a serial port number to be opened; it is the number of the virtual serial port (usually it is COM4). After the virtual serial port is opened, you can send commands using SerialPort.Write function, for example if you want to turn on the first relay: SerialPort.Write("6") To read the answer from the board and to acknowledge the command received use the SerialPort.Read function

3 din 5

08.09.2008 18:48

USB I/O Board (Microchip usb port drive)

http://dev.emcelettronica.com/print/51874

Command protocol
Send 0 = 0x30 Send 2 = 0x32 Send 5 = 0x35 otherwise "H" Send 6 = 0x36 Send 7 = 0x37 Send 8 = 0x38 Send 9 = 0x39 Send a = 0x61 Send b = 0x62 Send c = 0x63 Send d = 0x64 Send e = 0x65 Send f = 0x66 Send g = 0x67 Send h = 0x68 Send i = 0x69 Send l = 0x6C Send m = 0x6D Send n = 0x6E Send o = 0x6F Send p = 0x70 Send q = 0x71 Send r = 0x72 Send s = 0x73 Send t = 0x74 Send u = 0x75 Send v = 0x76 = 48 => Turn on Led and answer "A" = 50 => Turn off Led and answer "C" = 53 => if the puss button is pressed, answer = = = = = = = = = = = = = = = = = = = = = = = =

"G"

54 => Turn on Relay 1 and answer "I" 55 => Turn off Relay 1 and answer "L" 56 => Turn on Relay 2 and answer "M" 57 => Turn off Relay 2 and answer "N" 97 => Turn on Relay 3 and answer "O" 98 => Turn off Relay 3 and answer "P" 99 => Turn on Relay 4 and answer "Q" 100 => Turn off Relay 4 and answer "R" 101 => if input 1 is on, answer "S" otherwise 102 => if input 2 is on, answer "U" otherwise 103 => if input 3 is on, answer "W" otherwise 104 => if input 4 is on, answer "J" otherwise 105 => if input 5 is on, answer "Z" otherwise 108 => if input 6 is on, answer "b" otherwise 109 => if input 7 is on, answer "d" otherwise 110 => if input 8 is on, answer "f" otherwise 111 => Turn on Relay 5 and answer "H" 112 => Turn off Relay 5 and answer "B" 113 => Turn on Relay 6 and answer "D" 114 => Turn off Relay 6 and answer "E" 115 => Turn on Relay 7 and answer "F" 116 => Turn off Relay 7 and answer "G" 117 => Turn on Relay 8 and answer "X" 118 => Turn off Relay 8 and answer "m"

"T" "V" "Y" "K" "a" "c" "e" "g"

You can also read how many time the board has been powered up:
Send w = 0x77 = 119 => Read the Most significant part of number of restart

4 din 5

08.09.2008 18:48

USB I/O Board (Microchip usb port drive)

http://dev.emcelettronica.com/print/51874

Send z = 0x7A = 122 => Read the Least significant part of number of restart

BUY NOW (24/48h delivery) Attachment Size

SW_PC_Relay_USB.zip 289.38 KB

Trademarks

Source URL: http://dev.emcelettronica.com/usb-io-board-microchip-usb-port-drive

5 din 5

08.09.2008 18:48


				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:774
posted:9/8/2008
language:English
pages:5
Description: Usb io board (based on a Microchip microcontroller featuring an usb port) allows you to drive relays and read input status, easily and at a low cost (starting from 39 euro).This board is similar to a PLC (Programmable Logic Control) yet, it receives commands from a Personal Computer using USB bus. It is easy to connect using USB because when you plug the USB to the PC, a virtual RS232 port is created so you can easily develop the application software. You can use this board for domotic application, industrial automation, etc...
About