Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 20577

BASCOM-AVR : PID Closed Loop Control of PURE SINE WAVE DC to AC inverter : REPLY

$
0
0
dear thank you very much for your intrest and reply to my post it looks like that you have idea how to implement control of inverter and for your understanding i attached circuit diagram and her is my code [code:1:f77cd51fb9] '========================= SYSTEM INT ====================== $regfile = "xm32a4udef.dat" '$regfile = "xm32d4def.dat" $crystal = 32000000 $hwstack = 100 $swstack = 200 $framesize = 200 Config Osc = Enabled , 32mhzosc = Enabled ' enable 2 MHz and 32 MHz interal oscillators Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1 ' use 32 MHz Config Submode = New $include "a4uadc.bas" '$include "LED_DISPLAY.BAS" '$sim '======================== CONSTANT'S ============================ Const Tsam = 128 Const Primry_volt = 7.43 * 30.63 Const Period = 200 'Const Cal_pwm = Primry_volt * Period Const Cal_pwm = 45514 'Const Bat_start = baettery volt *pervolt constant Const Bat_start = 337 Const Bat_trip = 306 '======================== ALIAS'S ============================== Power_sw Alias Pind.4 '========================I/O CON FIG ========================== 'Config Portb = Output Config Portc = Output Config Portd.1 = Output Config Portd.0 = Output Config Portc.5 = Output Config Portc.7 = Output Config Portc.6 = Output 'Config Xpin = Portb.3 , Invertio = Enabled , Slewrate = Enabled , Outpull = Wiredand , Sense = Both Config Xpin = Portd.1 , Invertio = Disabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portd.0 , Invertio = Disabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portc.5 , Invertio = Disabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portc.7 , Invertio = Disabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portc.6 , Invertio = Disabled , Slewrate = Enabled , Outpull = Totem , Sense = Both 'lcd pins Config Xpin = Portd.7 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Porte.0 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Porte.1 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Porte.2 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portd.6 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portd.5 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both 'HB DRIVE PINS Config Xpin = Portc.0 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portc.1 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portc.2 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both Config Xpin = Portc.3 , Invertio = Enabled , Slewrate = Enabled , Outpull = Totem , Sense = Both 'HERE INPUT SENS SETTING Config Xpin = Portd.2 , Outpull = Pullup , Sense = Falling 'enable Pull up and Config Xpin = Portd.4 , Outpull = Pullup , Sense = Falling 'enable Pull up and Config Xpin = Portb.3 , Outpull = Pullup , Sense = Falling 'enable Pull up and Config Portr = Output Config Porte = Output '========================== PHRIPAREL INT =========================== Adc_cfg Adc_diff Config Tcc0 = Pwm_topbot , Prescale = 4 , Comparea = Enabled , Compareb = Enabled , Comparec = Enabled , Compared = Enabled Tcc0_per = Period ' period register 'Tcc0_ccabuf = 50 'compare A match value 'Tcc0_ccbbuf = 50 'compare B match value 'Tcc0_cccbuf = 50 'compare C match value 'Tcc0_ccdbuf = 50 'GOSUB CONFIG_ADC Config Tcc1 = Normal , Prescale = 4 Tcc1_per = 1600 'for testing 'Tcc1_per = 3200 Tcc1_ccabuf = 1 Config Lcdpin = Pin , Db4 = Portd.7 , Db5 = Porte.0 , Db6 = Porte.1 , Db7 = Porte.2 , E = Portd.6 , Rs = Portd.5 Config Lcd = 16 * 4 Initlcd Cls Lcd " hello" Wait 2 '========================INT CONFIG ============================ On Tcc1_cca Trigadc Enable Tcc1_cca , Hi 'Adca_ch0_intctrl = &B00000011 ' TEMP CHANGE Pmic_ctrl = &B00000111 '======================== FLAGS VERIABLES ========================= Dim Upson As Bit , Doom As Bit , Backupon As Bit Dim Cycle_start As Bit , Output_doom As Bit Dim Ovd_warn As Bit , Ovd_shutdown As Bit , Batlow_shut As Bit , Batlow_warn As Bit , Startup As Bit Dim Over_heat As Bit '======================== VERIABLE============================== Dim Mux As Byte Dim W As Integer , Wold As Long , Cnt As Byte 'Adca_ch0_muxctrl = &B00001000 Dim Sine_counter As Byte , Sine_table As Word , Pwm_update As Word Dim Pwm_out As Byte At Pwm_update + 1 Overlay Dim Outload As Integer , Outputrms As Integer , Outcurrent As Integer Dim Output_prv As Integer , Output_pk As Integer Dim Batvolt As Integer , Batact As Word , Batlcd As Single , Outputac As Integer Dim Pwm_max As Word Dim Batdispl As Word , Battery_sigma As Word , Battery_count As Byte Dim Bvstr As String * 8 Dim Output_load As Long , Load_display As Long , Load_compare As Byte Dim Output_volt As Long , Output_volt_display As Long '======================== MAIN LOOP ============================= 'Enable Interrupts SEI Do 'HERE CALCULATE TO DISPLAY BATTER VOLT Batlcd = Batact / 30.63 Bvstr = Fusing(batlcd , "#.##") If Power_sw = 0 Then Backupon = 1 'TURN ON INVERTOR Else 'TURN OFF INVERTOR Backupon = 0 End If 'LCD UPDATE DELAY Waitms 500 Loop End 'end program '=======================ISR FUNCTION'S ============================ '///////////////////////////// timer c1 intreupt for analog chanel readings ////////////////////////// Trigadc: Bv_ch_slect ' mux slection function for battery volt reading Adc_run 'start adc conversion Get_analog 'read chanel register and store values in veriable ad_result Batvolt = Ad_result 'move result to batvolt veriable for battery level detect Oc_ch_slect ' mux slection function for ct reading Adc_run 'start adc conversion Get_analog 'read chanel register and store values in veriable ad_result Outcurrent = Ad_result Ov_ch_slect ' mux slection function for output volt reading Adc_run 'start adc conversion Get_analog Outputac = Ad_result Shift Batvolt , Right , 2 Shift Outcurrent , Right , 2 , Signed Shift Outputac , Right , 4 , Signed 'here calculate avrge battery volts because adc result is not good so avrging will give the good result Battery_sigma = Batvolt + Battery_sigma If Battery_count = 16 Then Battery_count = 1 Batdispl = Battery_sigma Shift Batdispl , Right , 5 'get avrge battery volt reading Battery_sigma = 0 Else Incr Battery_count End If Batact = Batdispl 'update battery reading 'HERE IF OUT PUT VOLT VALUE IS IN NEGITIVE THEN CONVERT IT IN POSITIVE If Outputac < 0 Then : Decr Outputac : Toggle Outputac : End If 'HERE IF OUT PUT CURRENT VALUE IS IN NEGITIVE THEN CONVERT IT IN POSITIVE If Outcurrent < 0 Then : Decr Outcurrent : Toggle Outcurrent : End If '---------------------- HERE SINE WAVE INVERTOR CONTROL LOOP 'Backupon = 1 'TURN ON INVERTOR If Backupon = 1 Then If Sine_counter = 49 Then : Sine_counter = 0 : Doom = Doom Xor 1 : Else : Incr Sine_counter : End If Pwm_max = Cal_pwm / Batact Sine_table = Lookup(sine_counter , Sine_table255) Pwm_update = Sine_table * Pwm_max If Doom = 1 Then Tcc0_ccbbuf = 0 'RIGHT HIGH HB OUT Tcc0_cccbuf = 0 'LEFT LOW HB OUT Tcc0_ccdbuf = Pwm_out + 1 'LEFT HIGH HB OUT Tcc0_ccabuf = Pwm_out 'RIGHT LOW HB OUT Else Tcc0_ccabuf = 0 'RIGHT LOW HB OUT Tcc0_ccdbuf = 0 'LEFT HIGH HB OUT Tcc0_ccbbuf = Pwm_out + 1 'RIGHT HIGH HB OUT Tcc0_cccbuf = Pwm_out 'LEFT LOW HB OUT End If End If 'HERE AVRGE CURRENT AND AVRGE OUTPUT VOLT DETECTION 'SO THERE WOULD BE NO NEED TO ADD ANY AVRGE CAP ADDITION 'WHEN INVERTOR ON THEN DISPLAY INVERTOR VOLT AND LOAD If Sine_counter = 0 And Doom = 1 Then Output_load = Output_load / 100 Load_display = Output_load Output_load = 0 Output_volt = Output_volt / 100 Output_volt_display = Output_volt Output_volt = 0 Else Output_volt = Output_volt + Outputac Output_load = Output_load + Outcurrent End If Return Sine_table255: Data 0 , 16 , 33 , 49 , 65 , 80 , 96 , 111 , 125 , 139 , 153 , 165 , 177 , 189 , 199 , 209 , 218 , 226 , 233 , 239 , 244 , 249 , 252 , 254 , 255 , 255 , 254 , 252 , 249 , 244 , 239 , 233 , 226 , 218 , 209 , 199 , 189 , 177 , 165 , 153 , 139 , 125 , 111 , 96 , 80 , 65 , 49 , 33 , 16 , 0 [/code:1:f77cd51fb9] now you can see that tried using transformer turn ratio vs battery volt and updated pwm but it didnt worked as i want yes at the starting i want to implement only volt control loop ( not the current control loop ) can you plz guide me that what would be code for p term control type thats what i have no idea about it how to add these lines for p type control waiting for your and all others experienced members reply

Viewing all articles
Browse latest Browse all 20577

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>