Estoy usando MC9S08AW60A con placa DEMO9S08AW60E (Freescale). He estudiado sobre los temporizadores dados con la MCU. Deseo saber exactamente cómo implementar temporizadores por código. La suite Freescale también viene con Processor Expert (una GUI para configurar la MCU).
He escrito el siguiente código para encender los LED de manera secuencial SIN usar una función de DEMORA, es decir, solo alterando/usando TEMPORIZADORES y GENERADOR DE RELOJ INTERNO.
//------------CODE BEGINS------------
PTFDD = 0xFF;
TPM1SC = 0x0E;//configures the Timer 1 Status and Control Register
TPM1C2SC = 0x98;//configures the TImer 1 CHANNEL 2 Status and Control Register
ICGC1= 0xE8; //Have altered the ICG with respect to TPM.
ICGC2= 0x8E;
//As you can see i have not altered the ICG in any way.And the same values as above
//(for TPM) i have emulated using the Processor Expert.
for (i=1;i<=8;i++)
{
if (i==8) i = 1;
if (i==1) PTFD = 0x01;
if (i==2) PTFD = 0x02;
if (i==3) PTFD = 0x04;
if (i==4) PTFD = 0x08;
if (i==5) PTFD = 0x10;
if (i==6) PTFD = 0x20;
if (i==7) PTFD = 0x40;
}
//----------CODE ENDS-----------------
Pero todo lo que obtengo:
En la hoja de datos, consulte la página 165 para el temporizador/PWM y la página 129 para Inter Clock Generator.
Aparentemente, como la frecuencia del temporizador es muy alta, para configurarlo necesitaríamos una configuración de preescalador grande (alcancé un máximo de 128). Después de haber tenido una conversación con mi colega, dice que necesito generar un "Tick" periódico con el período de parpadeo para cada LED configurado en consecuencia. Para asegurarse de que el LED (ENCENDIDO o APAGADO) corresponda al TICK en lugar de a la frecuencia del reloj del bus. Ya, esto funciona, pero todavía estoy confundido.
Si puede usar la hoja de datos para comprender las diversas funciones de registro, ¿por qué no funciona configurar la frecuencia del temporizador según los requisitos?
Además, ¿este "Tick" no es lo mismo que la función Delay?
aquí está el código para el mismo (por cierto, este código me fue sugerido en el foro de freescale, pero también podría ayudar a alguien más; no tomo crédito por este código):
// Assumed bus frequency: 8.0 MHz
// TPM prescale divisor: 4
// Global variables:
byte tic_cnt; // Timer tick counter
byte ch_nbr; // LED channel number
// LED mask values:
#define mLED0 0x01
#define mLED1 0x02
#define mLED2 0x04
#define mLED3 0x08
#define mLED4 0x10
#define mLED5 0x20
#define mLED6 0x40
#define mLED7 0x80
#define TIC_INCR 20000 // 10 ms tick period, with prescale 4
//***************************************************************
// LED blink polling function
void LED_poll( void)
{
if (!tic_cnt)
{ // Timeout occurred
tic_cnt = 50; // Start new 500ms timing interval
ch_nbr++;
if (ch_nbr == 8) ch_nbr = 0;
if (ch_nbr == 0) PTFD = mLED0; // Turn LED0 on, other LEDs off
if (ch_nbr == 1) PTFD = mLED1; // Turn LED1 on, other LEDs off
if (ch_nbr == 2) PTFD = mLED2; // Turn LED2 on, other LEDs off
if (ch_nbr == 3) PTFD = mLED3; // Turn LED3 on, other LEDs off
if (ch_nbr == 4) PTFD = mLED4; // Turn LED4 on, other LEDs off
if (ch_nbr == 5) PTFD = mLED5; // Turn LED5 on, other LEDs off
if (ch_nbr == 6) PTFD = mLED6; // Turn LED6 on, other LEDs off
if (ch_nbr == 7) PTFD = mLED7; // Turn LED7 on, other LEDs off
}
}
__interrupt VectorNumber_Vtpm1ch0 void ISR_TPM1_ch0( void)
{
TPM1C0_CH0F = 0; // Clear TPM channel flag
TPM1C0V += TIC_INCR; // Set next software compare
if (tic_cnt) tic_cnt--;
}
incrustado.kyle
sábanas
sábanas
incrustado.kyle
incrustado.kyle
TPM1SC = 0x10
.ELSnB:ELSnA
ambos deben ser 0 para que el temporizador no alterne la salida en comparación.sábanas