Pure Sine Wave Inverter

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Pure Sine Wave Inverter

Post by mnf »

Okay - so a first attempt which seems to work okay..

Unfortunately the C is written in 'write only' or 'write once' style (no comments) - so I haven't tried to decipher the register writes. This is left as an exercise. It would possibly be okay just to use a standard FC timer interrupt setup - but I've used the code as is and set as a custom interrupt..

As mentioned - the C has a bug - I've replaced the recursive calls to Inverter with gotos (so now I have to go and scrub my hands again :| )

It's written and tested using v9 (I don't have FC8 installed at present and our broadband is slooowwww at the moment - estimated time 4h for the download)

I also used a Nano as one was to hand - you'll need to change the target...

The C also sets the 'volume' in the interrupt handler - which I would probably try and 'move' into the Inverter loop.. I think I set an initial volume - instead of the 0 the C has... (change this back to 0 - but volvalue is only read after 140 'waves' and having it the interrupt handler will cause a 'glitch' in the waveform) The 'test' in the C should be >=175 not > 175 in the ISR..

Button on pin12 toggles the output on and off... I used a jumper to a 470 resistor to gnd and 'touched' the wire on. The resistor doubled as the current limiting resistor for the LED on pin2
PWM Inverter.fcfx
(26.22 KiB) Downloaded 175 times
Here with the 'setvolume' code 'disabled'..
LabNation_Screenshot0.png
LabNation_Screenshot0.png (203.04 KiB) Viewed 8143 times
A snippet of the waveform - notice that the pulse is slightly longer each time.

Martin

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Pure Sine Wave Inverter

Post by Derrihj »

Thanks allot mnf for all the time you have put out just for me and others, I tell you this looks really cool, on my side it looks so advanced at the moment, first thing I don't have FC9 I have only FC8 another thing won't this be hard for me to change from AD.nano to my PIC18F442 inorder to get my SPWM outputs ,aren't there many things to change to make this work on the 18F442? I also wanted to see how you bring in the SPWM look-up table.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Pure Sine Wave Inverter

Post by mnf »

Hi.

No problem - it should compile under v8 okay.
Converting it to pi.c won't be easy though - all the register writes are very AVR specific - the pic will have similar capabilities but you are probably best starting from scratch or swapping mcu - it will work with some minor modification on various Atmega or possibly attiny MCUs.

Martin
.

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Pure Sine Wave Inverter

Post by Derrihj »

Am kindly asking if you get some time you help change this to 18F442 as it's so advanced for me to know how to change it as a beginner.Another thing I tried looking for the sine look-up table in your code but couldn't find it,how did you implement your SPWM without this sine- look up table.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Pure Sine Wave Inverter

Post by mnf »

It won't be easy to convert :cry:

Any PIC folk any ideas - the code generates a sine wave over two pins with x = time and y = length of pulse. The 'negative' y values are a mirror on the second pin.

The code seems to work well - but it's very AVR specific (uses the PWM to generate the pulses..)

I use a LUT component for the table - in v9 I would just use an array....

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Pure Sine Wave Inverter

Post by mnf »

I found some (partial) PIC code at https://microcontrollerslab.com/complet ... -inverter/ - he requests $40 for the complete code...
However, there may be enough clues there to give us a start.

Martin

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Pure Sine Wave Inverter

Post by Derrihj »

Thanks mnf for the link, but we don't need to buy one when we already have one for free in the link below, the guy used PIC16F684 I think this has enough info for a pro like you to figure things out and make it work in flowcode. Here is the link:. http://tahmidmc.blogspot.com/2012/10/ge ... 0.html?m=1

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Pure Sine Wave Inverter

Post by mnf »

So - first, a literal translation.

However, all I can say for sure is that it compiles.... Under v9...

Perhaps you could test and see if there is any output? Note that the interrupt setting might need some adjustment depending on the clock you have..
Attachments
PIC Inverter.fcfx
(10.57 KiB) Downloaded 194 times

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Pure hard meat Sine Wave Inverter

Post by Derrihj »

Thanks mr mnf for your time in this but i think as for me, this is becoming hard meat to tear down, and i have only FC8, i don't know if i can do a direct shift to FC8 with 18F442 and a 20mhz crystal.Question, which pins is your spwm on?

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Pure Sine Wave Inverter

Post by mnf »

I'm hoping so - unfortunately I don't have a PIC licence under v8 to test. However, i 've not used any v9 specific features..

I do have some PIC hardware which I can try - although it will be tomorrow before I get a chance.

It is a direct translation of the program given - try changing the target - it is dependent on the registers used being present in both MCUs. If (and it's a a big IF) it compiles then have a look at the output on the pwm pins

Martin

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Pure Sine Wave Inverter

Post by Derrihj »

Ok then did u use the code on the link i provided? coz i think that one has 4 outputs.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Pure Sine Wave Inverter

Post by mnf »

Yes...

Derrihj
Posts: 348
Joined: Mon Jul 09, 2018 12:43 pm
Has thanked: 67 times
Been thanked: 33 times
Contact:

Re: Pure Sine Wave Inverter

Post by Derrihj »

I can see many downloads of this mnf inverter code, has anyone tried changing this to a PIC , has anyone built this already to share the ups en downs if any?

Lambra
Posts: 3
Joined: Mon Jan 23, 2023 10:25 am
Been thanked: 1 time
Contact:

Re: Pure Sine Wave Inverter

Post by Lambra »

hello Derrihj.. I am very late in posting here.. I have had to change my name a few times already.. I have studied the TAHMID systems very well.. I have used TAHMID notes to construct his PWM invertor circuit. I built a few different models.. the only problem I have is in the feedback system.. TAHMID'S transformer ratios are also strange.. I have tried his 1:32 winding ratio.. which does not work... I have asked a company to make me a transformer with a 11-0-11 .. to 220 volt winding.. I will keep you posted..

Post Reply