Main Site Documentation

IO60P16 PWM and Cerbuino Bee question


#1

Hi All,

My local GHI distributor told me that the FEZ Panda 2 was end of life and Cerbuino Bee would be its successor. So I ordered some to play with, but I’m having some difficulties :-). I got the firmware update running and am now capable of doing some programming using a new .NET Gadgeteer Application (NETMF 4.2). Nicely done GHI, with the designer and all. I’m impressed. I could easily connect my brand new RFID module and that worked instantly.

However, I missed the 80 IO ports I got so used to on FEZ. So I also bought the IO60P16 to be able to have control myself again and not be forced to use gadgeteer modules (you would give up an entire socket for one button and I need a lot more).

But that is where the problems kicked in. If I use the designer it adds a
Gadgeteer.Modules.GHIElectronics.IO60P16 io60p16;

Definition. that’s nice. But it has no methods. Instead, it seems that the static IO60P16 now magically knows that it´s bound to this socket. But what if I want to add more IO60P16 modules later on? How would it know what module I refer to when I use a method on GTM.GHIElectronics.IO60P16?

But, I can still live with that for now. I created a small application that sets a multi-color LED to a specific color when I placed a RFID tag. Using output pins on IO60P16 that’s not a problem:

        IO60P16.OutputPort ledGreen = null;
        ledGreen =  new IO60P16.OutputPort(IO60P16.IOPin.Port0_Pin1, false);

However, I could not define the ledGreen directly like:

        IO60P16.OutputPort ledGreen = new IO60P16.OutputPort(IO60P16.IOPin.Port0_Pin1, false);

So I’ve set it to NULL outside the class and created the instance within ProgramStarted. That works. I could do this for the red, green and blue pin and write true to set it on and false for off.

But…, I wanted to use PWM to dim the Led’s. And that’s where I got another problem. I changed the outputport definitions to PWM definitions:

        IO60P16.PWM ledGreen null;
        ledGreen = new IO60P16.PWM(IO60P16.PWMPin.PWM0, IO60P16.PWM.TickWidth.TickWidth_1500KHz_667ns);

And I could give it a pulse:

        ledGreen.SetPulse(10, 20);

The green light does lite up. However, I set red and blue to .SetPulse(0,0) as well. Red and blue are registered on PWM1 and PWM2, green = PWM0. But as soon as I change the pulse setting on any of the PWM ports it seems to affect all of them.

Chances are that I did something truly stupid here, because I’m a complete PWM noob, but I did not expect the PWM ports to affect each other. This was no problem with the output ports.

Any help or pointing in the right direction would be greatly appreciated :slight_smile:


#2

Check out this thread…

http://www.tinyclr.com/forum/topic?id=9784&page=1


#3

I swear I answered your question this morning! I forgot to hit submit?! Anyways …

This is incorrect, who is your distributor? This needs ot be explained better. Panda is premium and cerbuino is OSHW, they are not direct replaceable of each other. If you are not using any of the premium features then maybe it is possible. Also cerbuino supports gadgeteer to expand the functionality is easier with cerbuino.

By naming them differently, in the designer where you drop the module.

Every module had a tutorial for it but looks like we forgot this one. We will add in next few days http://wiki.tinyclr.com/index.php?title=IO60P16_Module


#4

@ Gus, I buy all my GHI stuff from Antratek (http://www.antratek.nl/). They are listed as your dutch supplier. They don’t have the FEZ panda 2 in stock anymore (http://www.antratek.nl/GHI.html) and when I asked them why they told me that FEZ Panda 2 was obsolete and replaced with Cerbuino.

That was a bit of a shock to me because I love FEZ and I already have a lot of them. I will probably need a lot of replacements too because of my crashing quadcopter project, but now I’m starting to like Cerbuino as well. Both great products. But great that you keep creating the Panda 2! I got so used to that board. I always bought at Antratek because they support IDeal, the dutch online payment method.

@ Ianlee74, thanks for helping me out again. I’m a bit embarrassed that I could not find that topic myself. Now that I scan the forum some more I even see that you created the first driver for the module. Great work :-). I missed any documentation and tutorials on the module, but I now see that they will arrive soon (tnx Gus!). I still dont get the LED working with the PWM example listed, but Ill keep trying.

Thanks!


#5

I think I’m not clear on the PWM usage. On FEZ I had one pin to do PWM control. On the IO60P16 I seem to have 3 pins for each PWM. I downloaded schematics somewhere and I thought the outer 2 pins were ground and +5v.

I have a terrible mobile phone camera, but I attached a picture of the setup. I attached the cerbuino +3v and ground to the breadboard power strip, connected socket 3 to the IO60P16 module and 2 to the RFID reader.

The PWM0 to 3 pins on port 6 closest to the processor are connected to the RED, GREEN and BLUE wire of the 3-color LED. The LED’s ground is connected to the FEZ ground.

Now I use the following code:


    public partial class Program
    {

        IO60P16.PWM io60p16_pwm1;
        IO60P16.PWM io60p16_pwm2;
        IO60P16.PWM io60p16_pwm3;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            io60p16_pwm1 = new IO60P16.PWM(IO60P16.PWMPin.PWM0, IO60P16.PWM.TickWidth.TickWidth_32KHz_31520ns);
            io60p16_pwm2 = new IO60P16.PWM(IO60P16.PWMPin.PWM1, IO60P16.PWM.TickWidth.TickWidth_32KHz_31520ns);
            io60p16_pwm3 = new IO60P16.PWM(IO60P16.PWMPin.PWM2, IO60P16.PWM.TickWidth.TickWidth_32KHz_31520ns);

            rfid.CardIDReceived += new RFID.CardIDReceivedEventHandler(rfid_CardIDReceived);

            io60p16_pwm1.SetPulse(0, 100);
            io60p16_pwm2.SetPulse(0, 100);
            io60p16_pwm3.SetPulse(90, 100);
           
        }

        void rfid_CardIDReceived(RFID sender, string ID)
        {
            switch (ID)
            {
                case "0100314B8C":
                    io60p16_pwm1.SetPulse(0, 100);
                    io60p16_pwm2.SetPulse(90, 100);
                    io60p16_pwm3.SetPulse(0, 100);

            break;
                case "4D0095056A":
            io60p16_pwm1.SetPulse(0, 100);
            io60p16_pwm2.SetPulse(0, 100);
            io60p16_pwm3.SetPulse(90, 100);
            break;
                case "06001EAD66":
            io60p16_pwm1.SetPulse(90, 100);
            io60p16_pwm2.SetPulse(0, 100);
            io60p16_pwm3.SetPulse(0, 100);
                    break;
                default:
            io60p16_pwm1.SetPulse(0, 100);
            io60p16_pwm2.SetPulse(0, 100);
            io60p16_pwm3.SetPulse(0, 100);
                    break;
            }
        }

When it initializes the LED turns green as expected. But as soon as I show RFID tag 06001EAD66, the following code executes:

           io60p16_pwm1.SetPulse(90, 100);
            io60p16_pwm2.SetPulse(0, 100);
            io60p16_pwm3.SetPulse(0, 100);

If I debug that, I see the LED turn green at the first line, turns off at the second and stays of at the third line. I thought this would be because setting one PWM port to 0 would affect all ports, but when I debug the application I see that each RFID tag is actually blinking the LED for a split second.

So either my understanding of PWM is terrible, or I messed up connecting the wires somehow. Still a lot to learn for me :slight_smile:


#6

Don’t be. The ability to search on this forum is infamously bad. If I didn’t know that thread existed, I would have probably never found it either.

Some additional labeling would definitely be nice here. I usually have to pull out a meter and test it to remind myself which column is which. I can’t really follow your pic but I think your main problem is probably that you’re not giving power to the V+ pin. See pic.

If that straightens out your wiring, let me know if you’re still having problems.


#7

Are you planning to issue a new driver that supports multiple instances? I checked the driver and the SoftwareI2C is static making it impossible to drive multiple IO60P16 modules using the standard driver. As Ian has pointed out, changing this will also require re-factoring of the driver interface in general.


#8

@ IanLee74,

I guess it’s just that I don’t know what I’m doing :). I thought by reading the schematics that the V+ and GND were all connected allready on the board. I also don’t understand the purpose of connecting them. I did connect the PWM wires to the V+ and GND now, but nothing changes. I also don’t understand why I should connect those, but that’s just because I’m a real hardware noob.


#9

I’d be surprised if you needed to give v+ power (I haven’t checked the schematics). That three pin configuration is for servo, which need a gnd and raw power line, plus the pwm pin to control the position. So if you’re just wanting to dim an LED, you only need to use gnd and the pwm pin. If you have a continuity tester or multimeter, make sure the Gnd pins are as Ian shows, then make sure your connections are correct and you’re using the correct pin - in fact, try setting all pins going and see if you can get it to work on any!


#10

Hi Brett,

Yes, that would surprise me as well, I’m controlling LED’s with a single PWM on the FEZ board, so I would expect that to work here as well.
The servo idea makes sense in placing ground and voltage next to the PWM signal as well. I know they already connected the ground for all PWMs, because if I connect a voltage meter to a PWM ground and +5 (the outer pins) it indicates 5 volts.

However, if I connect the middle PWM pin and ground with my voltage meter, nothing happens. Strange, because I would have expected voltage on that as well for servos.
Also weird, if I connect my voltage meter ground to PWM7 ground and PWM 7’s PWM pin, it indicates 3.3V. None of the other PWM’s on port 6 have that behavior.
I’m back at my “somehow changing the pulse on one PWM changes it for all PWM’s” again. At least, while debugging. If I run the program real-time the PWM just makes the LED blink. While debugging it will stay on.

This is just beyond my comprehension. I’ll wait and hope for more detailed tutorials and connection examples.


#11

The approach I was really thinking about was to prove a pwm code in netmf worked by using an extender module and dimming the LED there, as well as confirming your LED setup is ok.

Since you have a voltmeter, set pwm duty cycle to 50% and read voltages again, that should give you about 1.75 volts on the meter singe it will be too slow to see the pwm wave so will just register the average.

I would be trying all pins and seeing what happens, they should be consistent is my assumption…


#12

GND is connected. V+ is for you to supply external power source. It is not connected to anything initially which is why you are not measuring any voltage. Connect V+ to +5V and you will get +5V down the entire rail. If you’re powering LEDs directly through the pin then this won’t really matter. My assumption was that you were powering them through the V+ pin.

How many LED’s are you controlling through a single pin? If you’re powering the LEDs through the pin instead of through a transistor then you certainly cannot control more than one on a pin with this module.


#13

I’m starting to think that either my Cerbuino or IO60P16 board is broken. I’ve attached an better image of how I connected things, and I think this is the way it should work. I use the following code:

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp1
{
    public partial class Program
    {

        IO60P16.PWM io60p16_pwm0;
        IO60P16.PWM io60p16_pwm1;     

        void pwmTest_Tick(GT.Timer timer)
        {
            // Increase red led output (pwm0)
            for (byte x = 0; x < 100; x++)
            {
                io60p16_pwm0.SetPulse(x, 100);
                Thread.Sleep(50);
            }
            // Set red led off
            io60p16_pwm0.SetPulse(0, 100);

            // Increase green led output (pwm1)
            for (byte x = 0; x < 100; x++)
            {
                io60p16_pwm1.SetPulse(x, 100);
                Thread.Sleep(50);
            }
            // Set green led off
            io60p16_pwm1.SetPulse(0, 100);
        }

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            // Initialize PWM pins
            io60p16_pwm0 = new IO60P16.PWM(IO60P16.PWMPin.PWM0, IO60P16.PWM.TickWidth.TickWidth_32KHz_31520ns);
            io60p16_pwm1 = new IO60P16.PWM(IO60P16.PWMPin.PWM1, IO60P16.PWM.TickWidth.TickWidth_32KHz_31520ns);

            // Set execution timer (increase red and green led every 10 seconds).
            GT.Timer pwmTest = new GT.Timer(10000);
            pwmTest.Tick += new GT.Timer.TickEventHandler(pwmTest_Tick);
            pwmTest.Start();
        }


    }
}

I want to control each of the LED’s with a separate pin, so I’m using PWM0 and PWM1 to control the red and green LED of the multi-color-led. If I run the application without debugger, nothing happens. If I run it on a USB cable with debugger, only PWM1 is increasing brightness. Attaching a voltage meter I see no output on PWM0 and PWM1 increasing from 0 to 3.3v (the green light increasing).

Now when I remove all PWM1 related code, PWM0 works (the red light is increasing), but PWM1 is also outputting 3.3v.

I don’t understand this behaviour at all. I can see why not setting PWM1 will always output 3.3v (maximum up-time threshold), but I don’t understand why PWM0 seems to work without declaring and using PWM1 this way.


#14

simplify your problem. does each work as you expect if you only have one channel that you define and use? does the behaviour change with/without debugger attached? what about if mfdeploy is attached instead of VS? Then repeat for the other pwm.


#15

Do you get the same behavior if you use PWM1 & 2 vs. 0 & 1? I do recall we encountered some weird behavior at one time regarding PWM0. Also, try using a different clock (second param of PWM constructor) on each pin and see if you get something different.


#16

I have no experience in these matters,so pardon my ignorance.

The Socket on the IO board is marked as an X. Socket 1 in the diagram is PSU Y.

Both are GPIO, but perhaps might there be differences causing different behavior than expected in this case?


#17

Any Y socket is also an X socket per the Gadgeteer specs.


#18

We found the issue and on the way to fix it.


#19

@ Dat,

That’s great news. Then I’m not going crazy :-). And great support finding and fixing issues on christmas :-).


#20

Hi Dat,

I was just wondering if you made any progress with the fix. Hope to hear from you :slight_smile: