2013-10-25 03:27 AM
Hello everyone,
I am trying to interface a CCD to STM32f4 discovery kit. I need to generate a clock of 4MHz and toggle couple of pins when the clock is high to to get the output from CCD. I referred some examples from ST peripheral library. And I configured Timer 8 to generate the update interrupt after every 125nsec so that i can toggle a pin in interrupt and generate clock of 4 MHz Also I can monitor the clock pin status and toggle some other pin as per my requirement. But the maximum freq by which i am able to toggle the pin is 875 KHz. Below is the timer 8 config function and the ISRvoid TIM8_Config(void)
{ NVIC_InitTypeDef NVIC_InitStructure;/* TIM1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);/* Enable the TIM1 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 15; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 8000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 1;//665; TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
/* Prescaler configuration */ TIM_PrescalerConfig(TIM8, PrescalerValue, TIM_PSCReloadMode_Immediate); /* TIM Interrupts enable */ TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE); /* TIM1 counter enable */ TIM_Cmd(TIM8, ENABLE); } //following is the interrupt routine void TIM8_UP_TIM13_IRQHandler(void) { if (TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM8, TIM_IT_Update); fnTogglePin(CCD1_MC); // using this function i am toggle the pin to generate clock } } Is this possible what ever I am trying to achieve using timer 8? please help me in using this timer to generate freq from 4 MHz to 8 Mhz What value should i put in Prescalar and time period while config? One more thing, i know that using PWM I can generate clock of requried freq on specific port pins. but in that case I won't come to know when my port pin has gone high. I actually want to monitor the clock output generated by microcontroller. Please guide to achieve the requriement. Thanks..2013-10-25 03:47 AM
The processor isn't going to be able to interrupt at MHz rates, it's wholly impractical.
Make the Prescaler the smallest number, in this case ZERO, put the larger factor in the Period.The TIM should be able to generate 8 MHz using PWM or Toggle modes. The Update and CCx interrupt can be used to determine transition points of the signal, but obviously not at the rates you're suggesting.