Motorshield V2 PWMfreq adjustment

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
careless
 
Posts: 10
Joined: Fri Feb 28, 2014 7:21 pm

Motorshield V2 PWMfreq adjustment

Post by careless »

I have a Motorshield V2 that I am hoping to use.

I'm looking at the library reference page, and I see the following:
void begin(uint16_t freq = 1600);
begin() must be called in setup() to initialize the shield. An optional frequency parameter can be used to specify something other than the default maximum: 1.6KHz PWM frequency.
I have some questions regarding the feature set and the library files.

first is in regards to the "default maximum". Is this indicating that the 1600 is the ceiling that is set by putting that code in setup (i.e. it can be, say... 3200hz if replaced with "3200"?), or is that just the maximum frequency this Motorshield provides via the onboard chip. I do not see any indication of what the minimum and maximum tolerable PWM frequencies available are. If I were to guess, by comparing to the PWM Shield you provide, it looks to be the same chip that is the brain of the system. And that is rated at 40-1600hz, so the Motorshield V2 is also the same rating, correct? Perhaps putting this in the description for the Motorshield might be a good idea, or perhaps even the FAQ (or pointing to it, because I may have missed it).

second is in regards to modifying the frequency after boot-time. Is it ok to move the "void begin(uint16_t freq = 1600)" code into a different loop instead of having it in the setup loop? Can I bring it into an conditional statement to modify the PWM frequency based on certain events, button presses, etc.? I'm unsure if initializing it in the setup loop is a requirement for this shield.

lastly... if 40 is the minimum frequency this shield allows, what recommendation would you provide in order to provide a range down to 15 or 20hz minimum, instead of the 40-1600hz range. I was hoping to bypass the internal PWM circuitry of the Arduino UNO R3 so that I can have a variably adjustable signal to control a non-polarized solenoid by disguising it as a DC motor and using this shield to drive it while being able to fine tune the frequency as well as the duty cycle.

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Motorshield V2 PWMfreq adjustment

Post by adafruit_support_bill »

Is this indicating that the 1600 is the ceiling that is set by putting that code in setup (i.e. it can be, say... 3200hz if replaced with "3200"?), or is that just the maximum frequency this Motorshield provides via the onboard chip.
1600Hz is the maximum the shield will do.
And that is rated at 40-1600hz, so the Motorshield V2 is also the same rating, correct? Perhaps putting this in the description for the Motorshield might be a good idea, or perhaps even the FAQ (or pointing to it, because I may have missed it).
Most people are concerned with the max rate spec, which you did find. It is not practical to run motors at very low clock rates.
Is it ok to move the "void begin(uint16_t freq = 1600)" code into a different loop instead of having it in the setup loop?
I have not tried it, but it should work.
what recommendation would you provide in order to provide a range down to 15 or 20hz minimum
You would have to dig into the library and the PCA9685 documentation on that. Worst-case, you could feed an external clock signal into Pin 14.

User avatar
careless
 
Posts: 10
Joined: Fri Feb 28, 2014 7:21 pm

Re: Motorshield V2 PWMfreq adjustment

Post by careless »

Hi again,

if 1600hz is the max, then it seems as though 40hz is the min, outlined in the datasheet. (It should still be described on the product page, though. I probably would not have purchased this because of the 40hz min... Just sayin! :mrgreen: )

I understand most people would be concerned with max spec, but the solenoid I'm using operates generally between 20-40hz, 31 being the best. I know the arduino uno can be set to 31hz by timer divisors/etc., but the attraction to this board was that i wouldn't need to use a logic-level FET to feed the 12v solenoid, which is only 7.5watt continuous. Also, having the PWM freq adjustable with some degree of variance using the code was attractive as well... the lower the frequency, the wider usable duty cycle range I can get from this solenoid. The widest suitable range for my application being somewhere in the neighbourhood of 25-30hz.

I have a MAC 4-port Hi-Power solenoid from the list below:

Image


Using a PID program like the Sous Vide system will allow this solenoid to have the widest range of error correction when put through it's paces to reach its target. It is contending with a very rapidly fluctuating air system, and this needs to be able to control that with a blend of speed (hz), and wider range at the best speed (duty). In any case, I will experiment with it sometime this week and report back my findings by seeing if it will do lower frequency by probing it with my scope setup.

Thank you, billlllll!

User avatar
careless
 
Posts: 10
Joined: Fri Feb 28, 2014 7:21 pm

Re: Motorshield V2 PWMfreq adjustment

Post by careless »

Bill, in another thread about driving a solenoid using the Motorshield (I swear, I've been searching!), you specified that the Motorshield can only run a solenoid up to 0.6A or 600mA in this post:

http://forums.adafruit.com/viewtopic.ph ... 18#p143518

It is my understanding that this is for Motorshield V1 with the L293D driver, correct? The Motorshield V2 has the trusty TB6612 MOSFET instead of the Darlington Transistor driver from the V1.

So if I were to assume that the previous recommendation 600ma was for V1, and I am using the V2... it would be able to power my 7.7Va holding current 12v solenoid with 10.9Va in-rush current (so 0.64 - 0.91amps, respectively) without the need for the IRLZ44/IRLZ34N Logic Level MOSFET I was going to use (quite like the one you recommended in the linked thread up above to user Jarguess).

As long as i remove the power jumper and hook up the solenoid to M1, I should be able to control the non-polarized solenoid from the board without a FET/Transistor circuit to power the solenoid from an alternate +12V feed. With that in mind (if it is correct), would I be able to hook up the solenoid to either of the M1 to M4 ports, and drive it as is, or would I need to use a Schottky Diode (e.g. 1N4004) between both leads to the solenoid?

Essentially, the circuit I was going to mimic was that of the PhotoDuino Solenoid Valve interface 1.0 (except it uses an IRL520 FET, which is overkill for my application but would still work). I should be able to forgo that entire intermediary circuit and power it off the Motorshield, right? I just don't wanna damage anything :-)

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Motorshield V2 PWMfreq adjustment

Post by adafruit_support_bill »

It is my understanding that this is for Motorshield V1 with the L293D driver, correct?
That is correct. Based on the solenoid specs above, you should be able to run it direct from one of the motor terminals. Both the inrush and holding currents are well within the device rating. There are protection diodes internal to the driver. Additional diodes should not be necessary.

User avatar
careless
 
Posts: 10
Joined: Fri Feb 28, 2014 7:21 pm

Re: Motorshield V2 PWMfreq adjustment

Post by careless »

so I can just wire this bad-boy straight up and pop some code champagne to start a solenoid party? shweeeeeet :mrgreen:

last question. if I'm powering the Arduino through this PSU: http://www.adafruit.com/products/352, does the shield get 12v power from the PSU just like the arduino does, or does it receive 5v power from the Arduino's 5v rail to power the shield and it's output ports?

Sorry if I'm asking questions that are answered in the FAQ/Doc, I've just want to be sure.

nvm, found my answer again:

Image

User avatar
careless
 
Posts: 10
Joined: Fri Feb 28, 2014 7:21 pm

Re: Motorshield V2 PWMfreq adjustment

Post by careless »

Hi bill,

Good news, it works even down to 10hz!!! WOOOO!

So I can power my solenoid at the desired frequency. The IC's don't seem to get hot at all, but perhaps when all is said and done I will use some non conductive thermal paste and put a snazzy heatsink on it that I can borrow from a motherboard I have layin' around because it will be concealed and I won't be able to monitor it from the seated position.

Howeeeeeeeeeever... This caught my eye:

Image

It says that it can only be called in setup... Is there absolutely noooo way to make a call to this during void loop and have it re-initialize without restarting the boost controller?

User avatar
adafruit_support_bill
 
Posts: 88090
Joined: Sat Feb 07, 2009 10:11 am

Re: Motorshield V2 PWMfreq adjustment

Post by adafruit_support_bill »

It just needs to be called before you try to use the PWM output for anything. In normal use, setup is the logical place to do that. If you need to change the frequency on-the-fly for your purposes, I don't think there is a problem with calling it in other places.

User avatar
careless
 
Posts: 10
Joined: Fri Feb 28, 2014 7:21 pm

Re: Motorshield V2 PWMfreq adjustment

Post by careless »

Hmmmm. I tried to call it outside of setup();, and it didn't work.
I'll give it another go with a bit of changes to the test code and report back with my findings, just incase anyone else is wondering if the Motorshield V2 will suit their needs.

Thanks for your quick responses. :D

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”