2012-11-29 08:26 PM
hi:
I want 24 Mhz clock generation for my sensor, how can i do that without MCO1? MCO2 can be option. but by MCO2 i get clock as 21.4Mhz etc but not exactly 24MHz, the sources and dividers didn't make right combination for 24MHz accurate. with timer I select timer3 counter clock at 21Mhz. I can generate frequencies upto 210KHz. by CCR1=50 , which is correct. but when CCR1=10 frequency should be 2.1Mhz, but it didn't. I use toggle mode. and I set the GPIO speed at 50Mhz why is this happening. #timer-clock-generation2012-11-30 03:37 AM
You'd need to run the part on a clock divisible by 24 MHz, and from a timer on a bus running at such a frequency, ie not APB1 as 84 MHz is not a multiple of 24 MHz
The USB clock, or PLLI2S might be a viable alternative source.2012-11-30 03:54 AM
// STM32 PWM 24 MHz (TIM1 CH1 PA.08) STM32F4 Discovery - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void RCC_Configuration(void)
{
/* --------------------------- System Clocks Configuration -----------------*/
/* TIM1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*-------------------------- GPIO Configuration ----------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect TIM1 pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
}
/**************************************************************************************/
void TIM1_Configuration(void)
{
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
uint16_t Period;
Period = (SystemCoreClock / 24000000); // Must be divisable
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0; // Dump 1X clock into timer
TIM_TimeBaseStructure.TIM_Period = Period - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Enable TIM1 Preload register on ARR */
TIM_ARRPreloadConfig(TIM1, ENABLE);
/* TIM PWM1 Mode configuration */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = Period / 2; // 50%
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
/* Output Compare PWM1 Mode configuration: Channel1 PA.08 */
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
/* TIM1 Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
/* TIM1 enable counter */
TIM_Cmd(TIM1, ENABLE);
}
/**************************************************************************************/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
TIM1_Configuration();
while(1); // Don't want to exit
}
/**************************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d
'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/**
* @}
*/
/**************************************************************************************/
2012-11-30 11:20 AM
2012-12-02 08:57 PM
thanks clive. i will update status.
is it feasible to source other device through timer toggeling? will the wavefrom is like clock from MCO1/MCO2 exactly or will it degraded to some extent?2012-12-03 06:51 AM
I believe most of the pins share a common driver design, which is quite capable of driving into a secondary device. If you need it to drive multiple devices, a very long trace, or high capacitive load, consider buffering it.