MHz frequencies on OUTPUT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2022-05-01 5:32 AM
hey there
I have a stm32f103 blue pill board which I wish to generate MHz frequencies on pinC13.
I have used TIM1. it starts and interrupts and on each interrupt I toggle PC13
like so
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if(htim->Instance == TIM1)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_13);
}
}
also I set APB1 to 64MHz in Cube.
and here is my TIM1 config(this part is generated by Cube so I just bring up the Prescaler and Period part )
htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 1;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
as you can see with these Prescaler and Period I should have frequency around 64000000/(0+1)(1+1)~32MHz
but on Oscilloscope I see around 125kHz!
I know my oscilloscope TIM/DEV is limited to us but at least I expect to see to parallel lines showing high frequency
what is the problem?
- Labels:
-
STM32F1 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2022-05-01 5:41 AM
You should use the TIM to drive/toggle pin a directly, without interrupts, if you don't want to saturate the MCU.
Depending on how efficient your interrupt code is, a few hundred KHz is the ceiling.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2022-05-01 5:46 AM
@Community member "You should use the TIM to drive/toggle pick a directly, without interrupts, if you don't want to saturate the MCU."
you mean should I use PWM connected to TIM1?
"Depending on how efficient your interrupt code is, a few hundred KHz is the ceiling."
I guess it is quit efficient, cause I have nothing else in my code...
so how can I generate MHz frequencies on a pin?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2022-05-01 6:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2022-05-01 7:34 AM
Should have read pin, not pick, darn auto-complete..
The TIM should have PWM and Toggle modes. Doesn't have to be TIM1, pick a TIMx/CHx associated with a pin.
>>I guess it is quite efficient, cause..
You're using HAL, the processor is counting instructions, figure at least 2x the friction there.
Up vote any posts that you find helpful, it shows what's working..
