AN1291 - APPLICATION NOTE
16/33
4. 3 ’AD interrupt’ routine
The AD interrupt is used as counter; in fact, each 16 µs an interrupt is generated and the counter
’AD_int_counter’is incremented.
The period between two interrupts is given by the formula:
Tconv=number_of_channels*[78*SCK+4]*TCKM
when ’SCK’ is 2 or 1 if AD frequency is divided by 2 or not, and TCKM is the period of the clock master.
In the case described, when the number of channels converted are 2 (0 and 1) and the AD frequency is
the clock master frequency (20 Mhz) divided by 2,
Tconv=2*[78*2+4]*50 ns= 16 µs.
Figure 21. A/D Interrupt routine
When the counter ’AD_int_counter’ reaches the value ’Fstator’, the pointers are incremented in order to
read on the look-up-table the new sample value of thesine wave (see Read_table folder paragraph), and
’AD_int_counter’is first put to 255, so that, when increased, it is reset.
4.4 ’External interrupt’ and ’PWM0 interrupt’ routines
The external interrupt is used to measure the rotor period; in fact it is measured by counting the time be-
tween two positive edges of the square wave supplied by a tachometer system, that is connected to the
INT pin; a variable named ’flag’ is used to select the edge. If the variable value is 0, the PWM0_int is en-
abled, in order to start the calculation of a period, and the variable ’flag’ is set to 1. At the next external
interrupt the PWM0_int is disabled andthe value reached from the variable ’Fr_measure’is a measure of
the rotor period.
Moreover, the variable ’flag’is set to 0, in order to restart the calculationat the following edgeandthe vari-
able ’flag_fuzzy’is set to 1, in order to perform the fuzzy control (see Fig. 23).