Nano Power Inverter - Roll Your Own Style

Author Message


Joined: 02/02/2017
Location: Australia
Posts: 1382
Posted: 11:14pm 11 Jul 2022      

I found out what is happening. I needed to load the broken code and see for myself.

how it all falls down:
on boot, code in setup() is executed. This includes setting oen = 0 (inverter commanded to STOP) and it calls init_vars() which in our case sets sst = 100
other stuff is completed then loop() is called repeatedly.
Within loop() a test is made, is sst > 0, if so, pull D5 high, else pull it low.
This test does not care if the inverter is supposed to be enabled, that is,
checking if oen = 1

And so we have D5 pulled high for a period of time EVEN THOUGH WE COMMANDED THE INVERTER OFF in the first code executed during boot.
This is not good.

I reproduced both of the results you show above.

A detail on the 3rd test you show when you set sst = 200
You pulled D8 high just before sst had enough time to count down to zero,
to cause D5 to then go low, so sst counted down from 200 to maybe 50, you pulled D8 high and then sst started to count up again. D5 always stayed high
since sst was always > 0

The experiments we are doing with changes to sst ALONE are not good.
Unexpected inverter running will result.

If you want to continue with this, you need to add a bit more code
to check for oen = 1 AND sst > 0 before pulling D5 (Gate drive enable) high

it will look like this:
if (sst <= 0)             // once fully stopped, no more changes to sst needed
       sst = 0;
       cbi(PORTD,5);     // pull IR2184 shutdown LOW to disable gate drive output
         if (oen == 1)
           sbi(PORTD,5);     // pull it HIGH, to enable output

I attach a new version with this fix, to allow you to use any value sst
within 0 to 200 (I do not want you to use larger values due to the risk of a sharp
transition from bang/bang to PID)

I needed to know the DC supply voltage so as to calculate the value of "pwr"
and so estimate a safe maximum for sst experiments.

31.2V AC RMS at your setpoint means 44.1V peak to peak
Let's say you are testing at 50V DC, that means pwr will be about
44.1 / 50 = 0.88
So for a smooth transition to PID, pwr needs to get to 0.88
With the 1000 step firmware, that means sst must increase for 880 steps

When we start the inverter, pwr is initialised to 0.0 and it will only be
changed by steps of 1/1000 either up or down.

IF we start sst at 200, it will NOT increase 880 steps, only 800 steps
since the max value for it is 1000. PID will switch over with a significant error,
about 80 times as large as it could be if we let pwr get to 0.88

IF we have sst = 100, then after the remaining 900 steps, pwr will be hovering
around 0.88 and so we get a smooth changeover.

This 0.88 is calculated from an assumed DC supply of 50V.
what voltage are you testing at anyway?

(This code is just for Mike to fiddle with. I very much prefer everyone else
to use earlier, unmolested code nano_1_v7_no_bessel)