cancel
Showing results for 
Search instead for 
Did you mean: 

set timer to pin

pedropbr
Associate II
Posted on December 01, 2010 at 17:52

set timer to pin

6 REPLIES 6
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:17

Hi rbpeter,

You have to do it by yourself.

1- Configure PC6 in output push pull

2- In the Interrupt Toggle the PC6 state

MCU Lüfter

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:17

1- PC6 in output:

  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  /* Configure PC6 output pin */

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

2-  Toggle PC6

    GPIOC->BSRR = 0x00000040;

pedropbr
Associate II
Posted on May 17, 2011 at 14:17

Thanks for the answer. This is what I was trying to do and it sets bits to PC6 when the timer interrupts, so:

using a 36Mhz frequency I get 550 Overflows so I see 275Hz in the oscilloscope.

But changing the question: Is it possible to force the timer to use the crystal's clock (25Mhz)?

Thanks
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:17

Hi rbpeter,

I have found in the reference manual the following descrption:

The counter clock can be provided by the following clock sources:

�? Internal clock (CK_INT) --> The system clock

�? External clock mode1: external input pin (TIx) --> Timer channels (CH1, CH2, ...)

�? External clock mode2: external trigger input (ETR) --> TIMx_ETR

�? Internal trigger inputs (ITRx): using one timer as prescaler for another timer

So I think it is not possible to increment your timer directely by external crystal.

If you provide much more details, perhaps I can find an idea.

Herzlich,

MCU Lüfter

picguy2
Associate II
Posted on May 17, 2011 at 14:17

For output you might want to use PWM rather that ISR and GPIO.

> Is it possible to force the timer to use the crystal's clock (25Mhz)?

You should look at the clock tree.  RM0008 at just over 1K pages is for your reading pleasure and general edification.  Read it all - become your local expert.

Xtal => PLL multiplier => PLLCLK

or

Xtal => PLLCLK directly

then

PLLCLK => AHB Prescaler (div 1..512 in powers of 2) => (next line)

AHB Prescaler => APB1 Prescaler (div 1..16) => (@36MHz max) APB1

APB1 Prescaler => *1 or *2 => timers 2..7

AHB Prescaler => APB2 Prescaler => *1 or *2 => timers 1 & 8

$1 8-bit microcontrollers have clock options.  STM32 has more options. 
Posted on May 17, 2011 at 14:17

The timer clocks can be anything you want to set the system too. You can use the prescaler to get counts to fit in the 16-bit counter. You can program the timers to output frequency to a pin directly, and you can control the frequency and duty cycle (pulse width).

With a PLL clock of 72 MHz, you can get timers on both the APB1 and APB2 running at that speed given they way the timer clocks are gated, compared to the main peripheral clocks.

Not sure why 25 MHz from the oscillator is particularly desirable for you, perhaps you can provide some more specifics.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..