flatdog Posted April 30, 2012 Report Posted April 30, 2012 Dear Pete, I have been using the sample lua script posted by Terry Hall to interface with a PoKeys56U card. I have added some switches and LEDs for various functions which all seem to work so I feel I have a reasonable understanding of what is happening. I would now like to use the PWM output(s) of the card to build a simple three position flaps gauge incorporating a servo. The example in the PoKeys manual is written in C# a language which I have no experiece of. The framework for the relevant portion of the lua script would be: function flap_check(offs, val) if (val == 0) then -- Flaps Full Up pokeys:SetPWMOutputs(.............................) else end else -- code for Takeoff Flaps else -- code for Landing Flaps event.offset(0x0BDC, "UD", "flap_check") The C# example is: Configuring PWM outputs Configures pin 17 as PWM output with 20 ms period and 1.5 ms (7.5%) duty cycle. If a model RC servo signal input is connected to this pin, servo motor horn should position itself in the middle position. bool[] channel = new bool[6]; uint[] duty = new uint[6]; // PWM base clock is 12 MHz (or 25 MHz on PoKeys56 devices), so 1 ms takes 12000 (25000) cycles float ms = MyDevice.GetPWMFrequency() / 1000; uint period = (uint)(ms * 20); // 20 ms period channel[5] = true; // Pin 17 = channel 5 (Pin 18 = channel 4, ...) duty[5] = (uint)(ms * 1.5); // Set duty cycle to 1.5 ms (7.5 %) MyDevice.SetPWMOutputs(ref channel, ref period, ref duty); Do you use C#? If so could you help me convert the example into the correct lua syntax? There is no desperate hurry for this, if you have a spare moment that would be great. Many thanks, Philip
Pete Dowson Posted April 30, 2012 Report Posted April 30, 2012 Do you use C#? No. If so could you help me convert the example into the correct lua syntax? Well, probably the equivalent in Lua is channel = {}duty = {}ms = pokeys:GetPWMFrequency() / 1000period = ms * 20channel[5] = trueduty[5] = ms * 1.5pokeys:SetPWMoutputs(channel, period, duty)[/CODE]but it makes no sense. You have two 6-entry arrays (channel and duty), but only set number 5 in each.And I don't know the external pokeys library, so I've no idea about those two calls.Is there a support forum for the pokeys driver you are using?RegardsPete
flatdog Posted April 30, 2012 Author Report Posted April 30, 2012 Dear Pete, There are six pins on the card that can be used as PWM outputs, channel 5 refers to pin 17. The other information in the manual is: SetPWMOutputs Set complete PWM outputs configuration bool SetPWMOutputs(ref bool[] channels, ref uint period, ref uint[] duty_values); Arguments: channels An array of 6 boolean values, each representing one PWM channel. Channel is enabled if this value is set to true. period 32-bit PWM period value. PWM module of a PoKeys55 device runs at 12 Mhz, so a value of 12 000 000 produces a period of 1 second. PWM module on PoKeys56E devices runs at 25 MHz, so a value of 25 000 000 produces a period of 1 second. duty_values An array of 6 32-bit unsigned integers, each representing the value of PWM duty for each channel. Minimum value is 0, maximum value is the same as period. Channel to pin mapping: Channels are mapping according to this table: Channel PoKeys pin 0 22 1 21 2 20 3 19 4 18 5 17 The PoKeys website does not appear to have a user forum. I will ask over at myCockpit to see if anyone knows of a user group. Many thanks, Philip
Pete Dowson Posted April 30, 2012 Report Posted April 30, 2012 There are six pins on the card that can be used as PWM outputs, channel 5 refers to pin 17. Yes, but your code extract is not setting or using the others. Additionally i don't know if "5" refers to the 5th or 6th element (in C/C++ 5 would be the 6th as C/C++ counts from 0. Lua counts from 1. I've no idea about C#). The other problem is that the Lua format for the arrays, whose pointer is being passed, is not going to be acceptable to those Pokeys functions unless the person who made the Lua pokeys library you are using has dealt with this sort of difference. All numbers in Lua are 64-bit floating point. I don't know what C# would use for its BOOL and UINT types, but most likely 32 bit integers -- most certainly not 64-bit floating point values. But whoever wrote the Lua library for pokeys would have surely known that. The PoKeys website does not appear to have a user forum. Well, I suppose the Pokeys folks wouldn't know about Lua in any case. You really need help, or at least good documentation, for the Pokeys Lua interface library I assume you must be using. You need to contact the author of that rather than of Pokeys itself. Regards Pete
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now