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.
Hi @wazi
Checking at your TIM initialization I can give you the following feedback:
By setting the value of TSC by 0x04 you will have the following configuration
TOF=0; TOIE=0; TSTOP=0; TRST=0; PS2=1; PS1=0; PS0=0;
If what you are looking is for TSTOP be set, the value charge on TSC should be 0x20
Also, for the rising edge capture setting I recommend you check Table 14-3. Mode, Edge, and Level Selection of datasheet.
Even though we do not have and specific example code for this configuration you can take as reference the following document, where it explains furthermore TIM module on HC08.