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

Hello everyone I need A program for HPWM 7khz to 40khz if input volt is > 100
then HPWM = 7KHZ else 20khz if input volt is > 150 then HPWM = 10KHZ else 20khz
if input volt is > 200 then HPWM = 15KHZ else 20khz if input volt is > 250 then HPWM = 20KHZ else 20khz if input volt is > 300 then HPWM = 40KHZ else 20khz and output volt control to the duty cycle as A feedback using 16f684

Pepe

I think you should do it and in any case ask for help if something doesn't work. Without effort and research, you can't learn new things. It's very easy to ask and have others solve your problems.

Stephen Moss

I agree with @Pepe
Are you sure that what (from your question) your want to do is the correct approach? Do you even understand PWM?

I ask because ususally the PWM frequcny is fixed and you adjust the cycle to change the amount of energy/voltage output, if you change the frequency then the duty factor changes as well to get the same energy out (50% modulation depth at 10Khz is not the same enery as 50% at 20Khz), that is a lot of refactoring.

Also, it looks like you fallback postion which I presum is for < 100V is 20KHz, and you say > 250V is also 20KHz, perhaps there is a reason for it but it does not seem logical to use the same frequency for both. 

Abdullah

Yes Sir but I don't know how can feedback work and how can variable frequency can work and how l can create variable frequency in difference state because I don't know about that I need a demo to learn because I don't have a teacher to teach me about positron compiler I am only a new student you all are my teachers I have a small idea how to make a pwm but I don't know what is the command of variable frequency and feedback to control out put volt sorry for disturbing

Abdullah

Quote from: Stephen Moss on Aug 31, 2025, 07:53 PMI agree with @Pepe
Are you sure that what (from your question) your want to do is the correct approach? Do you even understand PWM?

I ask because ususally the PWM frequcny is fixed and you adjust the cycle to change the amount of energy/voltage output, if you change the frequency then the duty factor changes as well to get the same energy out (50% modulation depth at 10Khz is not the same enery as 50% at 20Khz), that is a lot of refactoring.

Also, it looks like you fallback postion which I presum is for < 100V is 20KHz, and you say > 250V is also 20KHz, perhaps there is a reason for it but it does not seem logical to use the same frequency for both. 
Yes sir this is idea for boost converter using in Soler inverter input 100V to 400V and output 230V AC. booster good work with to Soler panels in 7khz and good work in 20khz in 4 panels

Abdullah

Quote from: Abdullah on Aug 31, 2025, 08:15 PM
Quote from: Stephen Moss on Aug 31, 2025, 07:53 PMI agree with @Pepe
Are you sure that what (from your question) your want to do is the correct approach? Do you even understand PWM?

I ask because ususally the PWM frequcny is fixed and you adjust the cycle to change the amount of energy/voltage output, if you change the frequency then the duty factor changes as well to get the same energy out (50% modulation depth at 10Khz is not the same enery as 50% at 20Khz), that is a lot of refactoring.

Also, it looks like you fallback postion which I presum is for < 100V is 20KHz, and you say > 250V is also 20KHz, perhaps there is a reason for it but it does not seem logical to use the same frequency for both. 
Yes sir this is idea for boost converter using in Soler inverter input 100V to 400V and output 230V AC. booster good work with to Soler panels in 7khz and good work in 20khz in 4 panels
I have a booster and I check it that's work in 7khz to 40khz with defrance input volt

charliecoutas

Surely solar panels produce DC? Is the frequency you talk about that of a DC to AC converter? The frequencies seem a bit low but it seems possible? So as the DC input from the panels change, the DC to AC converter also changes frequency? Then another converter changes it to AC mains frequency? Just a few thoughts....

Charlie

Abdullah

Quote from: charliecoutas on Sep 01, 2025, 07:36 AMSurely solar panels produce DC? Is the frequency you talk about that of a DC to AC converter? The frequencies seem a bit low but it seems possible? So as the DC input from the panels change, the DC to AC converter also changes frequency? Then another converter changes it to AC mains frequency? Just a few thoughts....

Charlie
Yes sir I'm use A boost converter the convert DC voltage 100 to 300 into 350v DC voltage and A use DC to AC converter H brigh AC 230 volt AC 50hz
So I need a demo code they work 100 to 300v DC of Soler panels 2 panels to 6 panels boost converter maintain DC voltage and still output 350v DC

Abdullah

Sorry for All teachers because my poor English language I speak only Urdu

Fanie

Making mains power off solar is not that simple.  There are a lot of factors to keep in check, the frequency, mains voltage regulation, the output sine wave has to be monitored and switched all in check with a possibly changing/varying DC input voltage (ie clouds etc) as well as monitoring the current supplied by the inverter in case of shorts and over current situations.
Unless you plan to make a very crude and basic inverter (for what ?) the 16F684 is not going to make it.

Abdullah

#10
Quote from: Fanie on Sep 01, 2025, 10:15 AMMaking mains power off solar is not that simple.  There are a lot of factors to keep in check, the frequency, mains voltage regulation, the output sine wave has to be monitored and switched all in check with a possibly changing/varying DC input voltage (ie clouds etc) as well as monitoring the current supplied by the inverter in case of shorts and over current situations.
Unless you plan to make a very crude and basic inverter (for what ?) the 16F684 is not going to make it.
yes your write sir but i need only boost converter code to control output volts fixed 350 and input volts is 100 to 300.I have DC to AC program for 50 hz
I am using 3 ICs first for LCD to show soler voltage input and output voltage AC ,2nd IC for 50 hz for H brigh and last IC for booster

Stephen Moss

Quote from: Abdullah on Aug 31, 2025, 08:15 PMYes sir this is idea for boost converter using in Soler inverter input 100V to 400V and output 230V AC. booster good work with to Soler panels in 7khz and good work in 20khz in 4 panels

I am sure you want to jump straight in to a project that means something to you, however perhaps this is too big a project for you to take on at this time.
You may want to slow down, read the Position manual and try a few simple programs first to learn the basic of coding in Positron and setting device configuration fuses, I/O (TRIS) resigters and read the device data sheet to identify the configuration fuse setting you need to make the PIC work as you want it to, how basic I/O ports and any Peripheral register you may need to use such as Capture and Compare Module (CCP peripherial is generally used for PWM) works and need to be configured.

If you had spent some time reading the Positron manual instead of potentially annoying people with constant requests for code you would have seen on page 149 of the Positron 8 manual the HMPW command and instructions on how to use it. It is should be very simple to use and would be a good place to start, enter the basic code provided, when you see the output that produces try modifying the parameter to learn what effect they have.
You may be able to the effects as voltage changes on a multi-meter but you really need to monitor it with an Oscilloscpe, if you do not have access to one, you could monitor it with a cheap USB logic analyser, but if you have nothing to monitor the output with there is little point in proceeding as how would you know if the output from the PIC is the output you want. 

However, you should still also read the device datasheet sections on the Capture and Compare modual to see how to use it for producing PWM output as the HPWM command may not work with the device you are using (Microchip changing register names/bit functions), in which case look at the examples provided with Positron in the samples folder, there is...

HPWM.bas - shows you how to configure the CCP module manually.
You will have to learn how to do this if the HPWM command either does not work for your device or cannot produce the output frequencies you want. Changing frequency and modulation depth should just a matter of calculating the required values to write to the applicable registers, which in Positon is simply Register Name = Value (in you preferred format, i.e, %10000000 in Binary, or 128 in Decimal or $80 on Hexadecimal)

In the Proteus sub folder there is PWM_Wgen.bas

In the New Sample sub folder there are a couple of PWM related files, but I think they will be less usefull to you as they appear to be for software PWM, and hardware PWM would probably be better.

You should look at the code for the examples supplied with the complier and try to uderstand how it works (referring to the device datasheet and Positron manual as necessary for more information about the comands/registers used), as only when you understand how they work you can then adapt the example code for your requirements.

Abdullah

Quote from: Stephen Moss on Sep 01, 2025, 12:34 PM
Quote from: Abdullah on Aug 31, 2025, 08:15 PMYes sir this is idea for boost converter using in Soler inverter input 100V to 400V and output 230V AC. booster good work with to Soler panels in 7khz and good work in 20khz in 4 panels

I am sure you want to jump straight in to a project that means something to you, however perhaps this is too big a project for you to take on at this time.
You may want to slow down, read the Position manual and try a few simple programs first to learn the basic of coding in Positron and setting device configuration fuses, I/O (TRIS) resigters and read the device data sheet to identify the configuration fuse setting you need to make the PIC work as you want it to, how basic I/O ports and any Peripheral register you may need to use such as Capture and Compare Module (CCP peripherial is generally used for PWM) works and need to be configured.

If you had spent some time reading the Positron manual instead of potentially annoying people with constant requests for code you would have seen on page 149 of the Positron 8 manual the HMPW command and instructions on how to use it. It is should be very simple to use and would be a good place to start, enter the basic code provided, when you see the output that produces try modifying the parameter to learn what effect they have.
You may be able to the effects as voltage changes on a multi-meter but you really need to monitor it with an Oscilloscpe, if you do not have access to one, you could monitor it with a cheap USB logic analyser, but if you have nothing to monitor the output with there is little point in proceeding as how would you know if the output from the PIC is the output you want. 

However, you should still also read the device datasheet sections on the Capture and Compare modual to see how to use it for producing PWM output as the HPWM command may not work with the device you are using (Microchip changing register names/bit functions), in which case look at the examples provided with Positron in the samples folder, there is...

HPWM.bas - shows you how to configure the CCP module manually.
You will have to learn how to do this if the HPWM command either does not work for your device or cannot produce the output frequencies you want. Changing frequency and modulation depth should just a matter of calculating the required values to write to the applicable registers, which in Positon is simply Register Name = Value (in you preferred format, i.e, %10000000 in Binary, or 128 in Decimal or $80 on Hexadecimal)

In the Proteus sub folder there is PWM_Wgen.bas

In the New Sample sub folder there are a couple of PWM related files, but I think they will be less usefull to you as they appear to be for software PWM, and hardware PWM would probably be better.

You should look at the code for the examples supplied with the complier and try to uderstand how it works (referring to the device datasheet and Positron manual as necessary for more information about the comands/registers used), as only when you understand how they work you can then adapt the example code for your requirements.
Yes, you are right. I have done a little work on PWM. I have an oscilloscope to check. I have input and output sources. This is a small project. I have a source to do AC. I can convert DC to AC. I have been working on it for two years. I just want to make a program to run the boost.

Pepe

demo proteus Buck-Boost Converter with 16f684

Abdullah

#14
Quote from: Pepe on Sep 02, 2025, 11:23 PMdemo proteus Buck-Boost Converter with 16f684
Sir how to add variable frequency in this code
and only boost not buck and this volts is maximum 74v and i need 350

ken_k

Quote from: Pepe on Sep 02, 2025, 11:23 PMdemo proteus Buck-Boost Converter with 16f684
Hi
I do not have a copy of proteus. Is it possible to post the schematic of the Buck-Boost converter?
Quote from: Abdullah on Sep 03, 2025, 01:43 PMonly boost not buck and this volts is maximum 74v and i need 350
What power level are you designing for?
What efficiency are you designing for?
Why do you need multi frequency? PWM at a single frequency should work OK.
Do you even need a microcontroller for a simple step-up boost converter from 74VDC to 350VDC?
For efficiency you may need a multi phase step-up boost converter, if so a dsPIC may be a good choice.