Go Down

Topic: From linear to exponential PWM output (Read 19 times) previous topic - next topic


Hi Paco,
It looks like the dimension declaration is wrong for the graph.
The Variant business just complicates things.
There is very little about line graphs in VB.
I found this slightly lower level code:

You have to scale the 0-255 coordinates to be graph values (use map) before drawing them.
You have only 3 pairs of XY data:
0, 0
switchPointX, switchPointY
255, 255

After that you could add drawing the hor speedstart line and vertical deadband lines (dotted).
You could also add some of the lookuptable points between the switchpoint and (255, 255) to see the curve.
Sorry I haven't done Visual Basic.


Jul 10, 2012, 09:11 pm Last Edit: Jul 10, 2012, 09:19 pm by backbone Reason: 1

Graph only in basic form is working with your suggestion of the VB6 picturebox drawing lines.
I am now looking in the 2DNTgraph.ocx to see if I can get this to work too as it more fancy and has more features.
But for the time being the simpel graph exactly shows what we are doing with X and Y points although it is not using the curvePower yet ;-).

I just tested the curvePower line.
Code: [Select]
//lookupTable[i] = map(i, switchpointXValue, 255, switchpointYValue, 255 );       // this could get replaced by a curve after all is working
             lookupTable[i] = (int) (0.5 + (switchpointYValue  + pow( map(i, switchpointXValue, 255, 0, 255 - switchpointYValue ) / 255.0, curvePower/10) * 255.0));

As soon as CP value is 1 I can reach 255 as maximum
When I raise CP to 2,4 value the maximum is getting lower. The higher CP the lower the maximum.

Never to old to learn and I learn every day


Soemtimes thing go quicker then expected.
With the help from VB forum guys I got the NTgraph.ocx working too.

Never to old to learn and I learn every day


Jul 11, 2012, 12:30 am Last Edit: Jul 11, 2012, 11:41 pm by Techylah Reason: 1
Excellent, Paco.  Nice to see the better graph.
I changed this post because the math was wrong. (perhaps that's considered bad form)

As you move the switchPoint around, this curve will automatically adjust, always starting where the linear part ends.

The curved part will approach 100% very slowly with the fastest change happening near the switchpoint.
endCurvePower adjusts this (from 1.0 for none to 4.0 or more, for very steeply curved)

The slope, or trigger sensitivity, changes right at the switchpoint.
Your graphing app is now really helpful to visualize this.
In order to really see and verify this, you should add to your graph all the points of the lookuptable that have X greater than switchpointX.

Code: [Select]

float endCurvePower = 2.5;
for (i=0; i<255: i++)
  if (i < deadbandXvalue)
       lookupTable[i] = 0;
        if (i < switchpointXValue)
               lookupTable[i] = map(i, deadbandXvalue, switchpointXValue, speedstartValue, switchpointYValue);
                lookupTable[i] = (int)(0.5 + switchpointYValue + (255-switchpointYValue) * ( 1.0 - pow( (255-x)/(255-switchpointXValue), endCurvePower) ));


Jul 11, 2012, 11:44 pm Last Edit: Jul 12, 2012, 12:28 am by Techylah Reason: 1
I completely changed the math so my last post is correct for the curve part.
I graphed it as a check.  Sorry for the inconvenience.

If you implement and graph it I'd like to see your plot.
Mitch (Techylah)

Go Up