Society of Robots - Robot Forum
Software => Software => Topic started by: javila on September 10, 2010, 01:11:26 AM
-
Hello:
I am currently trying to use pwm with webbolib to control two motors but I am having trouble picking the right frequencies.
I am using this:
void appInitHardware(void){
pwmInitHertz(B2,9000,100,null);}
To set the frequency to 9k in this case. It seems that when I use anything above 9000, the microcontroller does not work properly. Can any of you tell me how I can calculate the range of frequencies that I can use, and how do I check that the frequency is being set properly. I know that that function is a Boolean function but do not know how to use it to check. Any example would be appreciated. ( I know that there is a motorpwm function but I am using a different pin configuration than the one required by that function).
I have a atmega328p, with a 18432000 Hz crystal connected to a L298
Thanks in advance
-
Try using Solarbotics/L298.h http://webbot.org.uk/WebbotLibDocs/34638.html (http://webbot.org.uk/WebbotLibDocs/34638.html) as thats just a fairly generic L298 implementation.
-
Alternatively: change the last parameter ie
// Allow use of %lu to print uint32_t values
// Put this right at the top of your program
#define RPRINTF_COMPLEX
#include "rprintf.h"
uint32_t actualHz;
if(pwmInitHertz(B2,9000,100, &actualHzl)){
// PWM is on and 'acutalHz' has the value
rprintf("Actual PWM freq=%lu\n",actualHz);
}else{
// PWM failed, maybe the pin doesn't support PWM
// or the timer is already used to do other stuff
}
-
thanks, that is really useful.