Laboratory Exercise 1 Microcontroller Board with Driver Board The purpose of this lab exercises is to demonstrate how the Microcontroller Board can be used to control motors connected to the Driver Board to achieve custom and precise control over the motors. There motors include DC motor, Unipolor and Bipoloar motors, servo motors, and brushless motors. In this exercises, we will demonstrate how to control the speed of the DC motor, how to control the degree of turning of a bipolar stepper motor as well as the servo motor. As previously mentioned in the Driver Board lab exercises, the Driver Board offers two type of control: manual, and PIC. When PIC mode is selected on the Driver Board, signal input from the Microcontroller will be expected by the Driver Board, and this signal will be routed to the motor to achieve control. DC Motor DC motors are devices that transfer electrical energy into mechanical energy. A typical DC motor consists of a series of magnetic poles (stator) arranged at a fixed number of degrees. A rotor containing a set of windings is located in between the stator. When electrical energy is applied to the motor the current circulating on the windings react with the magnetic field produced by the magnetic poles creating movement of the rotor. The rotor is then attached to a shaft where the load can be applied. Driving the DC motor using an external microcontroller requires two basic digital signals: (1) a Start/Stop and (2) a Direction signal. The Start/Stop signal can be pulse width modulated (PWM) in order to control the speed of the motor. The PWM signal should have a frequency from 1 KHz to 2 KHz. (CAUTION: Check the ratings of your motor for the actual frequency requirements). In order to increase or decrease the speed of the motor you need to control the duty cycle (i.e. the amount of time the signal is ON). To demonstrate in basics how the Start/Stop signal works, we will use delay functions generated in the PIC16 on the Microcontroller to pulse the output of the PORT pins and therefore achieving the PWM frequency required. While the choice of pin is arbitrary, we will use RA1 for Start/Stop signal and RA0 for the Direction signal. For 1 KHz frequency we pulse the pin RA0 in 1ms interval. Start_Stop bsf PORTA,1 ;Pluse RA1 high call Delay ;Delay for 1ms bcf PORTA,1 ;Pluse RA1 low call Delay ;Delay for 1ms goto Start_Stop ;infinite loop goto $
The delay routine can be generated easily by an online tool called Delay Code Generator. 1 Note that in order for the delay generated to function correctly, the Clock Frequency must be set to 10MHz which is the oscillator frequency on the Microcontroller Board. The delay code will look something like the following: ;*************************************** ; Delay 1ms ;*************************************** Delay movlw 0xF3 movwf d1 movlw 0x02 movwf d2 Delay_0 decfsz d1, f goto $+2 decfsz d2, f goto Delay_0 goto $+1 return ;2 cycles Note that variables d1, d2 are not declared in the delay routine generated. The user must declare the variables at the beginning of the code. The Direction signal can be either a high signal for the forward direction or low signal for the reverse direction. This is easily achieved by setting a particular pin high or low in the Microcontroller. bcf PORTA,0 ;Pluse RA0 low for dirction selection In order to drive a DC motor using the PIC Microcontroller board follow the next steps: 1. Make sure that the Mode Selector switch is in the DC mode. The LED labelled DC will turn ON. 2. Also, make sure that the DC/Bipolar jumper is on the DC mode. 3. Locate the PIC/ MAN switch on the controller side of the DC motors. Select the PIC mode. 4. Based on your motor ratings connect the required power of the motor on the right side of the board. Look for the terminal labelled DC1 PWR. 5. Connect the motor to the terminals labelled DC1 OUT located at the bottom right side of the board. 1 This tool can be found online at: http://www.piclist.com/cgi bin/delay.exe
6. Locate the DC1 Controller module and connect the three signals: DIR DC1, CLK DC1 and GND from the PIC Microcontroller Board. 7. In order to achieve the right duty cycle you can implement delays between turning the signal ON and OFF, the time of the delay depends mainly in the frequency of your motor and the speed requirements. For instance, a 50% on a 1KHz motor will require a delay of 500ms. Bipolar Stepper Motor A stepper motor is designed to run in discrete incremental steps when the correct electrical sequence of pulse is applied to the coils of the motor. Typically a bipolar motor has 4 wires which represent two sets of coils. Each set of coils can be thought ad a separate DC motor. Therefore it is possible to run a bipolar stepper motor in the same way a DC motor is run. The bipolar stepper motor requires a pulse sequence to operate; the direction and speed of the motor can be entirely controlled by adjusting the pulse sequence. Driving the Bipolar Stepper motor using an external microcontroller requires three basic digital signals: (1) a Start/Stop and (2) a Direction signal and (3) a Clock signal. In the following example we will attempt to drive a bipolar stepper motor with PIC16 on the Microcontroller Board. The pin assignment is as follow: RA2 will be used as Start/Stop pin, RA0 will be used as Direction signal, and RA1 as clock signal. The Start/Stop signal RA2 can be simply set high to start the motor or low to stop the motor by using the bcf or bsf command. The Direction signal RA0 is set to high for forward direction and low for reverse direction. By changing the frequency of the Clock signal you should be able to speed up or reduce the speed of the motor. To change the frequency the ON and OFF times must change either independently or simultaneously. To drive the bipolar motor, you can set the ON and OFF time delays at 1ms each. clock bsf PORTA,1 ;Pluse the clock signal high call Delay ;1ms delay bcf PORTA,1 ;Pluse the clock signal low call HalfS ;1ms delay goto clock ;infinite loop goto $ Note that with different delay time one can change the speed of bipolar stepper motor. Also one of the properties of stepper motors is the degree per turn. This is the degree the bipolar motor turns during one clock signal in this case, 2ms. To control the degree of turning, one can simply calculated the number of cycle needed according to the motor property, and use a finite loop instead of the infinite loop. In order to drive a bipolar motor using the PIC Microcontroller board follow the next steps:
1. Make sure that the Mode Selector switch is in the BP mode. The LED labelled BP will turn ON. 2. Also, make sure that the DC/Bipolar jumper is on the BP mode. 3. Locate the PIC/MAN switch on the controller side of the bipolar motor. Select the PIC mode. 4. Based on your motor ratings connect the required power of the motor on the right side of the board. Look for the terminal labelled DC1 PWR or DC2 PWR. 5. Connect the motor to the terminals labelled DC1 OUT and DC2 OUT located at the bottom right side of the board. 6. Locate the Bipolar Controller module and connect the four signals: CLK, START STOP, DIR AND GND from the PIC Microcontroller Board. Servo Motor Servo motors are used in many applications because they provide a reliable and controlled movement. A servo motor consists of a DC motor a small electronic feedback system which includes a potentiometer and a gear system. A typical servo motor consists of three wires. A power and a ground wires and a signal wire. The signal wire is used to provide the motor the necessary pulse to drive it. Servo motors are really simple to drive but they can be delicate too. You must be careful when driving a servo motor since a high frequency pulse can permanently damage the motor. Always review the motor datasheet before running it. The servo motor requires only one clock pulse to operate. The required clock pulsed must be low frequency (about 50 Hz) and a low duty cycle range to operate (0.9 to 2.1 ms). By changing the duty cycle between the appropriate duty cycle ranges, the servo can be positioned accurately. To drive the servo motor with pluses generated by the Microcontroller, assign any pin for the clock pulse, and the ON delay should be anywhere from 0.9 to 2.1 ms and the OFF time for 17.9 or 19.1ms. clock bsf PORTA,1 ;Pluse the clock signal high call ON_Delay ;On delay at 0.9 to 2.1ms depends on ;the motor bcf PORTA,1 ;Pluse the clock signal low call OFF_Delay ;OFF delay at 17.9 to 19.1ms goto clock ;infinite loop goto $ ;Stall here The duty cycle wave will looks something like this:
To control the degree of turn of the servo motor, In order to drive a servo motor using the PIC Microcontroller board follow the next steps: 1. Locate the PIC/MAN switch on the controller side of the servo motors. Select the PIC mode. 2. Based on your motor ratings connect the required power of the motor on the right side of the board. Look for the terminal labelled SRV PWR 3. Connect the motor to the terminals labelled SRV OUT or if the servo motor has the right female header, connect it to the supplied male header 4. Locate the Servo Controller module and connect the two signals: CLK AND GND from the PIC Microcontroller Board. 5. To drive the servo motor, you need to set the ON delay anywhere from 0.9 to 2.1 ms and the OFF time for 19.1 or 17.9 ms.