IO60P16 Module and PWM on PORT7

Hey guys im new and just started with .NET Gadgeteer.

I just install the release candidate and got some problems.
If I use the PWM0-PWM7 i got no problems and can easily configure my PWM.
If i use PWM8-PWM15 (PORT7) i get a PWM but i cant configure it.
It is always the same frequency.
Does anybody got a hint for me?

ok i got the same behavour with another IO60P16 maybe a bug?

I just used the RegisterWrite Methode and the Pwm was configurable.
So it seems the driver is buggy.
I hope someone can verify that.

What driver are you using ?

Please show your code.

This is just the code about the pwm. The whole Project is a bit to long to post it.


                                            case 0x0D:
                                                    {
                                                        uint periodeTime = (uint)((MessageToHandle.Data[1] + (MessageToHandle.Data[0] << 8)));
                                                        uint pulseWidth = (uint)((MessageToHandle.Data[3] + (MessageToHandle.Data[2] << 8)));
                                                        GTM.GHIElectronics.ModulePWM Servo12;
                                                        Servo12 = Extender1.CreatePwm(
                                                            GTM.GHIElectronics.PwmPin.Pwm12,
                                                            periodeTime,
                                                            pulseWidth,
                                                            GTM.GHIElectronics.ModulePWM.ScaleFactor.Milliseconds,
                                                            false
                                                            );
                                                        Servo12.Start();
                                                        break;

and here the code for the manual register access:


                                                case 0x0E:
                                                   {
                                                        byte pulseWidth = MessageToHandle.Data[0];
                                                        byte period = MessageToHandle.Data[1];
                                                        byte devider = MessageToHandle.Data[2];
                                                        Extender1.WriteRegister(0x18, 7);
                                                        Extender1.WriteRegister(0x1A, 0xff);
                                                        Extender1.WriteRegister(0x28, 0x0C);
                                                        Extender1.WriteRegister(0x29, 0x04);
                                                        Extender1.WriteRegister(0x2A, period);
                                                        Extender1.WriteRegister(0x2C, devider);
                                                        Extender1.WriteRegister(0x2B, pulseWidth);

with the second part i can configure the pwm with the first one i cant. Maybe im doing something wrong but it is strange. If i use the first part with PWM0-PWM7 I can configure the PWM.

I am using the Drivers included in GHI NETMF v4.1 v4.2 and .NET Gadgeteer Package (RC2 8-24-2012).zip

@ e.trautmann
It seems you are using original io60p16 driver.
How you declared “Extender1” ?


  Extender1.WriteRegister(0x18, 7); // Select Port 7
  Extender1.WriteRegister(0x1A, 0xff); // all pin as PWM
  Extender1.WriteRegister(0x1C, 0x00); // direction as output

  Extender1.WriteRegister(0x28, 0x0C); // Select PWM 12 (Port7, bit4)
  Extender1.WriteRegister(0x29, 0x04); // Select clock to 1.5Mhz
  Extender1.WriteRegister(0x2A, period); // set Period
  Extender1.WriteRegister(0x2C, devider); // Divider needed ?
  Extender1.WriteRegister(0x2B, pulseWidth); // set Pulsewidth 

I don’t see any problem here, except that you need to set Port7 direction bits to output, but it’s output by default. Keep in mind that “drive mode” works also on PWM output pins.


    GTM.GHIElectronics.IO60P16 Extender1 = new GTM.GHIElectronics.IO60P16(7);

Extender1 is just an IO60P16 Module on Socket 7.

The manual writeRegister Operations are only to test the device. I just wanted to be sure that the device is ok.

I just tried an older version of the driver which was posted during the development. With this driver i could configure pulswidth and the period.

@ e.trautmann - If you are using the driver you can setup and use PWM calling ModulePWM methods


                                                        Servo12 = Extender1.CreatePwm(
                                                            GTM.GHIElectronics.PwmPin.Pwm12,
                                                            periodeTime,
                                                            pulseWidth,
                                                            GTM.GHIElectronics.ModulePWM.ScaleFactor.Milliseconds,
                                                            false
                                                            );
                                                        Servo12.Start();
...
// From now on, you can use:
//          Servo12.SetPWM(byte port, byte pin, uint period_ns, uint pulseWidth_ns );


Using SetPWM method you can directly set period and pulse in ns and the driver take care of the port settings.

@ dobova: i just tried Servo12.SetPWM(…) and i got the same behaviour.
I got a pmw and cant configure the pulsewidth and the period.

Mhhh… ok let me check …

Is nobody able to verify the behaviour?

@ e.trautmann - I can’t do that now, I will in couple of hours…

Please can you give me some value for period and dutycicle you are setting in your app ?

Ok I’ve tested the code :


...

            pwm = io60p16.CreatePwm(
                                    GTM.GHIElectronics.IO60P16.PwmPin.Pwm12,
                                    400,
                                    200,
                                    PWM.ScaleFactor.Milliseconds,
                                    false
                                    );

            Debug.Print("0x1C = " + io60p16.ReadRegister(0x1c).ToString());
            pwm.Start();

            // Blink an LED.
            op15 = io60p16.CreateOutputPort(IOPin.Port0_Pin0, true);
            op15.Resistor = ResistorMode.StrongDrive;
            var timer = new GT.Timer(1000);
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Start();

            return;
...

and it works perfectly. I’ve used 400mS period and 200mS dutycyle (50%) at startup. In the attached image you can see the last blu line labeled PWM12 and see that it works.
The problem is that changing running PWM dutycycle, the driver lack a function that use the same parameters scale like the PWM creation or eventualy a percentage. In any case using


public void SetPwm(byte port, byte pin, uint period_ns, uint pulseWidth_ns)

and supplying correct value it works correctly.

Thank you for your help.
I will give it another try today but i am very confused that my code is working on Port 6 and not working on Port 7.

OMG … Ok something is weird. The Ian’s driver in codeplex works fine. The driver included in the GHI sdk is failing on port 7. I don’t know what they changed inside, but it doesn’t work correctly.
Setting 400ms with 200ms dutycycle (50%) with the GHI included driver I get 8ms period and 4ms dutycycle (50%) but only if I power off the board, otherwise it remains in the last state.
This call has different behaviour in the original Ian’s driver.


pwm = io60p16.CreatePwm(
                                    GTM.GHIElectronics.IO60P16.PwmPin.Pwm12,
                                    400,
                                    200,
                                    PWM.ScaleFactor.Milliseconds,
                                    false
                                    );


If you want experiment with better control on the driver download the source here:
http://netmfx.codeplex.com/SourceControl/list/changesets

Ah ok i was getting frustrated. Thank you for the verify and thank you for the link.