Hi all, I have come across a statement that many MCUs have a hardware option for their PWM signal. I have used the ARDUINO examples 'knob' and 'sweep' with the coding supplied. I find that at many points of the servo positions the servo is jittering. It has been suggested that the timing of the pwm signal from the nano and uno boards pwm pins is not accurate. It is also suggested that it is better to use a hardware generated pwm signal.
I have seen a reference to a genuino mega board which contains servo hardware pwm signals and not for just a single servo but multiple servos. I cannot locate this board anywhere. Does anyone know where I could get an arduino board which uses a hardware pwm as suggested many MCUs have?
I have designed software for the sweep and knob examples that have stopped this jittering. The software uses no libraries. I would like to publish this on this forum but I believe I could then be jeopidising any copyright I could have in the programming. Perhaps anyway there is already an improved version of the sweep and knob examples with software rather than a hardware option.
Publish a diagram showing all your connections.
It very well might be a hardware problem, especially on the power supply side
The nano and Uno do have hardware PWM, it's just not implicitly used by the servo library.
Hi Jim, Any idea how you access this pwm hardware on the nano board for instance. When hardware is referred to for the board this could mean the clock signal generated from a crystal or other means of generating the clock on the atmega chip. This could be called hardware.
Then there still would be coding necessary to use this clock to get a specific position on the servo?
When you start to see how complicated this coding would have to be to use the clock then you may be able to understand why arduino have used the pwm pins for signals to the servo in their 'sweep' and 'knob' examples. Even though it causes jittering at the servo positions.
My software solution is very simple. And no jittering at all. Very stable at any position of the servo. I would like to publish but then I guess any copyright would be compromised?
This is exactly why I don't like libraries Delta. You cannot see the code they are using. I assumed they were using the pwm pins ie analog write. The library generates an interrupt on a hardware timer. Are you saying the drawback (jittering) is due to the software interrupt of the hardware timer? At the interrupt you have a resultant jitter? Sounds feasible.
I agree my solution was not difficult . But it gets rid of that annoying jittering in both the knob and sweep examples. Also of course when you are using sensors rather than the pot in the knob example.
Can you give an example of a licence I can use to stop the corpos using software for free. I am all for sharing on the community. It seems to me the corpos are already getting free stuff from sites like this. You may be talking about a patent. I have an Australian patent on more efficient heaters. But patent attorneys do not come cheap.
If you have the library installed on your PC, which you have, then you can see the code and even copy or change it if you want to
Sure, it’s explained in the 328P datasheet. I suggest you become familiar with it and the app notes regarding PWM. The “Low-Jitter Multi-Channel Software PWM” app note may be of interest.
I don’t understand your questions about copywriting and even if I did, I not a lawyer.
To be honest, do you really believe that your solution is so genious, that corpos will use it? There are thousends of implementations of creating servo pulses out there. But if you really want to you can use GNU GPL.
Bob, How exactly can you see the coding in the file. Do you double click on the library file or something like that? The file I am talking about is' #include <Servo.h>'. I need to see what is in here.
It has been explained in a general way what is in this file on this forum. That hardware is used( what is the hardware?) This is not explained. Then a software interrupt is used to access the hardware. Then the suggestion is made that the interrupt is causing the jittering in the servo.
The coding I have used avoids all of this. No hardware needed. No interrupt. No ' #include <Servo.h>'. No jittering of the servo at any point.
It also has been suggested that the software coding to move the servo is easy.
This is my challenge then on this forum. Can anybody come up with a code that has all the attributes of mine?
Thanks for that Jim. The 328p people have been aware of the jittering problem for servos. I will look that up.
Here's the file path to the stepper library on my Linux box, Windurs should be similar.
/home/usrName/arduino-1.8.5/libraries/Stepper/src
Navigate to the folder holding the library files using File Explorer. Use any text editor, Notepad++ is a favourite here, to open the library files for examination
Hi @petercl14
The Uno/Nano has 16-bit timer 1 that can be configured for 50Hz servo operation on digital pins D9 and D9:
// Set-up hadware PWM on the Arduino UNO at 50Hz on digital pins D9 and D10
void setup() {
// Initialise timer 1 for phase and frequency correct PWM
pinMode(9, OUTPUT); // Set digital pin 9 (D9) to an output
pinMode(10, OUTPUT); // Set digital pin 10 (D10) to an output
TCCR1A = _BV(COM1A1) | _BV(COM1B1); // Enable the PWM outputs OC1A, and OC1B on digital pins 9, 10
TCCR1B = _BV(WGM13) | _BV(CS11); // Set phase and frequency correct PWM and prescaler of 8 on timer 1
ICR1 = 19999; // Set the PWM frequency to 50Hz
OCR1A = 1500; // Centre the servo on D9
OCR1B = 1500; // Centre the servo on D10
}
void loop() {
OCR1A = 1000; // Move the servo to min position on D9
OCR1B = 1000; // Move the servo to min position on D10
delay(1000); // Wait for 1 second
OCR1A = 2000; // Move the servo to max position on D9
OCR1B = 2000; // Move the servo to max position on D10
delay(1000); // Wait for 1 second
}
In addition to timer 1, the Mega also has 16-bit timers 3, 4 and 5, all with three output channels: A, B and C. That's twelve 16-bit timer outputs in total.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.