Cerb40 PWM on 4.2

Hi.

The cerb40 is supposed to have 9 PWM pins (http://wiki.tinyclr.com/index.php?title=Cerb-Family#Helpful_Notes).

There are two problems:

  1. There are only 8 PWMChannels (PWMChannel.PWM_0 to PWMChannel.PWM_7) and additionally only four of them work.

  2. If I try to declare a PWM pin like that:
    PWM e4 = new PWM((Cpu.PWMChannel) GHI.OSHW.Hardware.FEZCerberus.Pin.PB3 , 10000, 1000, PWM.ScaleFactor.Microseconds, false); // WARNING!!! DON’T DO IT!!!

the cerb40 stops responding when I uploaded the program. Visual Studio and MFDeploy could not see it. I had to reflash it using ST-LINK to restore it in working condition.

Is there a way to use more than 4 PWM pins on 4.2?

Check this thread:

http://www.tinyclr.com/forum/topic?id=7760

Thanks for the link.

I found useful information but I did not find a solution for the problem.

I cannot find what is wrong with my code. I tried to step into the program and everything worked fine till the specific line.

Have anyone successfully used more than 4 pwm channels on cerb40 on .netmf 4.2?

it is channel 8, this has nothing to do with the pin number. This is what you need, where 8 is the channel number. This can be any number but NETMF has enums for first 7 only.

PWM e4 = new PWM((Cpu.PWMChannel) 8 , 10000, 1000, PWM.ScaleFactor.Microseconds, false);

The Cerb40 may not have all of the PWM channels exposed on the pins. The Cerb-Family has 16 PWM channels programmed into Micro Framework. Here is a list of Channel to pin on the Cerb-Family:

C6, A7, C7, A8, B0, B1, B5, B4, B3, B11, B10, A10, A9, A15, B8, B9

The channels are in this order from PWMChannel.PWM_0 ~ PWMChannel.PWM_15. However, as you said past channel 7 you have to enumerate like this:

(Cpu.PWMChannel)8 ~ (Cpu.PWMChannel)15.

Look at the pinout on the Cerb40 and check to find the proper pin from the list above.

vote on this if you like please https://netmf.codeplex.com/workitem/1846#

1 Like

Voted. It’s a great idea!

I run the following code for testing, then I searched all the pins, pin by pin, using a logic analyzer.

Finally, I found 6 PWM pins. There should be at least two more.
I used different dutyCycle to determine which PWMChannel is assigned to each pin. It is easier than reading the board diagram and the cerb40 specs.

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.Threading;
namespace MFConsoleApplication3
{
    public class Program
    {
        public static void Main()
        {

            PWM p0 = new PWM(Cpu.PWMChannel.PWM_0, 500, 0.2, false);
            p0.Start();
            PWM p1 = new PWM(Cpu.PWMChannel.PWM_1, 500, 0.3, false);
            p1.Start();
            PWM p2 = new PWM(Cpu.PWMChannel.PWM_2, 500, 0.4, false);
            p2.Start();
            PWM p3 = new PWM(Cpu.PWMChannel.PWM_3, 500, 0.5, false);
            p3.Start();
            PWM p4 = new PWM(Cpu.PWMChannel.PWM_4, 500, 0.6, false);
            p4.Start();
            PWM p5 = new PWM(Cpu.PWMChannel.PWM_5, 500, 0.7, false);
            p5.Start();
            PWM p6 = new PWM(Cpu.PWMChannel.PWM_6, 500, 0.8, false);
            p6.Start();
            PWM p7 = new PWM(Cpu.PWMChannel.PWM_7, 500, 0.9, false);
            p7.Start();
            
            Debug.Print(
                Resources.GetString(Resources.StringResources.String1));
           Timer  t = new Timer (new TimerCallback(TimerTest),"start",200,1000);
            
           Debug.Print("Program started");
           Thread.Sleep(Timeout.Infinite);
        }

        private static void TimerTest(object o)
        {
            Debug.Print("timer triggered");
        }
    }
}

So http://wiki.tinyclr.com/index.php?title=FEZ_Cerb40_Developer is the developer page for Cerb40. From that I can see only 4 PWM channels discussed. I’m not sure why you have the number 8 in your mind? The Wiki page you point to is for the FAMILY of devices, not Cerb40; as Aron says the Cerb40 doesn’t say it has all those exposed. Now you’ve found the pinouts, you could add a PWM section to the Cerb40 developer page to help others out.

Here are the PWM pins of the Cerb40

Cpu.PWMChannel.PWM_0 PC6
Cpu.PWMChannel.PWM_1 PA7
Cpu.PWMChannel.PWM_2 PC7
Cpu.PWMChannel.PWM_3 PA8
Cpu.PWMChannel.PWM_6 PB5
Cpu.PWMChannel.PWM_7 PB4