I am using a MC9S12DT256 with an E-clock of 8MHz, 8bit PWM.
the servo motor requires a period of 20ms with a minimum pulse of 0.7ms and a max pulse of 2.5ms.
The problem is that when I hook it up to the motor it just rotate left a little. (same rotation at 0.7ms and 2.5ms)
I can't seem to see where my code or calculations went wrong.
I divided the 8Mhz clock by 10 to get 0.8MHz(Scaled A), then divided that by 64 to get 12500HZ.
I want a 20ms period for the motor so my period register will be:
0.020=(1/12500)*PWMPERx which gives PWMPERx=250
Then for the duty register I want 0.8ms out of 20 ms period which is a duty of 4%
so 0.04=(250-PWMDTY0)/250
PWMDTY=240
Any help is much appreciated.
Here is my code:
================================================
#include <hidef.h>
#include "derivative.h"
#include <mc9s12dt256.h>
void main(void) {
PWMCTL=0x00; // 8bit pwm
PWMSCLA=0x05; // A/(2*5) =SA
PWMSCLB=0x05; // B/(2*5) =SB
PWMCLK=0xff; // select scaled clock
PWMPOL=0x00; // start low
PWMPRCLK=0x06; // SA/64 = clock
PWMCAE=0x00; // left aligned
PWME=0xff; // PWM enabled
PWMPER0=0xfa; // 20ms=250/12500
PWMDTY0=0xf0;
EnableInterrupts;
for(;
{
_FEED_COP();
}
}
================================================