17.06.2009, 01:08 PM
Habe bis jetzt alles ohne das OS gemacht, Vertrauen ist gut Kontrolle ist besser,
mir geht es nur um den STM32.
Für zeitkritische Anwendungen wenn ein Atmega nicht mehr langt,
oder wenn man zu faul ist beim proggen.
z.B.:
The TIMxCLK frequency is set to 72 MHz, the Prescaler is 0 so the TIM2 counter
clock is 72 MHz. so the minimum frequency value to measure is 1100 Hz.
TIM2 is configured in PWM Input Mode: the external signal is connected to
TIM2 Channel2 used as input pin.
To measure the frequency and the duty cycle we use the TIM2 CC2 interrupt request,
so In the TIM2_IRQHandler routine, the frequency and the duty cycle of the external
signal are computed.
The "Frequency" variable contains the external signal frequency:
Frequency = TIM2 counter clock / TIM2_CCR2 in Hz,
The "DutyCycle" variable contains the external signal duty cycle:
DutyCycle = (TIM2_CCR1*100)/(TIM2_CCR2) in %.
/*******************************************************************************
* Function Name : TIM2_IRQHandler
* Description : This function handles TIM2 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM2_IRQHandler(void)
{
/* Clear TIM2 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
/* Get the Input Capture value */
IC2Value = TIM_GetCapture2(TIM2);
if (IC2Value != 0)
{
/* Duty cycle computation */
DutyCycle = (TIM_GetCapture1(TIM2) * 100) / IC2Value;
/* Frequency computation */
Frequency = 72000000 / IC2Value;
}
else
{
DutyCycle = 0;
Frequency = 0;
}
}
mir geht es nur um den STM32.
Für zeitkritische Anwendungen wenn ein Atmega nicht mehr langt,
oder wenn man zu faul ist beim proggen.
z.B.:
The TIMxCLK frequency is set to 72 MHz, the Prescaler is 0 so the TIM2 counter
clock is 72 MHz. so the minimum frequency value to measure is 1100 Hz.
TIM2 is configured in PWM Input Mode: the external signal is connected to
TIM2 Channel2 used as input pin.
To measure the frequency and the duty cycle we use the TIM2 CC2 interrupt request,
so In the TIM2_IRQHandler routine, the frequency and the duty cycle of the external
signal are computed.
The "Frequency" variable contains the external signal frequency:
Frequency = TIM2 counter clock / TIM2_CCR2 in Hz,
The "DutyCycle" variable contains the external signal duty cycle:
DutyCycle = (TIM2_CCR1*100)/(TIM2_CCR2) in %.
/*******************************************************************************
* Function Name : TIM2_IRQHandler
* Description : This function handles TIM2 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM2_IRQHandler(void)
{
/* Clear TIM2 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
/* Get the Input Capture value */
IC2Value = TIM_GetCapture2(TIM2);
if (IC2Value != 0)
{
/* Duty cycle computation */
DutyCycle = (TIM_GetCapture1(TIM2) * 100) / IC2Value;
/* Frequency computation */
Frequency = 72000000 / IC2Value;
}
else
{
DutyCycle = 0;
Frequency = 0;
}
}