Translated Version:
The PWM is controlled by the CCP1MX and P1Mx pins.
CCP1MX controls which pins are active high. We desired 1100.
P1MX controls whether we drive the motor in full h-bridge mode forward or backwards. Toggle these to change direction.
Pin connections: P1B and P1D should be attached to the motor outputs
When going forward, P1B is held low and P1D is modulated.
When going backwards, P1D is held low and P1B is modulated.
Benjie's code starts with a baseline speed from -8 to 8, then adds the direction (for the right motor) since the direction nibble ranges from full left turn to full right turn.
Our PWM period is 0x80. We write to CCPR1L to change duty cycles.
Example:
0xF8 is our input raw motor speed = -8
Our first bit is high, so we want to go backwards.
Bitshift to upper nibble = 1000 = 128 = 0x80
Which mean we go backwards at FULL SPEED
*********************************************************************
Transcript from Laurel re: PWM Pins
To whom it may concern:
The PWM is controlled by CCP1CON. Note that CCP1M1 is not equal to P1M1. \ (>_<) \
(Laurel is unhappy) So, we want CCP1M to be 1100: The magic combination with P1A and P1c active-High, P1B, P1D active -high. This is set for full H-Bridge control, the P1m1 and P1m0 are 11 (reverse) or 01 (forwards).
CCP1Mx enables PWM by setting bits 3 and 2 high. having bits 0 and 1 low makes it so that it's active high, which assume hi is on and low is off.
P1m control direction and whether it's half bridge or full bridge mode. For full bridge forward, we want *01* for full bridge reverse, we want *11*
Current configuration:
CCP1Mx: 1100
P1Mx: Toggle to go for'ard, back'ard
When it's going for'ard, P1B is held low, and P1D is modulated. Higher high times on the duty cycle means it goes for'ards faster!
When it's going back'ards, P1D is held low, and P1B is moduled. Higher high times on the duty cycle means it goes back'ards faster!
P1A and P1C are doing crazy things. IGNORE THEM!!! (or figure out what they mean later)
What Benjie's code does is calculate duty cycle based on direction. It looks at speed and direction bits. The code is currently written for the right motor. Since higher numbers means RIGHT TURN, it adds direction nibble to speed nibble. The higher the direction nibble is, the more we want to be truckin' forward on the right motor. Speed is baseline, goes from full backwards (-8) to full forwards (8). Thus, we add the direction er...directly to the speed and we get our desired duty cycle and motor direction. Negative number means we, the right motor, are going backwards (Hereafter referred to as RIGHT MOTOR)
To set direction, we set P1Mx accordingly. To set duty cycle, we write to CCPR1L.
Raw motor speed: -8 to 8
Look at 1st bit to set direction.
Bitshift to upper nibble
Our duty cycle is ready!
Note that our PWM period is 0x80.
Example:
0xF8 is our input raw motor speed = -8
Our first bit is high, so we want to go back'ards.
Bitshift to upper nibble = 1000 = 128 = 0x80
Which mean we go backwards at FULL SPEED
Example 2:
0x06 is our input raw motor speed = 6 = 00000110
Our first bit is low, so we want to go for'ards.
Bitshift to upper nibble 0110 = 0x60 which is pretty fast for our duty cycle
75% Benjie, you rock!
Sincerely,
Laurel Fullerton, Mechanical Engineering, Stanford University
Sunday, May 11, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment