how mc68hc908qt4 handles the interrupt.
I used it to receive PWM signals from the TCS3200 sensor How to do that?
I tried to do some on my own, but seemed to go in without interruption
/* Global Variables */
volatile unsigned int edge_count = 0; // Rising edge counter
volatile unsigned int total_edges = 0; // Edges in 10ms window
/* TIM Initialization */
void TIM_Config(void)
{
// 1. Stop and reset TIM
TSC = 0x04; // TSTOP=1 (Stop counter), TRST=1 (Reset counter)
// 2. Configure prescaler and modulo for 3.2MHz clock
TSC_PS2 = 0; // PS[2:0]=011 (Prescaler
TSC_PS1 = 1;
TSC_PS0 = 1; // TIM clock = 3.2MHz/8 = 400kHz (2.5μs period)
TMODH = 0x0F; // Modulo value = 4000 (400kHz * 0.01s = 4000 cycles)
TMODL = 0xA0; // 0x0FA0 = 4000
// 3. Configure Channel 0 for rising edge capture
TSC0 = 0x00; // Clear configuration
TSC0_ELS0A = 0; // ELS0B:ELS0A=00 (Capture rising edge)
TSC0_ELS0B = 0;
// 4. Start TIM counter
TSC_TSTOP = 0; // Enable counting
}
/* Main Function */
void main(void)
{
TIM_Config();
while(1)
{
// Detect input capture events
if(TSC0_CH0F)
{
edge_count++; // Increment edge counter
TCH0L; // Dummy read to clear capture flag
TSC0_CH0F = 0; // Clear channel flag
}
// Handle 10ms overflow
if(TSC_TOF)
{
total_edges = edge_count; // Save result
edge_count = 0; // Reset counter
TSC_TOF = 0; // Clear overflow flag
// Frequency = total_edges / 0.01s = total_edges * 100 (Hz)
// Add your frequency calculation/display logic here
}
}
}
That's my program,If you have a timer or input capture about this chip.Can give me a reference? THINK YOU.