AnsweredAssumed Answered

generate 8 Mhz Clock on port pin and monitor the port pin status

Question asked by p.jagdish on Oct 25, 2013
Latest reply on Oct 25, 2013 by Clive One
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 ISR

void 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;

  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 */

//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.