Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

PWM using Netduino Go and Shield Base ...

PWM shield base go motor

Best Answer Gutworks, 02 January 2014 - 08:48 PM

Hi Dave, 
 
It looks like you are using the Microsoft PWM class rather than the Secretlabs PWM class. The MS PWM class has two constructors, one that is often used for driving pulsing LEDs and piezo buzzers, and the other for devices like servos. I think you should be using the other constructor that looks like this:

public PWM(Cpu.PWMChannel channel, uint period, uint duration, PWM.ScaleFactor scale, bool invert);

Some time ago I wrote a sample app for a servo and the Netduino Go Shield Base and I also have a couple other posts that go a little more in detail about the PWM class. Hopefully so of these links will help you along the way.


  • Please log in to reply
5 replies to this topic

#1 DaveFer

DaveFer

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationAustin, TX

Posted 02 January 2014 - 04:04 PM

Hey all -

 

Last night I connected my LC Tech dual motor driver board to my Netduino Go w/ Shield Base.

 

I first connected it to an analog port and use .WriteRaw(int) to make 1 motor go. It worked.

 

But then I had trouble modulating the speed ... it seemed to only have 1 speed. (I should go back and verify that I had the right wire in the right port and wasn't trying to modulate the forward/reverse connection. :( )

 

So I switched it to a Digital Port and tried to use PWM -- no results. Nothing happened. The motor never budged.

 

Here's ONE of the code snips I used. I also used another style which I did myself without looking at a sample. Sorry I don't have that very intuitive code handy now.

 

var pwm0 = new PWM(sBase.PWMChannels.PWM_PIN_D9, 60, 50.0, false);

...

pwm0.Start();

...

if (On == true) pwm0.DutyCycle = 70.0;
else pwm0.DutyCycle = 10.0;
 
Anyone see any obvious deal breakers in my code here? Any sample motor driving code here? I'd like to see both Analog and Digital (PWM) examples of motor driving code.
 
THANK YOU!
 
- Dave F.


#2 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 02 January 2014 - 08:48 PM   Best Answer

Hi Dave, 
 
It looks like you are using the Microsoft PWM class rather than the Secretlabs PWM class. The MS PWM class has two constructors, one that is often used for driving pulsing LEDs and piezo buzzers, and the other for devices like servos. I think you should be using the other constructor that looks like this:

public PWM(Cpu.PWMChannel channel, uint period, uint duration, PWM.ScaleFactor scale, bool invert);

Some time ago I wrote a sample app for a servo and the Netduino Go Shield Base and I also have a couple other posts that go a little more in detail about the PWM class. Hopefully so of these links will help you along the way.


#3 DaveFer

DaveFer

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationAustin, TX

Posted 03 January 2014 - 03:26 AM

Thanks for the great response, GutWorks. Looks like it will be very helpful. (Even though I wasn't able to immediately make it work.)

 

In the mean time, I'm also curious to learn to use the Analog ports to drive a motor.

 

Isn't there an analog method to drive a motor (with varying power) thru an analog port?

 

Thanks.



#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 January 2014 - 10:07 AM

Hi Dave, On PWM...duty cycle has a range of 0.0 to 1.0. Setting it to >1.0 (in the constructor or later on) won't give you the results you seek :)

In the mean time, I'm also curious to learn to use the Analog ports to drive a motor.   Isn't there an analog method to drive a motor (with varying power) thru an analog port?

The analog input pins are ADC (analog input) rather than DAC (analog output). If you turn on/off the analog pins, your app will be accessing digital mode and sending out either 3.3V or 0.0V. Chris

#5 DaveFer

DaveFer

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationAustin, TX

Posted 03 January 2014 - 09:56 PM

I see ... so that explains why the Microsoft.SPOT.Hardware.OutputPort.Write() method takes a bool ... it only on or off.

 

Well, that's a bummer. :(

 

Ok, back to work trying to get the PWM to work. Trying to isolate the problem(s) and rule out my motors, driver module, wiring mistakes.

 

Thanks! PS - Chris, not sure you ever saw the mail I sent you here ... first time sending a message, not sure it actually went.



#6 DaveFer

DaveFer

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationAustin, TX

Posted 05 January 2014 - 04:17 PM

Ok, so GutWorks had the winning respones, But pulling the constructor from his sample code ... well, it took me quite a while to figure out why it behaved in an unpredictable manner:  The period and duration from his sample were something like 20000 and 1500 respectively (microseconds).

 

I found that until I brought those values down into 2000 and 150 range there was completely random behavior. (Motors not running until after I quit debugging, starting and then stopping after 1 change to the duty cycle.) There still remains 1 seemingly random misbehavior ... I'm successfully adjusting the DutyCycle to affect changes in motor speed ... but stepping thru the code, the DutyCycle behaves as if it is Read Only. For example: 

 

PWM0.DutyCycle = 0.99;  // DutyCycle reads 5000.0 after executing this line. And other other similar lines.

 

So, in short, Thank you GutWorks for getting me up and running! Much obliged. PS -- Another reason it took so long to debug had to do with a tiny motor that was drawing 0.380 ma because it was sticky (old and gunked?) My motor driver board kept heating up dramatically within a few seconds.







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.