RAMStart EQU $0060
RomStart EQU $8000
VectorStart EQU $FFD2
$Include 'mr_regs.inc'
org RamStart
PTR_SINUS ds 3
LOOPTIMING ds 1
LOOPCOUNTER ds 1
TEMP ds 1
TIMER ds 1
org RomStart
;******** sine table with 192 base points
SINE_TABLE
DB 128T,132T,136T,140T,145T,149T,153T,157T ; line 1
DB 161T,165T,169T,173T,177T,180T,184T,188T ; line 2
DB 192T,195T,199T,202T,205T,209T,212T,215T ; line 3
DB 218T,221T,223T,226T,229T,231T,234T,236T ; line 4
DB 238T,240T,242T,244T,245T,247T,248T,250T ; line 5
DB 251T,252T,253T,253T,254T,254T,255T,255T ; line 6
DB 255T,255T,255T,254T,254T,253T,253T,252T ; line 7
DB 251T,250T,248T,247T,245T,244T,242T,240T ; line 8
DB 238T,236T,234T,231T,229T,226T,223T,221T ; line 9
DB 218T,215T,212T,209T,205T,202T,199T,195T ; line 10
DB 191T,188T,184T,180T,177T,173T,169T,165T ; line 11
DB 161T,157T,153T,149T,145T,140T,136T,132T ; line 12
DB 128T,124T,120T,116T,111T,107T,103T,099T ; line 13
DB 095T,091T,087T,083T,079T,076T,072T,068T ; line 14
DB 064T,061T,057T,054T,051T,047T,044T,041T ; line 15
DB 038T,035T,033T,030T,027T,025T,022T,020T ; line 16
DB 018T,016T,014T,012T,011T,009T,008T,006T ; line 17
DB 005T,004T,003T,003T,002T,002T,001T,001T ; line 18
DB 001T,001T,001T,002T,002T,003T,003T,004T ; line 19
DB 005T,006T,008T,009T,011T,012T,014T,016T ; line 20
DB 018T,020T,022T,025T,027T,030T,033T,035T ; line 21
DB 038T,041T,044T,047T,051T,054T,057T,061T ; line 22
DB 065T,068T,072T,076T,079T,083T,087T,091T ; line 23
DB 095T,099T,103T,107T,111T,116T,120T,124T ; line 24
;*****REPEAT TABLE*****
DB 128T,132T,136T,140T,145T,149T,153T,157T ; line 25
DB 161T,165T,169T,173T,177T,180T,184T,188T ; line 26
DB 192T,195T,199T,202T,205T,209T,212T,215T ; line 27
DB 218T,221T,223T,226T,229T,231T,234T,236T ; line 28
DB 238T,240T,242T,244T,245T,247T,248T,250T ; line 29
DB 251T,252T,253T,253T,254T,254T,255T,255T ; line 30
DB 255T,255T,255T,254T,254T,253T,253T,252T ; line 31
DB 251T,250T,248T,247T,245T,244T,242T,240T ; line 32
DB 238T,236T,234T,231T,229T,226T,223T,221T ; line 33
DB 218T,215T,212T,209T,205T,202T,199T,195T ; line 34
DB 191T,188T,184T,180T,177T,173T,169T,165T ; line 35
DB 161T,157T,153T,149T,145T,140T,136T,132T ; line 36
DB 128T,124T,120T,116T,111T,107T,103T,099T ; line 37
DB 095T,091T,087T,083T,079T,076T,072T,068T ; line 38
DB 064T,061T,057T,054T,051T,047T,044T,041T ; line 39
DB 038T,035T,033T,030T,027T,025T,022T,020T ; line 40
DB 018T,016T,014T,012T,011T,009T,008T,006T ; line 41
DB 005T,004T,003T,003T,002T,002T,001T,001T ; line 42
DB 001T,001T,001T,002T,002T,003T,003T,004T ; line 43
DB 005T,006T,008T,009T,011T,012T,014T,016T ; line 44
DB 018T,020T,022T,025T,027T,030T,033T,035T ; line 45
DB 038T,041T,044T,047T,051T,054T,057T,061T ; line 46
DB 065T,068T,072T,076T,079T,083T,087T,091T ; line 47
DB 095T,099T,103T,107T,111T,116T,120T,124T ; line 48
;*****REPEAT TABLE*****
DB 128T,132T,136T,140T,145T,149T,153T,157T ; line 25
DB 161T,165T,169T,173T,177T,180T,184T,188T ; line 26
DB 192T,195T,199T,202T,205T,209T,212T,215T ; line 27
DB 218T,221T,223T,226T,229T,231T,234T,236T ; line 28
DB 238T,240T,242T,244T,245T,247T,248T,250T ; line 29
DB 251T,252T,253T,253T,254T,254T,255T,255T ; line 30
DB 255T,255T,255T,254T,254T,253T,253T,252T ; line 31
DB 251T,250T,248T,247T,245T,244T,242T,240T ; line 32
DB 238T,236T,234T,231T,229T,226T,223T,221T ; line 33
DB 218T,215T,212T,209T,205T,202T,199T,195T ; line 34
DB 191T,188T,184T,180T,177T,173T,169T,165T ; line 35
DB 161T,157T,153T,149T,145T,140T,136T,132T ; line 36
DB 128T,124T,120T,116T,111T,107T,103T,099T ; line 37
DB 095T,091T,087T,083T,079T,076T,072T,068T ; line 38
DB 064T,061T,057T,054T,051T,047T,044T,041T ; line 39
DB 038T,035T,033T,030T,027T,025T,022T,020T ; line 40
DB 018T,016T,014T,012T,011T,009T,008T,006T ; line 41
DB 005T,004T,003T,003T,002T,002T,001T,001T ; line 42
DB 001T,001T,001T,002T,002T,003T,003T,004T ; line 43
DB 005T,006T,008T,009T,011T,012T,014T,016T ; line 44
DB 018T,020T,022T,025T,027T,030T,033T,035T ; line 45
DB 038T,041T,044T,047T,051T,054T,057T,061T ; line 46
DB 065T,068T,072T,076T,079T,083T,087T,091T ; line 47
DB 095T,099T,103T,107T,111T,116T,120T,124T ; line 48
org $9000
**************************************************************
* DUMMY_ISR - Dummy Interrupt Service Routine. *
**************************************************************
dummy_isr rti ; interrupt return
Main_Init: mov #$01,CONFIG ;INDEP=0, complementary output COPD=0 (cop enabled)
; ---------------
bclr 5,PCTL ; set PLL activ
lda #$33
sta PPG
bset 5,PCTL
bset 4,PCTL
; ----------------------- set Stack Pointer
ldhx #$02FF
txs
;--------------------------------- clear RAM ------------
clr TEMP
ldhx #RamStart
next_x mov TEMP,X+
cphx #$0300
blo next_x
;---------------------------------------
bset 3,DDRB ; only for test to see interrupt time
bset 6,DDRB ; only for test to see loop time
jsr Init_PWMMC
cli ; Allow interrupts to happen
*************************************************************
**************************************************************
LOOP sta $FFFF ; reset watchdog if cop enabled
brclr 7,LOOPTIMING,LOOP ; Realtime approx. 5 msec
bclr 7,LOOPTIMING
* -----
dec LOOPCOUNTER
bne LoopCountOkay
lda PORTB
and #%01000000
beq set_6
bclr 6,PORTB
bra ok_6
set_6 bset 6,PORTB
ok_6
mov #200T,LOOPCOUNTER
LoopCountOkay
jmp LOOP
**************************************************************
* Init_PWM for 3 phase sine output
**************************************************************
Init_PWMMC ldhx #256T ; Load Counter Modulo Register with 256T
sthx pmodh
mov #0T,DEADTM
ldhx #$8000
sthx PTR_SINUS
ldhx #20T
sthx PVAL1H
ldhx #40T
sthx PVAL3H
ldhx #80T
sthx PVAL5H
mov #0,PCTL2 ; Reload every PWM cycle, fastest PWM frequency
mov #$23,PCTL1 ; interrupt, load parameters, PWM on
bset 1,PCTL1 ; force reload on PWM parameters
mov #%00111111,pwmout
rts
***********************************************************
INT_PWM6 pshh
lda PCTL1
bclr 4,PCTL1
ldhx PTR_SINUS
lda 0,X ; indexed H:X with offset
sta PVAL1L
lda 64T,X
sta PVAL3L
lda 128T,X
sta PVAL5L
bset 1,PCTL1
inc PTR_SINUS+2
bne ptr_ok
lda PTR_SINUS+1
inca
cmp #192T
blo save_a
clra
save_a sta PTR_SINUS+1
ptr_ok
****************************************
dec TIMER
bne Timer_Okay
mov #$FF,LOOPTIMING
mov #$24,TIMER
Timer_Okay
*****************************************
lda PORTB
eor #%00001000
sta PORTB
pulh
rti
**************************************************************
* Vectors - Timer Interrupt Service Routine. *
**************************************************************
org VectorStart
dw dummy_isr ; SCI Transmit Vector
dw dummy_isr ; SCI Receive Vector
dw dummy_isr ; SCI Error Vector
dw dummy_isr ; SPI Transmit Vector
dw dummy_isr ; SPI Receive Vector
dw dummy_isr ; ADC Conversion Complete
dw dummy_isr ; TIM2 Overflow Vector
dw dummy_isr ; TIM2 Channel 1 Vector
dw dummy_isr ; TIM2 Channel 0 Vector
dw dummy_isr ; TIM1 Overflow Vector
dw dummy_isr ; TIM1 Channel 3 Vector PE7
dw dummy_isr ; TIM1 Channel 2 Vector
dw dummy_isr ; TIM1 Channel 1 Vector
dw dummy_isr ; TIM1 Channel 0 Vector
dw INT_PWM6 ; PWMMC Vector
dw dummy_isr ; Fault 4 Vector
dw dummy_isr ; Fault 3 Vector
dw dummy_isr ; Fault 2 Vector
dw dummy_isr ; Fault 1 Vector
dw dummy_isr ; PLL Vector
dw dummy_isr ; ~IRQ1 Vector
dw dummy_isr ; SWI Vector
dw main_init ; Reset Vector