Motor Driver, PWM

Hello Folks

I hope you can help me. There have been many changes since I last used the system. :confused:
I wanna make a system with two Servo motors.
Two years ago I made a sucessful test with a motorboard for big DC motors.

But I think the code changed.
Can I still use this command in 4.3?

motordiver1.SetSpeed(MotorDriverL298.Motor.Motor1, 0.8);

This is my setup:

you don’t need to use the L298 to drive a standard servo, the L298 is for DC motors. All you need is a standard PWM signal.
I don’t think that answers the question you asked, but it should reorient your thinking - you don’t need the L298 gadgeteer driver to get the servo to work.

In theory, yes.

But back in 4.1 I used it because the command was very easy to get a pwm.

motordiver1.SetSpeed(MotorDriverL298.Motor.Motor1, 0.8);

But when I look at the documentation in 4.3… it looks way different.
… there is a new example in the legacy devices… but when I add those to the code:

using System.Threading;
using GHIElectronics.TinyCLR.Devices.Pwm;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Pins;

They are marked red :confused:

everything TinyCLR is not .NETMF 4.3, its early alpha version of what comes after 4.3… and of course different booter/firmware

ahhh ok… so, TinyCLR is not something I need to have a look at it.

So, what would be the most simple way to get a PWM signal on my 4.3 FEZ Reaper?

Here’s the netmf PWM document

Unless you are in a production ready stage, you should use TinyCLR. That is my recommendation.

1 Like


Really? we should use TinyCLR unless we’re at a production ready stage?

serious ?
TinyCLR is a nice very early alpha preview but far away from stable and far away from done and its missing to much features compared to your stable version of NETMF 4.3
based on the past TinyCLR releases it seems it could be feature equal to NETMF in one year from now on

That is why you should not use it if you are ready for production but for any other use, TinyCLR is the way forward.

Ok, I had a look at the documentation.
It totally exceeds my knowledge for PWM… but I give it a try.
Since I use a servo, I probably have to use this code:

public class Program
public static void Main()
PWM MyServo = new PWM(Cpu.PWMChannel.PWM_3, 2175, 175, PWM.ScaleFactor.Microseconds, false);

// 0 degrees. 20ms period and 1.25ms high pulse
MyServo.Duration = 1250;
MyServo.Period = 20000;

But how does my FEZ Reaper know, that the servo is connected on Socket_7 Pin_7 ?
Additional does my programm not know this … command :confused:

And what is the difference to this kind of PWM use?
motordiver1.SetSpeed(MotorDriverL298.Motor.Motor1, 0.1);

I’m really thankful for all your help.
It’s very imprtant to me to get this servo running :3

Kind regards,

Ok… I noticed that the documentation is not correct :smiley:
Pin 7: Motor A Speed (PWM) … Pin_7 is Motor B

The servo is doing something now… but he’s more or less just running into a end position :confused:
Could this have to do something with the mentioned frequency?

Servos expect a pulse every 20ms to 30msstrong text

Gadgeteer is still an option for you if you really want - although the core netmf capabilities changed from where you came so you may still need to re-learn some of these things.

PWM pin mapping comes from the definition of the PWM object; the first parameter is Cpu.PWMChannel.PWM_3 which references a physical channel, and that is linked back to a specific pin. What that pin’s capabilities are, are listed in the GHI provided helper GHI.Pins. Add that reference, and you can browse to see sockets and enclosed pin definitions. I’d suggest you actually use the GHI provided mapping, GHI.Pins.FEZRaptor.Socket18.Pwm7 looks to be the right place to connect it.

PWM reference not being found means your app needs another reference so that it can locate the correct calling procedure pattern - just add the Microsoft.SPOT.Hardware.PWM reference and you’re done.

you’d need to dig into the driver code that the L298 motor module used, because it’s abstracting the PWM component away from the user. I don’t think you need to worry about this, just move on and learn something new. :wink:

Hey Brett

Uhh, I’m always up to learn something new.
But on the beginning I need a moment to understand such things.
Mostly I get stuck at the basics… for example this:

No idea what VS wants to tell me :smiley:

Where do I find the GHI provided mapping?
I’m still working on it to understand how I adress that specific pin.
Documentation says this:

PWM MyServo = new PWM(Cpu.PWMChannel.PWM_3, 2175, 175, PWM.ScaleFactor.Microseconds, false);

But which pin am I adressing here?
In the end I need 3 PWM signals on 3 different pins.
How do I do that?

I really hope you’re not laughing too hard about my sillyness -.-

Kind regards,

Nope, I’m laughing along with you ( :wink: )

You added a USING statement, not a REFERENCE. You add references in the right hand panel in VS, in “references”, right click and say Add Reference, select it from the list.

You are addressing the pin that is connected to PWM Channel 3. It’s completely up to the person who implemented the firmware to map that - so it’s a GHI question that I can’t answer and doesn’t have a clear logical mapping. But if you add the GHI.PINS reference that I told you about, you get easy access to the correct PIN mapping without concern for the channels-to-pins (this is why GHI give you this!). There are three pins in Socket18 that have PWM capability.

1 Like

uhhh, we’re getting closer.
Step by Step ^.^
I found the reference thingy and I added it.
No red markings anymore in that line: yay

PWM MyServo = new PWM(Cpu.PWMChannel.PWM_3, 2175, 175, PWM.ScaleFactor.Microseconds, false);

Uhm… I only have 14 Sockets on my board :confused:

Can you give me an example where I would need to enter this “GHI PIN reference”?

I think I need to use those 3 pins:
Socket 7 Pins 7,8 &9

I guess it should look like this:

But where do i have to write this in?

I think we’re very close to complete the system ^.^

yep, perfect. Sorry, I was looking at RAPTOR not REAPER :slight_smile:
They are the references you need.

is how you will use it…

Uhhh, it wooooorks!!!
Even found the GHI Pin reference.

@Brett You’ve been a very big help. Wouldn’t have managed it without ya :smiley:
Now my next project can be realized :smiley: Thank you sooo much