I cannot for the life of me figure out how to get the correct output. So here's what's going on.
I have an ESC that I need to drive at 400hz (yes 400Hz NOT 50/60). I also need to write very specific values to this ESC. For instance, when I use the pulseIn() function with a RC receiver connected to the Arduino, I'm seeing a value of min 940 though max 1860.
How do I setup the Adafruit PWM Driver to output those same numbers, 940 through 1860? On the learn page for that product, they tell you to use this to modify the output:
setPWM(channel, on, off)
What does that even mean??? I understand the actual voltage goes high for a certain amount of time then low, but how do translate that into the values 940 through 1860 (which are being read from the pulseIn() function)?
From the Adafruit code:
pwm.setPWM(pin, 4096, 0); // turns pin fully on
pwm.setPWM(pin, 0, 4096); // turns pin fully off
Strange, because I expected 0-4095.
I suppose you map that 940-1860 value to 0-4095.
And then use
pwm.setPWM(pin, mappedValue ,(4095 - mappedValue));
Leo..
I also posted this question over on Adafruit's forum, and they gave me a quick response that solved my question. Here is the short version in case anyone else stumbles across this forum with the same problem.
"In your setup, you need to call setPWMFreq(400). That will give you a period of 2.5 milliseconds and a pulse width resolution of about 6 nanoseconds
With a RC receiver connected to the Arduino using pulseIn(), I'm seeing a value of min 940 though max 1860.
Those numbers are in microseconds. To generate a 940 microsecond pulse within a 2.5 millisecond pulse period with 12 bit resolution, you would need an 'off' parameter of (940/2500) * 4096 = 1540. For a 1860 microsecond pulse, the 'off' parameter would be: (1860/2500) * 4096 = 3047."
Note: Use the formula above to calculate a rough estimate of the length of pulse you want. Through my testing I found it only ballparks you. Adjust the value slowly up or down till you reach the desired pulse. If you're curious what they mean by change the "off" parameter look at the first comment in the code below.
// setPWM(channel, on, off)
pwm.setPWM(channel, 0, 2930); // Yields a 1850 microsecond pulse.
CrossRoads:
Are you posting this same question in multiple places?
That's your takeaway?
I'm trying to meet deadlines at my job, this is very important that I get it done. I'm already 3 days behind so yes I in fact did post in multiple places. And it worked great. I deleted the other thread I was going to delete this thread too but I don't think you can on Ard forums.
And before you jump on my case further I usually never do that but sometimes you just gotta get the job done.
Posting at different places is generally OK but it's considered good practice to add the links to the respective sites right away. Then we all know what's going on and save effort when questions are answered.
Anyway thanks for copying the answer to this forum, most posters won't bother with that either... and good luck with your project.
wvmarle:
Posting at different places is generally OK but it's considered good practice to add the links to the respective sites right away. Then we all know what's going on and save effort when questions are answered.
Anyway thanks for copying the answer to this forum, most posters won't bother with that either... and good luck with your project.
I hate it when people leave forums unanswered, so I just had to throw the answer up; I'm sure someone will have the same problem sooner or later!