News:

;) This forum is the property of Proton software developers

Main Menu

PWM feedback and variable frequency

Started by Abdullah, Aug 31, 2025, 06:04 PM

Previous topic - Next topic

Abdullah

#20
Quote from: Pepe on Sep 04, 2025, 09:08 PMdemo proteus fixed
Hello Sir please share BAS file

Pepe

#21
demo proteus with control (proportional+integral)

Abdullah

#22
Quote from: Pepe on Sep 05, 2025, 07:31 PMdemo proteus with control (proportional+integral)
sir BAS file not available in this zip demo proteus with control (proportional+integral)

Pepe

#23
source in post #22


Abdullah


 If piterm < I_MIN Then piterm = I_MIn
VALUE WILL OVERFLOW A WORD SIZE VARIABLES

RGV250

Hi,
It is only a warning, to get rid of it change Dim piterm As SWord to Dim piterm As SDword

Bob

Pepe

I think the warning is wrong, there is no need to change to sdword, sword is from 32767 to -32768 and I_min is -50

Abdullah

Quote from: Pepe on Sep 06, 2025, 12:09 PMI think the warning is wrong, there is no need to change to sdword, sword is from 32767 to -32768 and I_min is -50
Ok I can change it
Sdword no error
Sword asked about overflow

RGV250

QuoteI think the warning is wrong, there is no need to change to sdword, sword is from 32767 to -32768 and I_min is -50
Probably, the strange thing is if you Dim I_Min as SByte rather than symbol you do not get error when using SWord

Bob

Pepe

#29
Don't change to sdword because all arithmetic operations become slower and the program takes up more memory; with sword it works correctly.That's why I think the warning is wrong.

top204

This is an anomaly, and has been corrected for the next update.

The warning is because the negative constant value is held as an alias. i.e. "I_Min", so the parser did not see the sign character preceding the value, and saw the negative of a 32-bit constant instead, which is a very large value. However, the compiler 'And's the value for a 16-bit loading, so it causes no assembler errors, or mathematic errors.

The warning can be removed with the declare:

Declare Warnings = Off

Pepe.... The "Declare Reminders" and "Declare Hints", serve the same purpose, and I added the "Hints" text for the Declare quite a few years ago, because the messages given by the compiler state "Hint", and I left the "Reminders" text for backward compatability. See page 420 of the PDF manual.

Abdullah

Quote from: top204 on Sep 06, 2025, 01:59 PMThis is an anomaly, and has been corrected for the next update.

The warning is because the negative constant value is held as an alias. i.e. "I_Min", so the parser did not see the sign character preceding the value, and saw the negative of a 32-bit constant instead, which is a very large value. However, the compiler 'And's the value for a 16-bit loading, so it causes no assembler errors, or mathematic errors.

The warning can be removed with the declare:

Declare Warnings = Off

Pepe.... The "Declare Reminders" and "Declare Hints", serve the same purpose, and I added the "Hints" text for the Declare quite a few years ago, because the messages given by the compiler state "Hint", and I left the "Reminders" text for backward compatability. See page 420 of the PDF manual.

Thanks Sir problem solved 

Pepe

#32
look #37

Abdullah

Quote from: Pepe on Sep 06, 2025, 03:40 PMdemo proteus with variations in direct input voltage
sir this demo frequency may be not variable 100 to 250 volts frequency is 7KHZ why

Pepe


Abdullah

#35
Quote from: Pepe on Sep 06, 2025, 04:11 PMIt is variable from 150v
sir I check it 100 to 300 volts in proteus frequency is same 7KHZ
if input volts is 350 then frequency is approximately 3khz

Pepe

#36
demo fixed

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 16F684

Config FOSC_INTOSCIO, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_ON, CPD_OFF, BOREN_OFF, IESO_OFF, FCMEN_OFF

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
Declare Xtal = 8
Declare Optimiser_Level = 3

Declare Watchdog off
Declare Warnings off
Declare Dead_Code_Remove = 1        ' Remove dead code
Declare Reminders Off

Declare Hints Off
Declare Create_Coff On

Declare Adin_Res 8
Declare Adin_Tad frc
Declare Adin_Stime 50
Declare CCP1_Pin = PORTC.5

 
  TRISA = $3f        '1- input, 0-output
  TRISC = $F
  ANSEL = 3          ' Configure other pins as digital
 


Symbol set_value 177' 350v
Symbol top 68
Symbol bottom 255

Symbol I_max = 50
Symbol I_min = -50
Symbol ki = 0.1

Dim ad_value As Byte
Dim new_value As Word = 0
Dim old_value As Byte
Dim control As Word
Dim mid_value As Word
Dim in_value As Byte
Dim iterm As Float
Dim IntegralCounter As Word
Dim frec As Word = 20000
Dim Errores As SWord
Dim piterm As SWord
Dim temp As Byte

Do
  ad_value = ADIn 0
 
  If old_value <> ad_value Then
                                old_value  = ad_value
                                 
                                sel_frec
  EndIf
 
  pid                                                 

Loop

Sub sel_frec

    in_value = ADIn 1
     
    temp = in_value - 50
     
    Select Case in_value
        Case < 50
        frec = 20000
        mid_value = top
   Case <  set_value +1           
        frec = 7000 + temp * 262
        mid_value = 157 + temp * 88 / 127
   Case Else
        frec = 40000
        mid_value = bottom
    EndSelect
EndSub

Sub PID
 
Errores = ad_value - set_value

If Abs(Errores) < 2 Then
                         Inc IntegralCounter
                         
                         iterm = iterm + (ki * Errores)
                         
                         If IntegralCounter > 9 Then
                           
                                                  If iterm >30000 Then
                                                                       iterm = 30000
                                                  ElseIf iterm < -30000 Then
                                                                             iterm = -30000
                                                  EndIf
                                                                             
                                                  piterm = iterm
                                                 
                                                  If piterm > I_max Then
                                                                         piterm = I_max
                                                  ElseIf piterm < I_MIN Then
                                                                             piterm = I_MIn
                                                  EndIf                           
                                                 
                                                  IntegralCounter = 0
                         EndIf
                         
                         If Errores < 0 Then
                                             new_value = -Errores
                                           
                                             If mid_value - new_value < 0 Then                     
                                                                               control = top
                                                                          Else
                                                                               control = mid_value - new_value
                                             EndIf                             
                         ElseIf Errores > 0 Then
                                                 
                                                 new_value = Errores 
                                                 
                                                 control = mid_value + new_value                   
                         EndIf
                         
                         If Errores <> 0 Then control = control + piterm
                         
                         If control > bottom Then
                                                  control = bottom
                         ElseIf control < top Then
                                                  control = top
                         EndIf   
                     Else
                         If Errores < 0 Then
                                             control = top
                                        Else
                                             control = bottom
                         EndIf                         
 EndIf

HPWM 1,control,frec

EndSub