Hello all,
I am currently working on a term project, it is a single to three phase converter, I am focusing on the control stage of the project and lets just say I am slightly overwhelmed.
What I need to achieve in this stage is a three phase sine PWM switching signal, I have found an open source code on the internet that uses the pic16f84a MCU to generate this switching signal. I have very limited experience with MCU programming, I took one introductory class so I know some basics.
If I purchase the following pic16f84a: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F84A-20/P-ND I assume I will need a development board or some way of interfacing to my compiler. If someone would be so kind and recommend me a good development board or what not for this particular application I would be grateful.
Unfortunately this whole process needs to be very turn-key as my expertise lies more in power engineering, embedded systems is beyond me.
Here is the code I hope to use with this MCU..
I am currently working on a term project, it is a single to three phase converter, I am focusing on the control stage of the project and lets just say I am slightly overwhelmed.
What I need to achieve in this stage is a three phase sine PWM switching signal, I have found an open source code on the internet that uses the pic16f84a MCU to generate this switching signal. I have very limited experience with MCU programming, I took one introductory class so I know some basics.
If I purchase the following pic16f84a: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=PIC16F84A-20/P-ND I assume I will need a development board or some way of interfacing to my compiler. If someone would be so kind and recommend me a good development board or what not for this particular application I would be grateful.
Unfortunately this whole process needs to be very turn-key as my expertise lies more in power engineering, embedded systems is beyond me.
Here is the code I hope to use with this MCU..
Rich (BB code):
;==============================================================================
; P r o c e s s o r
;==============================================================================
list p=16f84a
include p16f84a.inc
;==============================================================================
; C o n s t a n t s
;==============================================================================
phaseA equ 2 ;RB2
phaseB equ 1 ;RB1
phaseC equ 0 ;RB0
outPort equ PORTB
;==============================================================================
; D a t a M e m o r y
;==============================================================================
cblock 0x0C
outPortBuffer
valueA
valueB
valueC
timeA
timeB
timeC
stateVar
endc
;==============================================================================
; M A C R O S
;==============================================================================
BANK0 macro
bcf STATUS, RP0
endm
BANK1 macro
bsf STATUS, RP0
endm
;==============================================================================
; R e s e t V e c t o r
;==============================================================================
org 0x0000
call Initialize
goto Main
;==============================================================================
; I n t e r r u p t V e c t o r
;==============================================================================
org 0x0004 ;Do not have to save context because of implementation
;Interrupt code
clrf outPortBuffer
incf timeA, f ;Advance time
movf timeA ,w
addlw D'21'
movwf timeB
addlw D'22'
movwf timeC
call PWM ;Update
btfsc stateVar, 0 ;Phase rotation is rounded depending upon state
goto StateB
btfsc stateVar, 1
goto StateC
StateA
bsf stateVar, 0
goto EndState
StateB
incf timeB, f
bsf stateVar, 1
goto EndState
StateC
incf timeB, f
incf timeC, f
clrf stateVar
EndState
call PWM ;Update
movlw D'65' ;Ensure between 0 and 64
subwf timeA, f
btfss STATUS, C
addwf timeA, f
subwf timeB, f
btfss STATUS, C
addwf timeB, f
subwf timeC, f
btfss STATUS, C
addwf timeC, f
call PWM ;Update
movf timeA, w ;Get sinewave value, phase A
call SineWave
movwf valueA
movf timeB, w ;Get sinewave value, phase B
call SineWave
movwf valueB
movf timeC, w ;Get sinewave value, phase C
call SineWave
movwf valueC
bcf INTCON, T0IF ;Reset interrupt flag
retfie
;==============================================================================
; M A I N
;==============================================================================
Main
bcf INTCON, GIE ;Disable interrupts
call PWM
bsf INTCON, GIE ;Enable interrupts
goto Main
;------------------------------------------------------------------------------
Initialize
;Set up output port
BANK1
movlw ~(1 << phaseA | 1 << phaseB | 1 << phaseC)
movwf outPort
;Set up TIMER0
movlw B'10001000'
movwf OPTION_REG
BANK0
;Set up for interrupt routine
clrf stateVar
clrf timeA
;Set up values
movlw D'127'
movwf valueA
movlw D'241'
movwf valueB
movlw D'19'
movwf valueC
;Set up timer interrupt
movlw B'10100000'
movwf INTCON
return
;------------------------------------------------------------------------------
PWM
movf TMR0, w ;Get time
subwf valueA, f ;Calculate for Phase A
btfss STATUS, C
bsf outPortBuffer, phaseA
addwf valueA, f ;Restore ValueA
subwf valueB, f ;Calculate for Phase B
btfss STATUS, C
bsf outPortBuffer, phaseB
addwf valueB, f ;Restore ValueB
subwf valueC, w ;Calculate for Phase C
btfss STATUS, C
bsf outPortBuffer, phaseC
movf outPortBuffer, w
movwf outPort
return
;------------------------------------------------------------------------------
SineWave
if (high TableStart)
movlw high TableStart
movwf PCLATH
endif
if (high TableStart) == (high TableEnd)
addwf PCL, f
else
messg "Table crosses page boundary"
addwf PCL, w
btfss STATUS, C
incf PCLATH, f
movwf PCL
endif
TableStart
retlw D'127'
retlw D'139'
retlw D'151'
retlw D'163'
retlw D'175'
retlw D'186'
retlw D'197'
retlw D'207'
retlw D'216'
retlw D'224'
retlw D'232'
retlw D'238'
retlw D'243'
retlw D'248'
retlw D'251'
retlw D'253'
retlw D'254'
retlw D'254'
retlw D'252'
retlw D'250'
retlw D'246'
retlw D'241'
retlw D'235'
retlw D'228'
retlw D'220'
retlw D'211'
retlw D'202'
retlw D'191'
retlw D'181'
retlw D'169'
retlw D'157'
retlw D'145'
retlw D'133'
retlw D'121'
retlw D'109'
retlw D'97'
retlw D'85'
retlw D'73'
retlw D'63'
retlw D'52'
retlw D'43'
retlw D'34'
retlw D'26'
retlw D'19'
retlw D'13'
retlw D'8'
retlw D'4'
retlw D'2'
retlw D'0'
retlw D'0'
retlw D'1'
retlw D'3'
retlw D'6'
retlw D'11'
retlw D'16'
retlw D'22'
retlw D'30'
retlw D'38'
retlw D'47'
retlw D'57'
retlw D'68'
retlw D'79'
retlw D'91'
retlw D'103'
TableEnd
retlw D'115'
;==============================================================================
; I N C L U D E S
;==============================================================================
end