HCS08 Timer problem

Hi There

I'm new with programming a microcontroller, so sorry for some questions. I have a HCS08 SofTec starterkit.

I want to control the light intensity of a external LED with a PWM. Therefor, I want to control the Duty Cycle of the PWM with the potentiometer on my starterkit. The ATD conversion is working. But my timer is not working and I have no idea why. To confirm that the timer is working, I set an interrupt. When the Timer has reached the channel value, port F on my starterkit should be increment (On port F are eight LEDs). But as I said, it dosen't work.

Can you help me?

Here's my code:

#include /* for EnableInterrupts macro */ #include "derivative.h" /* include peripheral declarations */ #include

#define Input 0x00 #define Output 0xFF

int low = 0; //low-value from ADC int high = 0; //high-value from ADC

void interrupt ISR_Timer(void) { PTFD++; //verification, that the flag is set TPM1C0SC = TPM1C0SC; //clear channel 0 interrupt falg TPM1C0SC_CH0F = 0; }

void InitPorts(void) { SOPT_COPE = 0; //disable Watchdog PTBDD = Input; PTDDD = Output; PTFDD = Output; }

void InitAD (void) { ATD1C_ATDPU = 1; /* power on */ ATD1C_RES8 = 0; /* 10-bit Resolution */ ATD1SC_ATDCO = 1; /* continuous mode */ ATD1PE_ATDPE0 = 1; /* enable bit 1 */ ATD1SC_ATDCH = 0; /* select channel 1 */ }

void InitTimer(void)

{ //Timer 1 Control & Status Register TPM1SC_TOIE = 0; //Timer 1 Overflow Interrupt disable TPM1SC_CPWMS = 1; //Center aligned mode TPM1SC_CLKSA = 1; //Internal Clock source TPM1SC_CLKSB = 0; TPM1SC_PS0 = 1; //Prescaler = 128 TPM1SC_PS1 = 1; //Prescaler = 128 TPM1SC_PS2 = 1; //Prescaler = 128 //Timer 1 Modulo Register TPM1MODH = 0xF4; TPM1MODL = 0x24; //Timer 1 Channel 0 Control Register TPM1C0SC_CH0IE = 1; //Channel 0 Overflow Interrupt enable TPM1C0SC_MS0B = 1; //PWM mode TPM1C0SC_ELS0A = 1; //Edge aligned mode }

void main (void) { InitPorts(); InitAD(); InitTimer(); for (;;) { if(ATD1SC_CCF == 1) { TPM1C0VL = ATD1RL; TPM1C0VH = ATD1RH; high = ATD1RH; low = ATD1RL; } } }

Allocation in *.prm file:

VECTOR 8 ISR_Timer

--------------------------------------- Posted through

formatting link

Reply to
aleksi
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.