electronics usb

13
IMPLEMENTATION SCHEDULE OF SCRAP COLLECTOR Electronics -- USB-FX2 Interface Board (USB-2.0)  A small microcontr oller-steered 16bit parallel IO interface board connecting external devices to a computer applying USB-2.0 (high-speed). Overview [click to enlarge: 233kb JPEG] This is a USB (universal serial bus) interface board supporting USB-2.0 high speed mode (480Mbit/s). Features: Throughput: Actual continuous transfer rates of 35Mb/s (mega bytes not bits). Flexibility: On-board 8051 microcontroller with 16kb RAM. FIFO IO: 8 or 16 bit wide, additional handshake lines, 3.3V logic. Several USB endpoints and buffering configurations (up to 512 bytes, quad-buffered);  bulk, isochronous and interrupt transfer. Several additional free digital IO lines. Firmware download via USB; optional non- volatile 64kb EEPROM. USB-powered and externally powered operation. Very few discrete components. If you would simply like to connect a microcontroller board to a computer using USB but don't need massive bandwidth (less than 800kb/s), then you may want to have a look at the smaller and cheaper USB8Bit board. Schematic

Upload: nany-indresh

Post on 10-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 1/13

IMPLEMENTATION SCHEDULE OF SCRAPCOLLECTOR

Electronics -- USB-FX2 Interface Board (USB-2.0) A small microcontroller-steered 16bit parallel IO interface board connecting external devices to a computer applying USB-2.0 (high-speed).

Overview

[click to enlarge: 233kb JPEG]

This is a USB (universal serial bus) interface boardsupporting USB-2.0 high speed mode (480Mbit/s).

Features:

• Throughput: Actual continuous transfer rates of 35Mb/s (mega bytes not bits ).

• Flexibility: On-board 8051 microcontroller with16kb RAM.

• FIFO IO : 8 or 16 bit wide, additional handshakelines, 3.3V logic.

• Several USB endpoints and bufferingconfigurations (up to 512 bytes, quad-buffered);

bulk, isochronous and interrupt transfer.• Several additional free digital IO lines.• Firmware download via USB; optional non-

volatile 64kb EEPROM.• USB-powered and externally powered operation.

• Very few discrete components.

If you would simply like to connect a microcontroller board to a computer using USB but don't need massive bandwidth (less than 800kb/s), then youmay want to have a look at the smaller and cheaper USB8Bit board.

Schematic

Page 2: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 2/13

[click to enlarge: 153kb PDF]

The main component is the CY7C68013A USB-2.0interface IC ("FX2", actually it's "FX2LP" but don'tmind) from Cypress Semiconductor with integrated8051 microcontroller. Beyond that, really few externalcomponents are required.

It includes a 5V-to-3.3V low-drop regulator to providethe 3.3V logic level. Access to all data, control,handshake and clock pins is granted via dedicatedconnectors and allows direct interfacing to a variety of high-speed devices (like AD/DA converters, hard drives,FIFOs, etc.).

For more information, have a look at the detailed circuitdescription .

Host Software and FirmwareFirst of all, the software part is not as easy as with the USB8Bit board,especially if you're after high transfer rates. In order to write your ownsoftware, you need:

• The CY7C8601xA Data Sheet and, even more important, the EZ-USBTechnical Reference Manual , both available from Cypress .

• An '8051 compiler like SDCC for the firmware.• libusb , including headers, GCC, and of course all the usual development

tools assumed to be on the hard drives of anybody who is surfing these pages...

Here is a list of local and external resources around the FX2:

• My software collection : Local tools and examples verified to work withmy FX2 board, including high-speed IO transfer program FX2Pipe .

• USB Live Osci , my a little dual 8 bit 10MS/s sampling USBoscilloscope.

• SSRP : Simple Software Radio Peripheral; basically an AD converter connected to the FX2. Fast IO source code.

• FX2 programmer , another programmer similar to my one, and also check out the software radio link on that page.

EEPROM ConfigurationAs shown in the schematic above, you can attach an EEPROM (e.g. 24LC64)to the FX2 in order to permanently store the firmware for the 8051. This way,

Page 3: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 3/13

you do not have to download the firmware each time the FX2 is plugged intothe USB. Instead, it starts up with the firmware and can configure the endpointdescriptors. Here is how you do it.

Stepper MotorOf all motors, step motor is the easiest to control. It'shandling simplicity is really hard to deny - all there is todo is to bring the sequence of rectangle impulses to oneinput of step controller and direction information toanother input. Direction information is very simple and

comes down to "left" for logical one on that pin and "right" for logical zero. Motor control isalso very simple - every impulse makes the motor operating for one step and if there is noimpulse the motor won't start. Pause between impulses can be shorter or longer and it definesrevolution rate. This rate cannot be infinite because the motor won't be able to "catch up" withall the impulses (documentation on specific motor should contain such information). Thepicture below represents the scheme for connecting the step motor to microcontroller andappropriate program code follows.

The key to driving a stepper is realizing how the motor is constructed. A diagram shows therepresentation of a 4 coil motor, so named because 4 coils are used to cause the revolution of the drive shaft. Each coil must be energized in the correct order for the motor to spin.

The key to driving a stepper is realizing how the motor is constructed. A diagram shows the

representation of a 4 coil motor, so named because 4 coils are used to cause the revolution of the drive shaft. Each coil must be energized in the correct order for the motor to spin.

In Figure 3.3, as in Figure 3.1, boxes are used to represent switches; a control unit, notshown, is responsible for providing the control signals to open and close the switches at theappropriate times in order to spin the motors. The control unit is commonly a computer orprogrammable interface controller, with software directly generating the outputs needed tocontrol the switches.

As with drive circuitry for variable reluctance motors, we must deal with the inductive kick

produced when each of these switches is turned off. Again, we may shunt the inductive kickusing diodes, but now, 4 diodes are required, as shown in Figure 3.4:

Step angle

It is angle through which motor shaft rotates in one step. step angle is different for differentmotor . selection of motor according to step angle depends on the application , simply if yourequire small increments in rottion choose motor having smaller step angle.

Page 4: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 4/13

No of steps require to rotate one complete rotation = 360 deg. / step angle in deg.

Steps/second

The relation between RPM and steps per sec. is given by ,steps or impulses /sec. =(RPM X Steps /revolution ) /60 Pause between impulses can be shorter or longer and i t defines revolution rate. This ratecannot be infinite because the motor won't be able to "catch up" with all the impulses(documentation on specific motor should contain such information). So referring to RPM valuein datasheet you can calculate steps/sec and from it delay or pause between impulses

INTERFACING TO 8051.

To cause the stepper to rotate, we have to send a pulse to each coil in turn. The 8051 doesnot have sufficient drive capability on its output to drive each coil, so there are a number of ways to drive a stepper,

Stepper motors are usually controlled by transistor or driver IC likeULN2003.

Driving current for each coil is then needed about 60mA at +5V supply. A Darlington transistorarray, ULN2003 is used to increase driving capacity of the 2051 chip. Four 4.7k resistors helpthe 2051 to provide more sourcing current from the +5V supply.

CODE EXAMPLE

To move motor in forward direction continuously

Connection -P1.0 -P1.3 connected to Coils A -D.

MBLY LANGUAGE C LANGUAGE (SPJ)

mov a,#66h ;Load step sequence

AGAINmov p2,a ;issue sequence to motorr a ;rotate step sequence right clockwise=Next sequencecall DELAY ;~ 20 msec.jmp AGAIN ;Repete again

void main (){

TMOD = 0x20 ; TCON = 0x40 ; TH1 = 0xf9 ; TL1 = 0xf9 ;PCON = 0x80 ;SCON = 0x50 ;while (1) /*continues loop */{printf("a"); /* transmit a along with CR & LF.

Page 5: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 5/13

}

As port A is used as an output port, control word for 8255 is 80H.

Stepper Motor Control Program:

6000H Excite code DB 03H, 06H,09H, OCH : This is the code sequence for clockwise

rotation

Subroutine to rotate a stepper motor clockwise by 360 ° - Set the counts:

MVI C, 32H : Set repetition count to 50ı ο

START: MVI B, 04H : Counts excitation sequenceLXI H, 6000H : Initialize pointer

BACK1: MOV A, M : Get the Excite codeOUT PORTA : Send Excite codeCALL DELAY : Wait INX H : Increment pointer DCR B : Repeat 4 timesJNZ BACK l DCR C JNZ START : Repeat 50 timesRET

Delay subroutine:

Delay: LXI D, Count Back: DCX D

MOV A, DORA E

Page 6: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 6/13

JNZ Back RET

Basic Circuit for 8051

8051 PIN OUT

Power - Vcc, Vss

Reset - RST

Crystal - XTAL[1,2] External device interfacing

– EA, ALE, PSEN, WR, RD

I/O Port– P0[7;0], P1[7:0], P2[7:0], P3

P3 is shared with control lines

– Serial I/O RxD, TxD,– external interrupts INT0, INT1– Counter control T0, T1

P0 and P2 are multiplexed with Address and Data bus

Page 7: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 7/13

EA/VP PinThe EA on pin 31 is tied high to make the 8051 executes program from Internal ROM

Reset Circuit

Page 8: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 8/13

RESET is an active High input When RESET is set to High, 8051 goes back to the power onstate.The 8051 is reset by holding the RST high for at least two machine cycles and then returning itlow.

Power-On Reset

- Initially charging of capacitor makes RST High- When capacitor charges fully it blocks DC.

Manual reset

-closing the switch momentarily will make RST High.

After a reset, the program counter isloaded with 0000H but the content of on-chip RAM is not affected.

Oscillator Circuit

The 8051 uses the crystal for preciselythat: to synchronize it’s operation.Effectively, the 8051 operates usingwhat are called "machine cycles." Asingle machine cycle is the minimumamount of time in which a single 8051

instruction can be executed. although many instructions take multiple cycles.

8051 has an on-chip oscillator. It needs an external crystal thats decides the operatingfrequency of the 8051.

This can be achieved in two ways,,

The crystal is connected to pins 18 and 19 with stabilizing capacitors. 12MHz(11.059MHz) crystal is often used and the capacitance ranges from 20pF to 40pF.

The oscillator can also be a TTL clock source connected with a NOT gate asshown

How fast 8051 works ?

A cycle is, in reality, 12 pulses of the crystal. That is to say, if an instruction takes onemachine cycle to execute, it will take 12 pulses of the crystal to execute. Since we know thecrystal is pulsing 11,059,000 times per second and that one machine cycle is 12 pulses, wecan calculate how many instruction cycles the 8051 can execute per second:

11,059,000 / 12 = 921,583

Why is such an oddball crystal frequency?

11.0592 MHz crystals are often used because it can be divided to give you exact clock ratesfor most of the common baud rates for the UART, especially for the higher speeds (9600,19200). Despite the "oddball" value, these crystals are readily available and commonly used.

Page 9: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 9/13

Power Supply

C1-1000 mf ,C2-100 mf

The 78L05 is a 5V regulator. The input voltage ranges from 7V to 35V and the output voltageis about 5V.

Using Ports for I/O Operation

8051 is TTL logic device. TTL logic has two levels: Logic "High" (1) and logic "Low" (0). The

voltage and current involved for the two levels are as follows:

Level Voltage Current

High Above 2.4V Virtually no current flow

Low Below 0.9V1.6mA Sinking current from TTL input toground(Depends on logic family)

1. Configuring for output

P0 is open drain.– Has to be pulled high by external 10K resistors.– Not needed if P0 is used for address lines

Writing to a port pin loads data into a port latch that drives a FET connected to the port pin.

P0: Note that the pull-up is absent on Port 0 except when functioning as the externaladdress/data bus. When a "0" is written to a bit in port 0, the pin is pulled low. But when a "1"is written to it, it is in high impedance (disconnected) state. So when using port 0 for output,an external pull-up resistor is needed, depending on the input characteristics of the devicedriven by the port pin P1, P2, P3 have internal pull-ups: When a "0" is written to a bit in these port , the pin ispulled low ( FET-ON) ,also when 1 is written to a bit in these port pin becomes high (FET-OFF) thus using port P1,P2,P3 is simple.

2. Configuring for input

At power-on all are output ports by default

Page 10: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 10/13

To configure any port for input, write all 1’s (0xFF) to the portLatch bit=1, FET=OFF, Read Pin asserted by read instruction

You can used a port for output any time. But for input, the FET must be off. Otherwise, youwill be reading your own latch rather than the signal coming from the outside. Therefore, a "1"should be written to the pin if you want to use it as input, especially when you have used it foroutput before. If you don't do this input high voltage will get grounded through FET so you willread pin as low and not as high. An external device cannot easily drive it high

so, you should not tide a port high directly without any resistor. Otherwise, the FET wouldburn.

Be Careful :

Some port pins serve multiple functions. Be careful writing to such ports. For example, P3.0 isthe UART RXD (serial input), and P3.1 is the UART TXD (serial output). If you set P3.0 to a '0',an external buffer (such as an RS232 level translator) cannot drive it high. Therefore you haveprevented receiving any serial input.

If an external interrupt such as EX1 on P3.3 is enabled, and set to be level sensitive, and youclear this pin's output latch to a zero, guess what? You've just caused a perpetual interrupt 1.The pin's input buffer will read the output of it's latch as always low. Your controller will spendall of its time in the interrupt handler code and will appear to have crashed, since it will havevery little time for other tasks. In fact, it will get to execute a single instruction before re-entering the interrupt handler, so the rest of your program will execute very, very slowly.

mov b,#00;mov a,#00;

initial:mov a,p1;cmp a,#00;

jnz l1; jmp drive;l1: cmp a,#01;

jnz l2; jmp back; jmp right;

l2:cmp a,#04; jnz l3;

jmp back; jmp left;

l3:cmp a,#03; jnz l4; jmp back; jmp left; jmp left;

Page 11: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 11/13

l4:cmp a,#06; jnz l5; jmp back; jmp right;

jmp right;

l5:cmp a,#02; jnz l6; jmp arm;

l6:cmp a,#07; jnz l7; jmp back; jmp right;l7:jmp initial

hltdrive:mov ro,a;mov a,#ffh ;Load step sequence mov p2,a ;issue sequence to motor rr a ;rotate step sequence right clockwise=Next sequenceacall DELAY ;~ 20 msec.mov a,ro;ret;

back:mov ro,a;mov a,#66h ;Load step sequence mov p2,a ;issue sequence to motor rr a ;rotate step sequence right clockwise=Next sequenceacall DELAY ;~ 20 msec.mov a,ro;setb p3.1;ret;

right:mov ro,a;mov a,#66h ;Load step sequence mov p2,a ;issue sequence to motor rr a ;rotate step sequence right clockwise=Next sequenceacall DELAY ;~ 20 msec.

Page 12: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 12/13

mov a,ro;

setb p3.2;ret;

left:mov ro,a;mov a,#66h ;Load step sequence mov p2,a ;issue sequence to motor rr a ;rotate step sequence right clockwise=Next sequenceacall DELAY ;~ 20 msec.mov a,ro;

setb p3.3;ret;

arm:mov ro,a;mov a,#ffh ;Load step sequence

mov r1,#50repeat:mov p2,a ;issue sequence to motor rr a ;rotate step sequence right clockwise=Next sequenceacall DELAY ;~ 20 msec.dec r1;

jnz repeat;

mov a,ro;ret;

MACHINE CONTROL:

Three IR sensors are placed in the front of the machine. So the inputs can be consideredas a three bit word with the following possibilities of output

0 0 0(00h) the machine must continue moving straight.

0 0 1 (01h) the machine has encountered an obstacle in the left and hence has to moveright.

1 0 0(04h) the machine has encountered an obstacle in the right and hence has to moveleft.

0 1 1(03h) the machine must move left twice and continue moving forward.

Page 13: Electronics USB

8/8/2019 Electronics USB

http://slidepdf.com/reader/full/electronics-usb 13/13

1 1 0(03h) the machine must move right twice and continue moving forward.

0 1 0(02h) the machine must use its arm.

1 1 1(07h) the machine must move back and turn left or right