mauricio fernandez montoya

SERVO control with TIM module of HC908JK1

Discussion created by mauricio fernandez montoya on Aug 20, 2007
Latest reply on Aug 23, 2007 by bigmac
HI.   i need to control a servo with the pwm module of JK1.   this is the code i wrote but it doesn't work!!!

maybe i have a big mistake in the way i analized the program, or maybe im using a wrong method to control the servo...

this is the code:
#include <hidef.h>
#include < MC68HC908JK1.h>
#include "TIMERAPI.h"

double Frecuencia=0.05;   
double Dureza;
double Modulo;
double Duty;   

double Periodos[5]={ 3.25,4.875,6.5,8.125,9.75};
unsigned char i;

void Init_uC(void);
void Init_PWM(void);

void main(void) {
    Init_uC();
    for(i=1;i<=5;i++) {
    Dureza=Periodos[i];
    Delayms(1000);
    }
}


void Init_uC (void){
    EnableInterrupts;
    CONFIG1_COPD=1;
    DDRB=0x18;
    DDRD=0x3C;
    PTB=0;
    PTD=0;
}


void Init_PWM(void){
    Modulo  = 2500/Frecuencia;            // 2.5Mhz / Frecuencia en Khz
    Duty       = Dureza*Modulo/100;
    TSC_TSTOP  = 1;                     // PARA EL TIMER
    TSC_TRST   = 1;                        // RESET AL TIMER
    TMOD       = Modulo;                 // Periodo de la señal de PWM                   
    TCH0       = Duty;                    // Ancho de pulso requerido
    TSC0_MS0A  = 1;                        // Unbufered PWM
    TSC0_ELS0B = 1;                        // Clear output on compare
    TSC0_TOV0  = 1;                        // Toggle on overflow
    TSC_TRST   = 0;                     // RESET AL TIMER
    TSC_TSTOP  = 0;                     // PARA EL TIMER       
}


TIMERAPI is a library that makes delays..... Delayms() is used with this library (milliseconds)
the servo i want to control : ROBBE RS200:

Min:0.65 ms
Neutral: 1.3 ms
Max: 1.95 ms
Frequency: 50 Hz (means 20 milliseconds period)


THANKS!!!!

Outcomes