este es el ejemplo mas simple de un pwm con un tiempo de togle de 3.125ms estudialo para que veas como funciona insisto te recomiendo que estudies la seccion del modulo pwm para que comprendas que se habilito y que se hizo porque de este es el codigo que se genere ya lo probe y funciona en 3 dias como dices no creo que alcances todavia a captar la parte de este modulo
solo modifica el codigo para que con el adc decremetes el valor de comparacion de timer que habilito en el codigo y tendras lo que estabas buscando
Saludos
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#ifdef __cplusplus
extern "C"
#endif
void MCU_init(void); /* Device initialization function declaration */
void main(void) {
MCU_init(); /* call Device Initialization */
/* include your code here */
for(;

{
__RESET_WATCHDOG(); //by default, COP is disabled with device init. When enabling, also reset the watchdog. */
} /* loop forever */
/* please make sure that you never leave main */
}
/*
** ###################################################################
** This code is generated by the Device Initialization Tool.
** It is overwritten during code generation.
** USER MODIFICATION ARE PRESERVED ONLY INSIDE EXPLICITLY MARKED SECTIONS.
**
** Project : pwm
** Processor : MC68HC908QY4CP
** Version : Component 01.078, Driver 01.01, CPU db: 2.87.147
** Datasheet : MC68HC908QY4/D Rev. 5 07/2005, MC68HLC908QY4/D Rev. 3 07/2005
** Date/Time : 10/03/2011, 10:27 a.m.
** Abstract :
** This bean "MC68HC908QY4_P_DW" provides initialization of the
** CPU core and shared peripherals.
** Settings :
** Clock setting
** Internal clock : 12800 kHz
** Initialization interrupt priority : 1
** Stop instruction enabled : no
** LVI module : yes
**
** Source clock : Internal Clock
** Internal bus clock : 3.2 MHz
** Contents :
** Function "MCU_init" initializes selected peripherals
**
** Copyright : 1997 - 2009 Freescale Semiconductor, Inc. All Rights Reserved.
**
** http :
www.freescale.com
** mail :
support@freescale.com
** ###################################################################
*/
#ifndef __pwm_H
#define __pwm_H 1
/* Include shared modules, which are used for whole project */
/* User declarations and definitions */
/* Code, declarations and definitions here will be preserved during code generation */
/* End of user declarations and definitions */
#ifdef __cplusplus
extern "C" {
#endif
extern void MCU_init(void);
#ifdef __cplusplus
}
#endif
/*
** ===================================================================
** Method : MCU_init (component MC68HC908QY4_P_DW)
**
** Description :
** Device initialization code for selected peripherals.
** ===================================================================
*/
__interrupt void isrINT_ADC(void);
/*
** ===================================================================
** Interrupt handler : isrINT_ADC
**
** Description :
** User interrupt service routine.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
__interrupt void isrINT_TIMOvr(void);
/*
** ===================================================================
** Interrupt handler : isrINT_TIMOvr
**
** Description :
** User interrupt service routine.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
__interrupt void isrINT_TIMCH0(void);
/*
** ===================================================================
** Interrupt handler : isrINT_TIMCH0
**
** Description :
** User interrupt service routine.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
/* END pwm */
#endif
/*
** ###################################################################
**
** This file was created by Processor Expert 3.07 [04.34]
** for the Freescale HC08 series of microcontrollers.
**
** ###################################################################
*/
/*
** ###################################################################
** This code is generated by the Device Initialization Tool.
** It is overwritten during code generation.
** USER MODIFICATION ARE PRESERVED ONLY INSIDE INTERRUPT SERVICE ROUTINES
** OR EXPLICITLY MARKED SECTIONS
**
** Project : pwm
** Processor : MC68HC908QY4CP
** Version : Component 01.078, Driver 01.01, CPU db: 2.87.147
** Datasheet : MC68HC908QY4/D Rev. 5 07/2005, MC68HLC908QY4/D Rev. 3 07/2005
** Date/Time : 10/03/2011, 10:27 a.m.
** Abstract :
** This bean "MC68HC908QY4_P_DW" provides initialization of the
** CPU core and shared peripherals.
** Settings :
** Clock setting
** Internal clock : 12800 kHz
** Initialization interrupt priority : 1
** Stop instruction enabled : no
** LVI module : yes
**
** Source clock : Internal Clock
** Internal bus clock : 3.2 MHz
** Contents :
** Function "MCU_init" initializes selected peripherals
**
** Copyright : 1997 - 2009 Freescale Semiconductor, Inc. All Rights Reserved.
**
** http :
www.freescale.com
** mail :
support@freescale.com
** ###################################################################
*/
/* MODULE MCUinit */
#include <MC68HC908QY4.h> /* I/O map for MC68HC908QY4CP */
#include "MCUinit.h"
/* User declarations and definitions */
/* Code, declarations and definitions here will be preserved during code generation */
/* End of user declarations and definitions */
/*
** ===================================================================
** Method : MCU_init (component MC68HC908QY4_P_DW)
**
** Description :
** Device initialization code for selected peripherals.
** ===================================================================
*/
void MCU_init(void)
{
/*** ### MC68HC908QY4_P_DW "Cpu" init code ... ***/
/*** PE initialization code after reset ***/
/* System clock initialization */
/* Common initialization of the write once registers */
/* CONFIG1: COPRS=0,LVISTOP=0,LVIRSTD=0,LVIPWRD=0,LVI5OR3=0,SSREC=0,STOP=0,COPD=0 */
CONFIG1 = 0x00;
/* CONFIG2: IRQPUD=0,IRQEN=0,OSCOPT1=0,OSCOPT0=0,RSTEN=0 */
CONFIG2 = 0x00;
OSCTRIM = *(unsigned char*far)0xFFC0; /* Initialize OSCTRIM register from a non volatile memory */
/* Common initialization of the CPU registers */
/* PTAPUE: OSC2EN=0,PTAPUE0=0 */
PTAPUE &= (unsigned char)~0x81;
/* ### Init_TIM init code */
/* TSC: TOF=0,TOIE=0,TSTOP=1,TRST=1,PS2=0,PS1=0,PS0=0 */
TSC = 0x30; /* Stop and reset counter */
TCH0 = 0x00U; /* Compare 0 value setting */
(void)(TSC0 == 0); /* Channel 0 int. flag clearing (First part) */
/* TSC0: CH0F=0,CH0IE=0,MS0B=1,MS0A=0,ELS0B=0,ELS0A=1,TOV0=0,CH0MAX=0 */
TSC0 = 0x24; /* Int. flag clearing (2nd part) and channel contr. register setting */
TMOD = 0xFFFFU; /* Period value setting */
(void)(TSC == 0); /* Overflow int. flag clearing (first part) */
/* TSC: TOF=0,TOIE=0,TSTOP=0,TRST=0,PS2=0,PS1=0,PS0=0 */
TSC = 0x00; /* Int. flag clearing (2nd part) and timer contr. register setting */
/* ### Init_COP init code */
COPCTL = 0xFF; /* Clear WatchDog counter */
/* ### Init_ADC init code */
/* ADICLK: ADIV2=0,ADIV1=1,ADIV0=0 */
ADICLK = 0x40;
/* ADSCR: COCO=0,AIEN=0,ADCO=1,CH4=0,CH3=0,CH2=0,CH1=0,CH0=1 */
ADSCR = 0x21;
/* ### */
/* Common peripheral initialization - ENABLE */
/* KBSCR: ACKK=1,IMASKK=0 */
KBSCR = (KBSCR & (unsigned char)~0x02) | (unsigned char)0x04;
asm CLI; /* Enable interrupts */
} /*MCU_init*/
/*
** ===================================================================
** Interrupt handler : isrINT_ADC
**
** Description :
** User interrupt service routine.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
__interrupt void isrINT_ADC(void)
{
/* Write your interrupt code here ... */
}
/* end of isrINT_ADC */
/*
** ===================================================================
** Interrupt handler : isrINT_TIMOvr
**
** Description :
** User interrupt service routine.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
__interrupt void isrINT_TIMOvr(void)
{
/* Write your interrupt code here ... */
}
/* end of isrINT_TIMOvr */
/*
** ===================================================================
** Interrupt handler : isrINT_TIMCH0
**
** Description :
** User interrupt service routine.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
__interrupt void isrINT_TIMCH0(void)
{
__RESET_WATCHDOG();
/* Write your interrupt code here ... */
}
/* end of isrINT_TIMCH0 */
/* Initialization of the CPU registers in FLASH */
#ifndef UNASSIGNED_ISR
#define UNASSIGNED_ISR 0xFFFF /* Unassigned interrupt service routine */
#endif
extern void _Startup(void); /* reset interrupt service routine */
void (* const _vect[])() @0xFFDE = { // Interrupt vector table
isrINT_ADC, /* Int.no. 0 INT_ADC (at FFDE) Used */
UNASSIGNED_ISR, /* Int.no. 1 INT_KBI (at FFE0) Unassigned */
UNASSIGNED_ISR, /* Int.no. 2 Reserved2 (at FFE2) Unassigned */
UNASSIGNED_ISR, /* Int.no. 3 Reserved3 (at FFE4) Unassigned */
UNASSIGNED_ISR, /* Int.no. 4 Reserved4 (at FFE6) Unassigned */
UNASSIGNED_ISR, /* Int.no. 5 Reserved5 (at FFE8) Unassigned */
UNASSIGNED_ISR, /* Int.no. 6 Reserved6 (at FFEA) Unassigned */
UNASSIGNED_ISR, /* Int.no. 7 Reserved7 (at FFEC) Unassigned */
UNASSIGNED_ISR, /* Int.no. 8 Reserved8 (at FFEE) Unassigned */
UNASSIGNED_ISR, /* Int.no. 9 Reserved9 (at FFF0) Unassigned */
isrINT_TIMOvr, /* Int.no. 10 INT_TIMOvr (at FFF2) Used */
UNASSIGNED_ISR, /* Int.no. 11 INT_TIMCH1 (at FFF4) Unassigned */
isrINT_TIMCH0, /* Int.no. 12 INT_TIMCH0 (at FFF6) Used */
UNASSIGNED_ISR, /* Int.no. 13 Reserved13 (at FFF8) Unassigned */
UNASSIGNED_ISR, /* Int.no. 14 INT_IRQ (at FFFA) Unassigned */
UNASSIGNED_ISR, /* Int.no. 15 INT_SWI (at FFFC) Unassigned */
_Startup /* Int.no. 16 INT_RESET (at FFFE) Reset vector */
};
/* END MCUinit */
/*
** ###################################################################
**
** This file was created by Processor Expert 3.07 [04.34]
** for the Freescale HC08 series of microcontrollers.
**
** ###################################################################
*