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 http://old.ghielectronics.com/docs/18/pwm

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

1 Like

@Gus,

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,
Evul

Edit:
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,
evul

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:
GHI.Pins.FEZReaper.Socket7.Pwm7

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:
GHI.Pins.FEZReaper.Socket7.Pwm7
GHI.Pins.FEZReaper.Socket7.Pwm8
GHI.Pins.FEZReaper.Socket7.Pwm9
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

3 Likes