Author Topic: Problems with PWM on webbotlib  (Read 1650 times)

0 Members and 1 Guest are viewing this topic.

Offline javilaTopic starter

  • Jr. Member
  • **
  • Posts: 31
  • Helpful? 0
Problems with PWM on webbotlib
« 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

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Problems with PWM on webbotlib
« Reply #1 on: September 10, 2010, 03:50:07 PM »
Try using Solarbotics/L298.h http://webbot.org.uk/WebbotLibDocs/34638.html as thats just a fairly generic L298 implementation.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Problems with PWM on webbotlib
« Reply #2 on: September 10, 2010, 03:56:15 PM »
Alternatively: change the last parameter ie

Code: [Select]
// 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
}
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline javilaTopic starter

  • Jr. Member
  • **
  • Posts: 31
  • Helpful? 0
Re: Problems with PWM on webbotlib
« Reply #3 on: September 10, 2010, 04:41:32 PM »
thanks, that is really useful.

 


data_list