06.07.2013 Views

Lab 8 - Claymore - Grand Valley State University

Lab 8 - Claymore - Grand Valley State University

Lab 8 - Claymore - Grand Valley State University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Grand</strong> <strong>Valley</strong> <strong>State</strong> <strong>University</strong><br />

Padnos School of Engineering<br />

EGR 345: Dynamic Systems Modeling and Control<br />

<strong>Lab</strong> Instructor: Dr. Andrew Blauch<br />

Instructor: Dr. Hugh Jack<br />

<strong>Lab</strong>oratory Exercise 8<br />

Title: Modeling Brushed DC Motors<br />

Author:<br />

Daniel D. Gage<br />

Date: December 2, 2004


Purpose:<br />

The purpose of this laboratory activity was to develop a differential equation that models<br />

brushed DC motors.<br />

Background:<br />

Applied voltage and the resulting current cause torque between the rotor and the stator in<br />

DC motors. This torque causes the rotor to accelerate. Different voltages will result in<br />

different final angular velocities. This is due to friction in the motor. As shown in Figure<br />

1, the relationship between torque and steady-state angular velocity is a straight line. As<br />

the voltage/current increase the torque and steady-state and angular velocity increase.<br />

Theory:<br />

Figure 1: Torque vs. Angular velocity ∗<br />

In order to develop the equations for the basic motor model, an equivalent circuit and a<br />

diagram showing the inertia components of the motor must be developed. These are<br />

shown in Figure 2. The circuit shows the resistance of the motor and the dependent<br />

voltage source; in this case it will be a tachometer. The right hand side shows the inertia<br />

components. The motor rotor causes the rotational inertia J1 and the attached load causes<br />

rotational inertia J2.<br />

Figure 2: Basic Motor Model *<br />

In the motor the current in the wire will push against the generated magnetic field, this<br />

∗ Jack, Hugh “Dynamics Systems Modeling and Control”, August 2004 Rev 2.5<br />

2


esults in a generated torque that is proportional to the current.<br />

T m<br />

= K ⋅ I<br />

The power of the motor must be considered.<br />

Tm<br />

∴ I =<br />

K<br />

P = Vm<br />

⋅ I = T ⋅ω<br />

= K ⋅ I ⋅ω<br />

∴ = K ⋅ω<br />

Next, the moments for the rotating masses must be summed.<br />

⎛ d ⎞<br />

∑ M = T − Tload<br />

= J ⎜ ⎟ ⋅ω<br />

⎝ dt ⎠<br />

m m<br />

load<br />

V m<br />

⎛ d ⎞<br />

∴T = J⎜<br />

⎟ ⋅ω<br />

+ T<br />

⎝ dt ⎠<br />

These equations can be manipulated to achieve the first order differential equation model<br />

of a motor.<br />

Equipment:<br />

V<br />

I =<br />

s −<br />

R<br />

V<br />

m<br />

Tm Vs<br />

− K ⋅ω<br />

∴ =<br />

K R<br />

⎛<br />

J⎜<br />

∴<br />

⎝<br />

d<br />

dt<br />

⎞<br />

⎟ ⋅ω<br />

+ T<br />

⎠<br />

K<br />

load<br />

V<br />

=<br />

2<br />

⎛ ⎞ ⎛ K ⎞<br />

∴⎜<br />

⎟ω<br />

+ ω ⋅ = V<br />

dt ⎜<br />

J R ⎟<br />

⎝ ⎠ ⎝ ⋅ ⎠<br />

s<br />

− K ⋅ω<br />

R<br />

⎛ K ⎞ T<br />

⋅⎜<br />

⎟ −<br />

⎝ J ⋅ R ⎠ J<br />

d load<br />

s<br />

• Laptop with WinAVR compiler<br />

• AT Mega32 microcontroller with L293 motor driver<br />

• 1 DC motor<br />

• 1 DC tachometer<br />

• 1 Digital Multi Meter<br />

• External power supply<br />

Procedure and Results:<br />

1. The differential equation was integrated to find an explicit function of speed as a<br />

function of time.<br />

⎛ K<br />

⎞<br />

⎛<br />

K<br />

⎞<br />

T<br />

2<br />

ω& + ω ⋅ ⎜<br />

J m<br />

⎟ = Vs<br />

⋅ ⎜ −<br />

J m R ⎟<br />

⋅<br />

load<br />

J m<br />

(1)<br />

⎝<br />

⎠<br />

⎝<br />

⎠<br />

3


Homogeneous:<br />

Therefore:<br />

Particular:<br />

Therefore:<br />

2 ⎛ K ⎞<br />

ω& + ω ⋅ ⎜<br />

⎟ = 0<br />

(2)<br />

⎝ J m ⎠<br />

t = e<br />

α<br />

ω (3)<br />

⋅t<br />

Let: ( )<br />

Homogeneous<br />

α⋅t<br />

( t)<br />

= α ⋅ e<br />

ω& (4)<br />

Homogeneous<br />

Substituting (3) and (4) into (2) yields:<br />

( t)<br />

⎛ K<br />

α + ⎜<br />

⎝<br />

2<br />

J m<br />

⎛<br />

∴α<br />

= − ⎜<br />

⎝<br />

Homogeneous<br />

⎞<br />

⎟ = 0<br />

⎠<br />

K 2<br />

J m<br />

⎟ ⎞<br />

⎠<br />

⎛ 2<br />

K ⎞<br />

−⎜<br />

⎟⋅t<br />

⎜ J ⎟<br />

⎝ m ⎠<br />

ω = C ⋅ e<br />

(5)<br />

Let: ( ) 2 C<br />

t Particular =<br />

1<br />

ω (6)<br />

( t)<br />

= 0<br />

ω& (7)<br />

Particular<br />

Substituting (6) and (7) into (1) yields:<br />

0 +<br />

∴ C<br />

⎛ K<br />

⎞<br />

K<br />

2<br />

s<br />

C ⋅ ⎜ Vs<br />

−<br />

J ⎟ = ⋅ ⎜<br />

m J m R ⎟<br />

2<br />

⋅<br />

2<br />

⎝<br />

⎠<br />

⎛<br />

⎝<br />

Vs<br />

Tload<br />

⋅ R<br />

= − 2<br />

K K<br />

Vs<br />

Tload<br />

⋅ R<br />

ω ( t)<br />

Particular = −<br />

(8)<br />

2<br />

K K<br />

Combining (5) and (8) yields:<br />

⎛ 2<br />

K ⎞<br />

−⎜<br />

⎟⋅t<br />

⎜ J ⎟ Vs<br />

Tload<br />

⋅ R<br />

⎝ m ⎠<br />

ω ( t)<br />

= C1<br />

⋅ e + −<br />

(9)<br />

2<br />

K K<br />

⎞<br />

⎠<br />

T<br />

load<br />

J<br />

m<br />

4


Solve for initial conditions:<br />

ω<br />

V<br />

K<br />

s load<br />

( ) = C + − = 0<br />

T<br />

0 1<br />

2<br />

Tload<br />

⋅ R Vs<br />

∴C = − 2<br />

K K<br />

K<br />

⋅ R<br />

1 (10)<br />

Substituting (10) into (9) yields:<br />

⎛ 2<br />

K ⎞<br />

−⎜<br />

⎟⋅t<br />

⎛ Tload<br />

⋅ R Vs<br />

⎞ ⎜ J ⎟ Vs<br />

Tload<br />

⋅ R<br />

⎝ m ⎠<br />

ω ( t)<br />

= ⎜ − ⎟ ⋅ e + −<br />

(11)<br />

2<br />

2<br />

⎝ K K ⎠ K K<br />

2. A plan was developed to measure motor parameters.<br />

R: A digital multimeter was used to measure resistance.<br />

K: The steady state response was used to attain K.<br />

2 ⎛ K ⎞<br />

ω ⎜<br />

⎟<br />

m ⋅ = V<br />

⎝ J m ⋅ R ⎠<br />

Vs<br />

∴ K =<br />

ω<br />

m<br />

s<br />

⎟ ⎛ K ⎞<br />

⋅ ⎜<br />

⎝ J m ⋅ R ⎠<br />

J: The time constant and K were used to attain J.<br />

J<br />

2<br />

K<br />

=<br />

R ⋅τ<br />

3. A program was written for the AT Mega32 that sets the PWM output and collects<br />

data for the tachometer speed. The user inputs an integer between 0 and 9, which<br />

sets the PWM output to a value between 0 and 255. The program begins to take<br />

analog voltage input from the tachometer every 10 ms. When the user presses “t”<br />

on the keyboard, the program generates a table that is displayed to the screen.<br />

This program also includes compensation for deadband in the motor. The<br />

program is shown in Appendix A.<br />

4. The resistance of the motor was measured.<br />

R = 9.4Ω<br />

5. The motor and tachometer were wired to the AT Mega32 as shown in Figure 3.<br />

5


Figure 3: Wiring diagram for AT Mega32 driving a motor with tachometer feedback<br />

6. The deadband limits of the motor were measured using the program.<br />

c_kinetic_posistve = 0x06<br />

c_kinetic_negative = 0x12<br />

c_static_positive = 0x07<br />

c_static_negative = 0x08<br />

7. From a previous lab activity, a relationship between the tachometer voltage and<br />

the angular velocity was found to be:<br />

⎛ 51⋅ π ⎞<br />

ω = ⎜ ⎟ ⋅V<br />

⎝ 30 ⎠<br />

Also, the value of count must be converted to a voltage. This was accomplished<br />

as follows:<br />

V s<br />

= count ⋅<br />

5<br />

255<br />

8. Data was obtained for the values of count, V s , ω, K, τ, and J. The data is shown<br />

in Table 1. The angular velocity of the tachometer is shown in Appendix B.<br />

6


Discussion:<br />

Count s<br />

Table 1: Motor data<br />

⎛ rad ⎞<br />

ω ⎜ ⎟<br />

⎝ sec ⎠<br />

V (V)<br />

K τ (sec)<br />

2<br />

J ( Kg ⋅ m )<br />

28 0.55 515.38 0.00107 0.30 4.02E-07<br />

56 1.10 696.67 0.00158 0.50 5.29E-07<br />

84 1.65 766.09 0.00215 0.50 9.83E-07<br />

112 2.20 805.56 0.00273 0.75 1.05E-06<br />

140 2.75 821.87 0.00334 0.75 1.58E-06<br />

168 3.29 832.56 0.00396 0.80 2.08E-06<br />

196 3.84 841.16 0.00457 0.85 2.61E-06<br />

224 4.39 848.28 0.00518 1.05 2.72E-06<br />

252 4.94 863.12 0.00572 1.30 2.68E-06<br />

The theoretical speed was calculated using Eq (11) with T = 0 . The equations used<br />

were:<br />

For count = 28<br />

ω<br />

( t)<br />

= −<br />

For count = 56<br />

ω<br />

( t)<br />

= −<br />

For count = 84<br />

ω<br />

( t)<br />

= −<br />

For count = 112<br />

ω<br />

( t)<br />

For count = 140<br />

ω<br />

( t)<br />

0.<br />

55<br />

0.<br />

00107<br />

1.<br />

10<br />

0.<br />

00158<br />

1.<br />

65<br />

0.<br />

00215<br />

⋅ e<br />

⋅ e<br />

⋅ e<br />

2.<br />

20<br />

= − ⋅ e<br />

0.<br />

00273<br />

2.<br />

75<br />

= − ⋅ e<br />

0.<br />

00334<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

2<br />

0.<br />

00107<br />

−7<br />

4.<br />

02 10<br />

×<br />

2<br />

0.<br />

00158<br />

−7<br />

5.<br />

29 10<br />

×<br />

2<br />

0.<br />

00215<br />

−7<br />

9.<br />

83 10<br />

×<br />

2<br />

0.<br />

00273<br />

−6<br />

1.<br />

05 10<br />

×<br />

2<br />

0.<br />

00334<br />

−6<br />

1.<br />

58 10<br />

×<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

load<br />

0.<br />

55<br />

+<br />

0.<br />

00107<br />

1.<br />

10<br />

+<br />

0.<br />

00158<br />

1.<br />

65<br />

+<br />

0.<br />

00215<br />

2.<br />

20<br />

+<br />

0.<br />

00273<br />

2.<br />

75<br />

+<br />

0.<br />

00334<br />

7


For count = 168<br />

ω<br />

( t)<br />

= −<br />

For count = 196<br />

ω<br />

( t)<br />

= −<br />

For count = 224<br />

ω<br />

( t)<br />

= −<br />

For count = 252<br />

ω<br />

( t)<br />

= −<br />

3.<br />

29<br />

0.<br />

00396<br />

3.<br />

84<br />

0.<br />

00457<br />

4.<br />

39<br />

0.<br />

00518<br />

4.<br />

94<br />

0.<br />

00572<br />

⋅ e<br />

⋅ e<br />

⋅ e<br />

⋅ e<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

⎛<br />

−⎜<br />

⎜<br />

⎝<br />

2<br />

0.<br />

00396<br />

−6<br />

2.<br />

08 10<br />

×<br />

2<br />

0.<br />

00457<br />

−6<br />

2.<br />

61 10<br />

×<br />

2<br />

0.<br />

00518<br />

−6<br />

2.<br />

72 10<br />

×<br />

2<br />

0.<br />

00572<br />

−6<br />

2.<br />

68 10<br />

×<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

⎞<br />

⎟⋅t<br />

⎟<br />

⎠<br />

3.<br />

29<br />

+<br />

0.<br />

00396<br />

3.<br />

84<br />

+<br />

0.<br />

00457<br />

4.<br />

39<br />

+<br />

0.<br />

00518<br />

4.<br />

94<br />

+<br />

0.<br />

00572<br />

The theoretical data for the angular velocity of the tachometer is shown in Appendix C.<br />

The theoretical and experimental data for the various speeds were graphed. The graphs<br />

are shown in Figures 4 through 12.<br />

ω (rad/s)<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 1<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 4: Angular velocity (rad/sec) vs. Time (ms), with Count = 28<br />

8


ω (rad/s)<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 2<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 5: Angular velocity (rad/sec) vs. Time (ms), with Count = 56<br />

ω (rad/s)<br />

900.00<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 3<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretcial<br />

Figure 6: Angular velocity (rad/sec) vs. Time (ms), with Count = 84<br />

9


ω (rad/s)<br />

900.00<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 4<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 7: Angular velocity (rad/sec) vs. Time (ms), with Count = 112<br />

ω (rad/s)<br />

900.00<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 5<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 8: Angular velocity (rad/sec) vs. Time (ms), with Count = 140<br />

10


ω (rad/s)<br />

900.00<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 6<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 9: Angular velocity (rad/sec) vs. Time (ms), with Count = 168<br />

ω (rad/s)<br />

900.00<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 7<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 10: Angular velocity (rad/sec) vs. Time (ms), with Count = 196<br />

11


ω (rad/s)<br />

1000.00<br />

900.00<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 8<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 11: Angular velocity (rad/sec) vs. Time (ms), with Count = 224<br />

ω (rad/s)<br />

1000.00<br />

900.00<br />

800.00<br />

700.00<br />

600.00<br />

500.00<br />

400.00<br />

300.00<br />

200.00<br />

100.00<br />

Speed 9<br />

0.00<br />

0 200 400 600 800 1000 1200<br />

Time (ms)<br />

Experimental<br />

Theoretical<br />

Figure 12: Angular velocity (rad/sec) vs. Time (ms), with Count = 252<br />

12


To show the relationship between the applied voltage and angular acceleration, all nine<br />

experimental speeds were graphed on a single graph. This is shown in Figure 13.<br />

Conclusions:<br />

ω (rad/s)<br />

1000.00<br />

800.00<br />

600.00<br />

400.00<br />

200.00<br />

0.00<br />

Speeds 1 - 9<br />

1 10 19 28 37 46 55 64 73 82 91 100<br />

Time<br />

Count 1<br />

Count 2<br />

Count 3<br />

Count 4<br />

Count 5<br />

Count 6<br />

Count 7<br />

Count 8<br />

Count 9<br />

Figure 13: Angular velocity (rad/sec) vs. Time (ms) with speeds 1 – 9<br />

• The experimental and theoretical data resulted in the same steady state angular<br />

velocity.<br />

• The theoretical data had a slightly slower acceleration than the experimental data.<br />

o This was due to errors in the selection of τ for the theoretical data.<br />

• The motor model is a very useful tool in the design and simulation of systems.<br />

13


Appendix A – C Program<br />

This program will set the PWM output and collect tachometer speed data. The user<br />

inputs a number between 0 and 9, which sets the PWM to a value between 0 and 255.<br />

The program will collect analog inputs every 10 ms. The data will be displayed onscreen<br />

when “t” is pressed on the keyboard.<br />

#include <br />

#include <br />

#include <br />

#include "sio.c"<br />

#define c_kinetic_pos 0x06 /* static friction */<br />

#define c_kinetic_neg 0x12 /* make the value positive */<br />

#define c_static_pos 0x07 /* kinetic friction */<br />

#define c_static_neg 0x08 /* make the value positive */<br />

#define c_max 255<br />

#define c_min 255 /* make the value positive */<br />

#define CLK_ms 50 /* update every 10 ms*/<br />

int moving = 0; /* assume it starts without moving */<br />

int j = 0;<br />

int table[100];<br />

int count = 0; /* a count value to be output on port B */<br />

int db_correct = 1; /* deadband correction is on by default */<br />

unsigned int CNT_timer0; /* The delay time */<br />

volatile unsigned int CLK_ticks = 0; /* The current number of ms */<br />

volatile unsigned int CLK_seconds = 0; /* The current number of seconds */<br />

int deadband(int c_wanted);<br />

void AD_setup();<br />

int AD_read();<br />

void PWM_init();<br />

void PWM_update(int value);<br />

int v_output(int v_adjusted);<br />

void IO_setup();<br />

void IO_update();<br />

void delay(int ticks);<br />

void create_array();<br />

void CLK_setup();<br />

int deadband(int c_wanted)<br />

{ /* call this routine when updating */<br />

int c_pos;<br />

int c_neg;<br />

int c_adjusted;<br />

if(moving == 1)<br />

{<br />

c_pos = c_kinetic_pos;<br />

c_neg = c_kinetic_neg;<br />

14


}<br />

}<br />

else<br />

{<br />

c_pos = c_static_pos;<br />

c_neg = c_static_neg;<br />

}<br />

if(c_wanted == 0)<br />

{ /* turn off the output */<br />

c_adjusted = 0;<br />

}<br />

else if(c_wanted > 0)<br />

{ /* a positive output */<br />

c_adjusted = c_pos +<br />

(unsigned)(c_max - c_pos) * c_wanted / c_max;<br />

if(c_adjusted > c_max) c_adjusted = c_max;<br />

}<br />

else<br />

{ /* the output must be negative */<br />

c_adjusted = -c_neg -<br />

(unsigned)(c_min - c_neg) * -c_wanted / c_min;<br />

if(c_adjusted < -c_min) c_adjusted = -c_min;<br />

}<br />

return c_adjusted;<br />

void AD_setup()<br />

{<br />

ADMUX = 0xC0; // Set the input channel to zero<br />

ADCSRA = 0xE0; // Turn on the ADC and set to free running<br />

}<br />

int AD_read()<br />

{<br />

return (ADCW >> 2); // Returns digital output from AD register<br />

}<br />

void PWM_init()<br />

{ /* call this routine once when the program starts */<br />

DDRD |= (1


{ /* call from the interrupt loop */<br />

int RefSignal; // the value to be returned<br />

if(v_adjusted >= 0)<br />

{<br />

/* set the direction bits to CW on, CCW off */<br />

PORTC = (PINC & 0xFC) | 0x02; /* bit 1 on, 0 off */<br />

if(v_adjusted > 255)<br />

{ /* clip output over maximum */<br />

RefSignal = 255;<br />

}<br />

else<br />

{<br />

RefSignal = v_adjusted;<br />

}<br />

}<br />

else<br />

{ /* need to reverse output sign */<br />

/* set the direction bits to CW off, CCW on */<br />

PORTC = (PINC & 0xFC) | 0x01; /* bit 0 on, 1 off */<br />

if(v_adjusted < -255)<br />

{ /* clip output below minimum */<br />

RefSignal = 255;<br />

}<br />

else<br />

{<br />

RefSignal = -v_adjusted; /* flip sign */<br />

}<br />

}<br />

}<br />

return RefSignal;<br />

void IO_setup()<br />

{<br />

DDRD = 0xFF; // all of port B is outputs<br />

AD_setup(); // Enable AD inputs<br />

PWM_init(); // Setup the PWM outputs<br />

DDRA = (unsigned char)0; // Set port A to outputs<br />

}<br />

void IO_update()<br />

{// This routine will run once per interrupt for updates<br />

if(db_correct == 0)<br />

{<br />

PWM_update(v_output(count));<br />

}<br />

else<br />

{<br />

PWM_update(v_output(deadband(count)));<br />

}<br />

if(count > 0)<br />

{<br />

create_array();<br />

}<br />

}<br />

16


void delay(int ticks)<br />

{ // ticks are approximately 1ms<br />

volatile int i, j;<br />

}<br />

for(i = 0; i < ticks; i++)<br />

{<br />

for(j = 0; j < 1000; j++){}<br />

}<br />

SIGNAL(SIG_OVERFLOW0)<br />

{ // The interrupt calls this function<br />

}<br />

CLK_ticks += CLK_ms;<br />

if(CLK_ticks >= 10)<br />

{ // The number of interrupts between output changes<br />

CLK_ticks = CLK_ticks - 10;<br />

CLK_seconds++;<br />

IO_update();<br />

}<br />

TCNT0 = CNT_timer0;<br />

void CLK_setup()<br />

{ // Start the interrupt service routine<br />

}<br />

TCCR0 = (0


}<br />

{<br />

}<br />

j = 0;<br />

count = 0;<br />

// -------------- The main program loop ------------------<br />

int main()<br />

{<br />

int c;<br />

sio_init();<br />

IO_setup();<br />

CLK_setup();<br />

for(;;)<br />

{<br />

while((c = input()) == -1){} // wait for a keypress<br />

if(c == 'd')<br />

{<br />

if(db_correct == 0)<br />

{<br />

db_correct = 1;<br />

outln("Deadband correction on");<br />

}<br />

else<br />

{<br />

db_correct = 0;<br />

outln("Deadband correction off");<br />

}<br />

}<br />

else if(c == 's')<br />

{<br />

count = 0;<br />

moving = 0;<br />

outint(count);<br />

outln(" = count, motor stopped");<br />

}<br />

else if(c == 'h')<br />

{<br />

outln(" d: enable (default) or disable deadband comp.");<br />

outln(" s: stop the motor");<br />

outln(" q: quit");<br />

}<br />

else if(c == '0')<br />

{<br />

count = 0;<br />

}<br />

else if(c == '1')<br />

{<br />

count = 28;<br />

}<br />

else if(c == '2')<br />

{<br />

count = 56;<br />

}<br />

18


}<br />

sio_cleanup();<br />

return 1;<br />

}<br />

else if(c == '3')<br />

{<br />

count = 84;<br />

}<br />

else if(c == '4')<br />

{<br />

count = 112;<br />

}<br />

else if(c == '5')<br />

{<br />

count = 140;<br />

}<br />

else if(c == '6')<br />

{<br />

count = 168;<br />

}<br />

else if(c == '7')<br />

{<br />

count = 196;<br />

}<br />

else if(c == '8')<br />

{<br />

count = 224;<br />

}<br />

else if(c == '9')<br />

{<br />

count = 252;<br />

}<br />

else if(c == 'r')<br />

{<br />

count = 0;<br />

outln("stopped");<br />

j = 0;<br />

}<br />

else if(c == 't')<br />

{<br />

int k;<br />

for(k = 0; k < 100; k++)<br />

{<br />

outint(table[k]);<br />

outln("");<br />

}<br />

}<br />

else if(c == 'q')<br />

{<br />

count = 0;<br />

moving = 0;<br />

outint(count);<br />

outln(" = count, Quitting");<br />

break;<br />

}<br />

19


Appendix B – Experimental angular velocity<br />

20


Appendix C – Theoretical angular velocity<br />

22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!