I have a project in which I need several PWM signals and preferably between 25kHz and 100kHz. I have not researched what the 2560 I am using can do but if it can do more and that was accessible then that would be great.
The problem with 500Hz is that the only way I can use it is to filter it to a DC value then use that, a ramp signal I would need to design and a comparator to generate the PWM I need. To make it worse, the 500Hz is so low the filter I would need would also be s-l-o-w.
There is an issue with a shared resource (millis and delay use at least one of the timers) so what can be achieved might be constrained by that but if there is a hack or workaround or other piece of creativity out there I'd be very grateful.
Hi Delta G,
My apologies for my original post and the lack of clarity. I'll try again....
The background to my question:
I need to generate between 6 and 12 PWM signals in total.
The exact number will depend on what PWM capabilities are available on the MEGA2560
At least 6 of them must be 25kHz or higher.
If more than 6 PWM signals is possible then only the first 6 need to be 25kHz or more and the rest can be anything from 50Hz and upward.
More than 8 bits resolution would be good but not mandatory.
I am using a MEGA2560.
And my question is:
Can the 2560 produce PWM signals at 25kHz or higher?
(I hope I have communicated better this time
Thanks in advance.
PE.
Can the 2560 produce PWM signals at 25kHz or higher?
Yes.
have not researched what the 2560 I am using can do
It would move things along faster, if you did that research and come back with some more specific questions. Google "pwm Arduino Mega" or 25KHz pwm Arduino Mega" do some reading, and get back to us.
The Mega has 6 hardware timers, which can be programmed for a specific PWM frequency each. A timer supports up to 3 independent PWM outputs. If you can't find libraries supporting your needs, study the data sheet and existing library code how to program PWM channels as desired.
DrDiettrich, Thanks for that. My suspicions confirmed, I'll have to get down and dirty with the data sheet and a spanner or two and tweak the PWM into the form I require. Dang. Was hoping to avoid that
The data sheet does indicate that this should be possible for up to 12 PWM outputs but a library to do it I have not found. So I'm thinking the most expedient way forward will be to do as you say and code it myself. If I can code it into a library then I'll have something to give back!
Hey cattledog, I had actually looked into this some and I was essentially asking if anybody else had faced this problem in the hope that they had and either found a solution or could at least, as the good Dr has just done, confirm that a library to do this does not (yet) exist and I'll have to sort it out the old fashioned way.
I don't know what you thought I was trying to do. It was a fairly simple question that somebody with the experience with Arduino and the 2560 might be able to answer and I figured that there would be a number of such persons on these forums. After all, the purpose of these forums is to share experience and knowledge, right? I am new to Arduino, I am not a software engineer but do have some experience in software, I also have a good deal of experience (about 30 years worth) in electronic design as well as a degree in electrical engineering.
If you did not have the answer to the question I asked, you were not obliged to answer at all. Especially in such a pompous and condescending tone. I wonder if you realise how confronting and offensive your response was and I wonder how many newbies have you scared off with this style of posting. Nobody likes a rebuke, everybody likes helpful and constructive advice. It is the fundamental principle of these forums to be helpful and constructive, not dismissive and high handed.
I have answered you in the same way you answered me, in public, and deliberately so.
Hi,
It sounds like you need the high PWM frequencies so you can use a filter to get fast response analog levels.
Have you researched using I2C or ISP Digital to Analog Converters?
Tom....
PedantEngineer:
At least 6 of them must be 25kHz or higher.
If more than 6 PWM signals is possible then only the first 6 need to be 25kHz or more and the rest can be anything from 50Hz and upward.
More than 8 bits resolution would be good but not mandatory.
I am using a MEGA2560.
If you want completely independent control of PWM frequency and duty cycle for 6 channels, then I'm thinking some other dedicated PWM module might be needed here. One that really does allow programming of each channel individually.
Indeed that's the other question: why do you want it to be at such high frequency?
if it's for providing an analog out, look for different microprocessors. Some of the ATtiny line have DACs built in, so newer ATmega chips probably have that as well (never looked into those).
If you are looking for another uc, you might consider an Arduino DUE since the Sam3x8e has very capable PWM and Timer Counter controllers able to output independant (or synchro) PWM signals with variable frequencies and duty cycles.
The max frequencies for either the PWM controller or the Timer Counter controller are well above 25 KHz.
Thank you all for your responses. Looks like I need to fill in a couple of details:
- I don't need independent frequency control as long as the frequency is high enough
- These outputs will be used to run a power conversion stage (DC/DC) to control the voltage applied to a number of independent loads.
The loads in question are brushless motors so I can't just PWM directly to them. So a simple power stage will do the job but the frequency needs to be high enough that I don't need an output choke the size of a house for it to work properly (and hopefully keep it in continuous conduction mode over the operating range).
I wasn't sure if the arduino IDE etc would allow much fiddling at low level but it does I think so there is hope! That's where I am at with this at the mo. Some coaxing of timers etc to bring a PWM to life.
The problem with 25kHz and the reason I have not aimed at something more convenient like 100kHz is that at 16MHz the 2560 would top out at a maximum of 62,500Hz with 8 bit PWM and I figured there will probably be a prescaler in there with a minimum value of 2 just to ruin my day
If the 25kHz is not possible but the PWM is then my backup plan (besides a DUE) is to run what PWM I can, filter that to DC and hand craft my own modulators.
Thanks again for taking the time to read and respond.
PE.
Brushless DC motors (BLDC) do not react on voltage, but on the frequency of the voltages. It's crucial that the output signals for one motor are in phase (0°, 120°, 240°).
You are better off with dedicated BLDC motor drivers, or direct control of the half-bridges by the hall sensors inside the motor. Consult a tutorial about driving and controlling BLDC motors.
Conditioning the output rectangles by RC filters is not required, the motor coil inductance does that almost automatically.
Hi,
What are your BLDC motors.
A link or picture of them would help.
A BLDC motor is basically a 3phase AC motor.
As mentioned above they have thier own driver, a computer fan is a BLDC motor with the driver built in.
Tom...
Further clarifications
I'm not trying to make a BLDC driver just power a few things that happen to have BLDC motors in them and therefore I can't just PWM the power to the thing as I could with a brushed motor. These 'things' are pumps and fans. I can modify speed by reducing the voltage to some extent and that's pretty much all I need to do only I need to do that with 6 of them and independently.
TomGeorge:
Hi,
What are your BLDC motors.
A link or picture of them would help.A BLDC motor is basically a 3phase AC motor.
As mentioned above they have thier own driver, a computer fan is a BLDC motor with the driver built in.Tom...
Did you just say that a BLDC and an induction motor are basically the same thing!?
That's like saying a petrol and diesel engine are the same thing. They are worlds apart.
Neither has brushes, true, and both use a 3 phase drive, yes, but that's it LOL.
Hi,
BLDC is basically three windings and a stator.
3 phase motor, three windings and a stator.
Both are frequency/speed controlled.
Tom..
And one runs on (switched) DC, as in BLDC and the other on AC. The one will even hold position if the coils are not switched and the current left flowing while the other will not. One is electromagnets and the other is more like a transformer with a short circuit secondary. BLDC do not have any form of secondary whereas induction motors have a rotating secondary which carries a current at a frequency dependent on the slip. BLDC motors don't slip without stalling. BLDC motors cannot start with the excitation running at full speed. BLDC motors typically require active current limiting at all but their top speed. Induction motors can be dropped straight online to start (not good for a big motor or large inertial loads though).
I apologise for taking issue with your simplification but I am a pedant and given that not everyone on here is sufficiently conversant with these things to appreciate the simplification but rather, likely to take it too literally I cannot just let it pass without a comment.
With any luck, our exchange will have enlightened a few more about the similarities and differences between the two motor types.
wvmarle:
Indeed that's the other question: why do you want it to be at such high frequency?if it's for providing an analog out, look for different microprocessors. Some of the ATtiny line have DACs built in, so newer ATmega chips probably have that as well (never looked into those).
Thanks for taking the time to read and respond.
Because I will driving a DC/DC power stage with these signals. so to keep the chokes small I need higher frequency. I'm also trying to keep the power stage in continuous conduction mode (which will tend to push the chokes to higher values and bigger physical sizes) to keep the regulation loop simple or non existent with only a single phase drive and a free wheeling diode. Simple and easy.
Originally I was looking at uChip who have a uC absolutely a perfect fit! Made for the job and cheap. But do you think I could get their tools to work? Or get the part properly supported by the tools? Or find any of the library files they (generically) said I should look for? Or find the "core" files (whatever they are) that they also suggested? I couldn't even get my login password reset so I could post a question on their forums! So I found an email address and requested 'guidance' and two days later my email bounced. uChip == basket case!
A very frustrating week was that one.
PE.
Hi,
pedant
ˈpɛd(ə)nt/
noun
- a person who is excessively concerned with minor details and rules or with displaying academic learning.
Okay I understand.
I stand corrected.
Tom..
Hey Tom,
Engineering is all about the details and one cannot 'become' an engineer, we are born this way (baby, as the song says). That said, even by engineers standards I am a pedant!
And I spent almost 10 years at University to prove it.
Hi,
Have you got an 2560 to code your PWM outputs for?
By now I'd have been experimenting with code to learn the limitations of the hardware I have, and be researching for PWM chips with high PWM frequencies that can be controlled by the 2560.
Something like this (not sure of the PWM frequency)
Tom...