psecody
Member
So last night I finally sat down and started working on the basic functions of a robot I'm building in my spare time. I don't actually have any servos with me at the moment to test the program but I started trying to figure out some of the basics anyway. So I'm using MikroC which has a PWM set of functions built into it. MikroC Manual (Page 303 is what I'm talking about)
In the manual the it details using Pwm_Init, Pwm_Start, Pwm_Change_Duty, and Pwm_Stop.
So in my program I first initialized it using the Pwm_Init where in parenthesis you're supposed to put the frequency. As I understand this the frequency is basically the period of the pwm, correct? Well I'm wanting about a 20mS period so this should be 50Hz (1000/20). When I go to try to compile the code it gives me an error saying that number is out of range or something similar to that. I typed it in exactly like Pwm_Init (50); I assume that the frequency is supposed to be written in Hz because the example uses Pwm_Init (5000); and says its 5KHz. So 50 would be right, right?
Also I was wondering if the oscillator that I'm using could be part of the problem (thats what I suspect) I'm using an 8MHz crystal but I also have a few 20MHz crystals laying around. Can someone also kind of explain to me how to figure out what speed of crystal you need for your projects? I've always wondered that.
Thanks I appreciate all the help.
In the manual the it details using Pwm_Init, Pwm_Start, Pwm_Change_Duty, and Pwm_Stop.
So in my program I first initialized it using the Pwm_Init where in parenthesis you're supposed to put the frequency. As I understand this the frequency is basically the period of the pwm, correct? Well I'm wanting about a 20mS period so this should be 50Hz (1000/20). When I go to try to compile the code it gives me an error saying that number is out of range or something similar to that. I typed it in exactly like Pwm_Init (50); I assume that the frequency is supposed to be written in Hz because the example uses Pwm_Init (5000); and says its 5KHz. So 50 would be right, right?
Also I was wondering if the oscillator that I'm using could be part of the problem (thats what I suspect) I'm using an 8MHz crystal but I also have a few 20MHz crystals laying around. Can someone also kind of explain to me how to figure out what speed of crystal you need for your projects? I've always wondered that.
Thanks I appreciate all the help.