**** 3 PHASE PWM OUTPUT ****
** The output frequency starts from 0Hz to 50Hz
** This program is tested on a HC11 board in extended mode
** eprom size 27C256
** if You change the start address from $8000 to $E000 eprom size 27C64
PORTA EQU $0000
TCNT EQU $000E
TOC1 EQU $0016
TOC2 EQU $0018
TOC3 EQU $001A
TOC4 EQU $001C
TOC5 EQU $001E
TCTL1 EQU $0020
TMSK1 EQU $0022
TFLG1 EQU $0023
OPTION EQU $0039
INIT EQU $003D
*----------------------------------------------------------------
org $0040
FREQ_PRESET RMB 2 * 5000 => 50 Hz
FREQ_ACTUAL RMB 2 * from 0 to 5000 => 0Hz to 50 Hz
V_MOT RMB 1 * Voltage Motor
pwm RMB 2 * temporary variable pwm3.inc
PTR_SINUS RMB 4 * pointer for sinus table
PTR_ADD RMB 2 * pointer increase with this value
TEMP RMB 2 * temporary variable
*----------------------------------------------------------------
*----------------------------------------------------------------
org $8000
START clr INIT+$1000 * direct Adressing Mode
sei
clr TMSK1
LDAA #10011011B enable ADC,clock monitor,
STAA OPTION and set COP timer delay
TPA
ORAA #$80 disable STOP instruction
TAP
lds #$FF
*--------------------------------
ldx #$40
clearram clr 0,X
inx
cpx #$0100
blo clearram
*---------------------------------------------
ldaa PORTA
anda #%11000111
staa PORTA
ldaa #%00010101 * Output Toggle bei Compares
staa TCTL1 * OC3, OC4 und OC5, Setzen bei OC2
ldaa #%10000000 * OC1 Interrupt freigeben
staa TMSK1 *
ldd #$FF69 * Output Compares initialisieren
std TOC1
ldd #$FF40
std TOC3
std TOC4
std TOC5
ldd #Sin000
std PTR_SINUS
*--------------------------------------------
ldaa #90
staa V_MOT
ldd #3000 * 5000 => 50 Hz
std FREQ_PRESET
* =============================
ldaa TCNT
adda #12
staa TOC1
cli
wai
*********************************************************************
*** BLOCK 1 7 x 128 µsec = 896 µsec
*********************************************************************
PWM3_LOOP wai
ldd FREQ_ACTUAL
addd #1
std FREQ_ACTUAL
cpd FREQ_PRESET
blt RAMP_OK
ldd FREQ_PRESET
std FREQ_ACTUAL
RAMP_OK
wai
ldd FREQ_ACTUAL
LDX #4200
IDIV
STX TEMP remainder in D
wai
LDX #4200
FDIV
wai
XGDX
TAB
LDAA TEMP+1
STD PTR_ADD
wai
wai
wai
*********************************************************************
*** BLOCK 2 7 x 128 ęsec = 896 ęsec UF_BERECHNUNG
*********************************************************************
wai
wai
ldd FREQ_ACTUAL
cpd #4200
blo div_okay
wai
ldab #255 * max. modulation
bra UF_OK
div_okay ldx #4200
wai
fdiv
xgdx
tab
UF_OK wai
ldx #UF_TABLE
abx
ldab X
subb #10
bcc save_V_MOT
clrb
save_V_MOT clrb
stab V_MOT
wai
*********************************************************************
*** BLOCK 3 7 x 128 µsec = 896 ęsec TIMER usw.
*********************************************************************
wai wai_0
wai wai_1
wai wai_2
wai wai_3
wai wai_4
wai wai_5
wai wai_6
jmp PWM3_LOOP
*====================================================================
*====================================================================
***********************************************************************
****** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *****
*Never make changes in this routines
*EVERY CYCLE is calculated exactly
*
* Bytes
INTERRUPT_OC1 LDAA TOC3+1 * 3 2 IM RAM
LDAB TOC4+1 * 3 2
NEGA * 2 1
NEGB * 2 1
STAA TOC3+1 * 3 2
STAB TOC4+1 * 3 2
NEG TOC5+1 * 6 2
*---------------------------------------*--- 22 cycles
nop * 2
nop
nop
nop
nop
*-----------------------------------------------
ldaa TOC3+1 * 4
LDY PTR_SINUS * 5
LDX PTR_SINUS * 4
CBA * 2
BCS SETPWM_1 * 3
CMPB #222 * 2
BCC SETPWM_2 * 3
LDD PTR_SINUS+1 * 4
ADDD PTR_ADD * 5
STAB PTR_SINUS+2 * 3
LDAB #186 * 2
STAB TFLG1 * 3
BCS *+3 * 3
CMPA #$10 * 2
STAA PTR_SINUS+1 * 3
LDAB V_MOT * 3
ABX * 3
LDAA TOC1 * 3
INCA * 2
STAA TOC1 * 3
LDAB 0,y * 5
ADDB 0,x * 4
LSRB * 2
STD pwm * 4
LDAB 62,y * 5
ADDB 62,x * 4
LSRB * 2
STD TOC4 * 4
LDAB 124,y * 5
ADDB 124,x * 4
LSRB * 2
LDX pwm * 4
STD TOC5 * 4
STX TOC3 * 4
RTI * 12
*-------------------------------------------
SETPWM_1 cmpa #222
bcc SETPWM_2
ldd PTR_SINUS+1
addd PTR_ADD
stab PTR_SINUS+2
ldab #186
stab TFLG1
bcs *+3
cmpa #$10
staa PTR_SINUS+1
ldab V_MOT * 3
abx * 3
ldaa TOC1
inca * 2
staa TOC1 * 3
ldab 124,y * 5
addb 124,x * 4
lsrb * 2
std pwm * 3
ldab 0,y * 5
addb 0,x * 4
lsrb * 2
std TOC3 * 4
ldab 62,y * 5
addb 62,x * 4
lsrb * 2
ldx pwm * 4
std TOC4 * 4
stx TOC5 * 4
rti * 12
*-------------------------------------------
SETPWM_2 ldd PTR_SINUS+1 * 4
addd PTR_ADD * 5
stab PTR_SINUS+2 * 3
ldab #186
stab TFLG1
bcs *+3
cmpa #$10
staa PTR_SINUS+1
ldab V_MOT
abx
ldaa TOC1
inca
staa TOC1
ldab 62,y
addb 62,x
lsrb
std pwm
ldab 124,y
addb 124,x
lsrb
std TOC5
ldab 0,Y
addb 0,X
lsrb
ldx pwm
std TOC3
stx TOC4
rti
*-----------------------------------------------------------------
*-----------------------------------------------------------------
ORG $F800 * The table must have address xx00
Sin000 fcb 064,067,071,074,078,081,084,087,090,093
fcb 096,099,101,104,106,108,110,112,113,115
fcb 116,118,119,119,120,121,121,122,122,122
fcb 122,122,122,122,122,122,122,122,121,121
fcb 121,121,121,120,120,120,120,120,120,120
fcb 120,121,121,121,121,121,122,122,122,122
fcb 122,122
Sin120 fcb 122,122,122,122,122,121,121,120,119,119
fcb 118,116,115,113,112,110,108,106,104,101
fcb 099,096,093,090,087,084,081,078,074,071
fcb 067,064,061,057,054,050,047,044,041,038
fcb 035,032,029,027,024,022,020,018,016,015
fcb 013,012,010,009,009,008,007,007,006,006
fcb 006,006
Sin240 fcb 006,006,006,006,006,006,006,007,007,007
fcb 007,007,008,008,008,008,008,008,008,008
fcb 007,007,007,007,007,006,006,006,006,006
fcb 006,006,006,006,006,006,007,007,008,009
fcb 009,010,012,013,015,016,018,020,022,024
fcb 027,029,032,035,038,041,044,047,050,054
fcb 057,061
Sin360 fcb 064,067,071,074,078,081,084,087,090,093
fcb 096,099,101,104,106,108,110,112,113,115
fcb 116,118,119,119,120,121,121,122,122,122
fcb 122,122,122,122,122,122,122,122,121,121
fcb 121,121,121,120,120,120,120,120,120,120
fcb 120,121,121,121,121,121,122,122,122,122
fcb 122,122
fcb 122,122,122,122,122,121,121,120,119,119
fcb 118,116,115,113,112,110,108,106,104,101
fcb 099,096,093,090,087,084,081,078,074,071
fcb 067,064,061,057,054,050,047,044,041,038
fcb 035,032,029,027,024,022,020,018,016,015
fcb 013,012,010,009,009,008,007,007,006,006
fcb 006,006
fcb 006,006,006,006,006,006,006,007,007,007
fcb 007,007,008,008,008,008,008,008,008,008
fcb 007,007,007,007,007,006,006,006,006,006
fcb 006,006,006,006,006,006,007,007,008,009
fcb 009,010,012,013,015,016,018,020,022,024
fcb 027,029,032,035,038,041,044,047,050,054
fcb 057,061
fcb 064,067,071,074,078,081,084,087,090,093
fcb 096,099,101,104,106,108,110,112,113,115
fcb 116,118,119,119,120,121,121,122,122,122
fcb 122,122,122,122,122,122,122,122,121,121
fcb 121,121,121,120,120,120,120,120,120,120
fcb 120,121,121,121,121,121,122,122,122,122
fcb 122,122
*
ORG $FC00 * Table to calculate motor voltage
UF_TABLE fcb 093,093,093,092,092,092,091,091,091,091 * 1
fcb 090,090,090,090,089,089,089,089,088,088 * 2
fcb 088,088,087,087,087,087,086,086,086,086 * 3
fcb 085,085,085,085,084,084,084,084,083,083 * 4
fcb 083,083,082,082,082,082,081,081,081,081 * 5
fcb 080,080,080,080,079,079,079,079,078,078 * 6
fcb 078,078,077,077,077,076,076,076,076,075 * 7
fcb 075,075,075,074,074,074,074,073,073,073 * 8
fcb 073,072,072,072,071,071,071,071,070,070 * 9
fcb 070,070,069,069,069,068,068,068,068,067 *10
fcb 067,067,067,066,066,066,065,065,065,065 *11
fcb 064,064,064,063,063,063,063,062,062,062 *12
fcb 061,061,061,061,060,060,060,059,059,059 *13
fcb 058,058,058,058,057,057,057,056,056,056 *14
fcb 055,055,055,054,054,054,054,053,053,053 *15
fcb 052,052,052,051,051,051,050,050,050,049 *16
fcb 049,049,048,048,048,047,047,046,046,046 *17
fcb 045,045,045,044,044,044,043,043,042,042 *18
fcb 042,041,041,040,040,040,039,039,038,038 *19
fcb 038,037,037,036,036,035,035,035,034,034 *20
fcb 033,033,032,032,031,031,030,030,029,029 *21
fcb 028,028,027,026,026,025,025,024,023,023 *22
fcb 022,021,021,020,019,018,017,016,015,014 *23
fcb 013,012,011,009,007,004,000,000,000,000 *24
fcb 000,000,000,000,000,000,000,000,000,000 *25
fcb 000,000,000,000,000,000
ORG $FFE8
FDB INTERRUPT_OC1
ORG $FFFE
FDB START