Page 287 - Programming Microcontrollers in C
P. 287
272 Chapter 5 Programming Large 8-Bit Systems
will execute its control code each time tick is TRUE. tick is ini
tialized to TRUE when it is created, and it is set to FALSE each time
the if (tick) routine is entered in the application program. If
you go to the end of Listing 5-7, you will find that tick is reset to
TRUE about each quarter of a second in the PWM timer routine.
This sequence will cause the feedback calculation to be executed
about each quarter of a second.
The initialization portion of the program shown in Listing 5-7 is
little changed from that of the one shown in Listing 5-6. As mentioned
above, we have added an application section that contains the
calculations to control the motor speed. Also, there is one simple
function that is used by the application section.
#include “hc11e9.h”
#define DIVIDE_8_SHIFT 3
#define COUNT_8 8
#define COUNT_MAX 3300
#define COUNT_MIN 1600
#define COUNT_ONE_QUARTER 32
#define PERIOD 0X1000
#define TIME_ON 0x0800
#define IMPOSSIBLE 3500
#define TOO_LOW 100
@port void IC1_Isr(void);
@port void OC2_Isr(void);
@port void OC3_Isr(void);
long limit (long);
long measured_period,delpc;
WORD time1,time2, motor_period,
motor_speed=IMPOSSIBLE;
WORD old_motor_speed=TOO_LOW,rpm,mparray[COUNT_8];
long PWM_period=PERIOD, PWM_count=TIME_ON;
int tick=TRUE,count=0;
main()
{