Professional Documents
Culture Documents
PIC18MICROCONTROLLER {MotorControl} {M C l}
MohamadFauziZakaria http://fkee.uthm.edu.my/mfauzi
PART PART1
Interfacetohighpower Interface to high power Relay
mfauzi
3 January, 2011
mfauzi
3 January, 2011
Driving a relay
4
mfauzi
3 January, 2011
mfauzi
3 January, 2011
mfauzi
3 January, 2011
OPTOISOLATOR
7
Also called optocoupler Used to reduce the effect of voltage spike especially in coil winding system (e.g.: motors). The gap between transmitter and receiver is to prevent the electrical current surge from reaching the g system
mfauzi 3 January, 2011
PART PART2
PWMandRelatedMotorControl PWM and Related Motor Control
mfauzi
3 January, 2011
CCP Registers
1. CCPxCON : to select the compare, capture, and PWM modes 2. CCPRxL a. 16-bit compare register p g b. 16-bit capture register c. 8-bit duty cycle register
3. CCPRxH
There are three registers involved: 1. 1 CCPxCON: CPP Control 2. PR2 : Period 3. 3 CCPRxL: Duty Cycle 4. T2CON: Timer2 Control 5. TMR2: Timer2 buffer 6. TRIS: I/O Direction
Factors in PWM
12
13
14
15
PWM Period
16
When TMR2 is equal to PR2, the following three events occur on the next increment cycle: TMR2 is cleared The CCPx pin is set exception: if PWM duty cycle = 0%, the CCPx pin will not be set The PWM duty cycle is latched from CCPRxL into CCPRxH
DC9 DC8 DC7 DC6 DC5 DC4 DC3 DC2 DC1 DC0
CCPRxL Main Duty Cycle 0 0 1 1 CCPxCON Decimal Point DC1 DC0 0 1 0 1 Value 0 0.25 0.5 0.75
1. 2. 3. 4. 5. 6. 6
Set the PWM period by writing to the PR2 register. Set th S t the PWM d t cycle b writing t CCPRxL for the higher 8 bits. duty l by iti to CCPR L f th hi h bit Set the CCPx pin as an output. p p Using the T2CON register, set the prescale value. Clear the TMR2 register content. Configure the CCPxCON register for PWM and set DCxB1:DCxB0 bits for the decimal portion of the duty cycle. Start Ti 2 St t Timer2.
7.
PWM: Example
19
Create a 2.5 kHz PWM with a 75% DC on the CCP1 pin by using 4 prescale and Fosc = 10 MHz.
SpeedMotorControlthroughPWMgeneratingby CCPRegister CCP Register OnOffatanypinusinghardwareTimerorSoftwareDelay. FeedbackSensor: Encoder CounterforT0CKIandT1CKI Polling/Interrupt. INT0,1,2 INT0,1,2 polling/interrupt. OtherPins polling. Potentiometer/VariableResistor Potentiometer / Variable Resistor
ADC
DCMotor DC Motor
21
HBridgeMotorDriver
23
RCServomotor RC Servomotor
24
Allservoshavethreewires:
Black orBrown isforground. Red isforpower(~4.86V). Yellow,Orange,orWhite isthesignal wire(35V).
mfauzi
3 January, 2011
25
PART 3 PART3
StepperMotor Stepper Motor
mfauzi
3 January, 2011
STEPPER MOTOR
26
Motor speed : measured in steps/s, is a function of the switching rate. rate Holding torque: the amount of torque at zero rpm condition
mfauzi 3 January, 2011
STEPPER MOTOR
27
mfauzi
3 January, 2011
28
0 1 1
mfauzi
3 January, 2011
CCW CW
29
mfauzi
3 January, 2011
mfauzi
3 January, 2011
mfauzi
3 January, 2011
Programming
32
mfauzi
3 January, 2011