Ok, a little update.
I've tested the program on the real PIC with an oscilloscope. All of the output signals are correct, but the sine cycle is very slow (about 4 seconds to make a complete sine period, so f=1/4=0,25Hz).
The PWM frequency seems correct (3,245kHz).
I've defined correctly the configuration fuses (or bits), with "HS oscillator" setting, because I'm using a 40MHz quartz oscillator connected to OSC1/OSC2 pins with 22pF ceramic capacitors.
The code (note I'm not using the FOR... NEXT loop in this case, like the upper programs, it's a lot faster if I use the FOR... NEXT loop, but I don't know why) :
Code:
'PIC initialization
DEFINE OSC 40
DEFINE LCD_EREG PORTD
DEFINE LCD_DREG PORTD
DEFINE LCD_EBIT 0
DEFINE LCD_RSBIT 1
'DT interrupt system include
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
'Port registers configuration
PORTB=%0 ' Clear ports
TRISB=%11000000 ' PWM 0,1,2,3,4,5 outputs
'PCPWM registers configuration
DTCON=%110 ' Deadtime (600ns)
PTCON0=%100 ' 1:1 postscale, Fosc/4 1:1 prescale, free running mode
PTCON1=%10000000 ' PWM time base is ON, counts up, 19.45kHz/4
PTPERL=%0 ' PWM low-side
PTPERH=%1 ' PWM high-side
'PWM registers configuration
PWMCON0=%1000000 'PWM 0,1,2,3,4,5 set in pair mode
PWMCON1=%1 'PWM timer sync configuration
'Interrupt processor
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag
INT_Handler TMR1_INT, _pwmint, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'Timer configuration
T1CON=%10000001 ; Prescaler = 1:8, TMR1ON, 16-bit counter
@ INT_ENABLE TMR1_INT ; Enable Timer 1 interrupts
'PWM calculation variables
uduty VAR WORD 'U phase duty
vduty VAR WORD 'V phase duty
wduty VAR WORD 'W phase duty
dutydiv var WORD 'Frequency diviser
dutymul VAR WORD 'Duty multiplier
t VAR byte 'Incremental value
'Variables definition
dutydiv=0 'Range : 0-65535
dutymul=65535 'Range : 0-65535 (for exemple, 32767=0.5)
t=%0 'T initial value
'Main program loop
mainlp:
HIGH PORTA.0
pause 100
LOW PORTA.0
pause 100
goto mainlp
'PWM calculation and update interrupt
pwmint:
'Frequency diviser
pauseus dutydiv
'PWM U, V, W phases calculation
uduty=(((sin(t)+%01111111)*%100)**dutymul)+%100
vduty=(((sin(t+%01010101)+%01111111)*%100)**dutymul)+%100
wduty=(((sin(t+%10101010)+%01111111)*%100)**dutymul)+%100
'PWM U phase update
PDC0L=uduty.LOWbyte
PDC0H=uduty.HIGHByte
'PWM V phase update
PDC1L=vduty.LOWbyte
PDC1H=vduty.HIGHByte
'PWM W phase update
PDC2L=wduty.LOWbyte
PDC2H=wduty.HIGHByte
'T variable verification and incrementation
if t<%11111111 then
t=t+%1
else
t=%0
endif
@ INT_RETURN
I think it's a TIMER problem (TMR1 is at 32kHz, isn't it?)
Bookmarks