About the interrupt frequency of stm32duino?

Post here first, or if you can't find a relevant section!
Post Reply
elina
Posts: 1
Joined: Fri Apr 01, 2022 1:08 pm

About the interrupt frequency of stm32duino?

Post by elina »

Hi everyone, please forgive my poor english, here is my google translation. I am new to stm32duino, I am now going to count a 200khz pulse, originally I used arduino uno @16mhz, the rising edge of the pulse Triggering the interrupt counts in the interrupt and prints it through the serial port, but the counted value is not accurate and is smaller than the actual value. I think the frequency of 200 kHz may be too high, so the atmega328 crystal oscillator is replaced with 20mhz, and the value is accurate. Later, I used stm32f030 @48mhz and did not get the accurate value, and then I tried stm32g030 @64mhz, and the same value was obtained. They are all inaccurate values. Finally, the correct value is obtained by using stm32f103c6t6 @72mhz. I am confused why the crystal of atmega328p is 20mhz and cannot be count accurately, and the main frequency of stm32 is much higher than 20mhz. However, it cannot be counted accurately, Why? What am I missing? THX!!!
Below is the code, the code for atmega328p is the same

Code: Select all

int i = 0;
void count (void)
{
  i++;
}

void setup()
{
  Serial.begin(9600);
  pinMode(PA4, INPUT_PULLUP);
  attachInterrupt(PA4, count, RISING);
}

void loop()
{
  Serial.println(i);
  delay(3000);
}
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: About the interrupt frequency of stm32duino?

Post by fpiSTM »

Some comments:
- Serial use IT and have higher priority
- CPU freq does not mean it is the same freq for EXTI. EXTI frq is probably linked to AHB freq which can be less than the system core clock
- Pay attention to EXTI pin used has EXTI is not exactly linked to one GPIO pin but to its number (PA10 = PB10= ...), GPIO port is ignored.
Post Reply

Return to “General discussion”