speed of execution - pin change seems too slow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-02 9:00 AM
I just got a simple program running on my STM32f0301k6. I am running the clock off a 20MHz crystal and the core is running off the PLL x 2 so everything is running at 40MHz. This means one cycle executes in 25nS, but if I write a loop like
GPIOB->ODR = 1<<1;
GPIOB->ODR &= ~GPIO_PIN_1;
then i see the pin toggle every 300nS or so. Why is this toggle time such a big difference from 25nS? More confusing to me is that if I change the pin mode to high speed, the toggle time gets much *slower*, measuring about 1.2uS
can anyone explain this to me?
- Labels:
-
GPIO-EXTI
-
STM32F0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-02 9:14 AM
When the compiler compiles code, it translates each line of C/C++ code into one or more native Cortex-M0 instructions. Each of those instructions can take multiple cycles. So you should not expect 1 line of C code to execute in a single processor tick. Optimization level can have a big effect on this.
Pin speed isn't going to affect this directly, but it might affect how the compiler does it job which will indirectly affect results.
Using the BSRR register to toggle pins instead of ODR is preferable since it will only affect the pin you want to change.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-02 9:25 AM
that makes sense. is there a disassembly i can view to see exactly what its doing? I'm not that bothered about the speed but it would be good to understand whats going on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-02 9:33 AM
Usually there is a "Show disassembly" or similar option in most IDEs that will show the native instructions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-03 7:24 AM
thanks, do you know how to view it inside of stm32cudeIDE?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-03 9:43 AM
Window / show view / disassembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-03 9:26 PM
Is it a learning experiment? anything that requires asic type reactivity should use hw assist instead of time lag and execute critical piece of sw. once you add usb or ethernet, if your io bitbang takes time or is jitter sensitive you may end up in the wrong path to reliable implementation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-04 3:43 AM
well i am learning but this is a piece of audio hardware I made. The lower the interrupt time the more 'note perfect' the sound is. So im not using usb or ethernet.
I'm not very experienced so I don't know what you mean by hw assist instead of time lag or 'sw'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-04 3:07 PM
For a fast or accurate pin toggling, PWM, beep tones etc. use timer output channel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-05 1:37 AM
the signal isn't an audio signal, its just used inside a piece of audio hardware. Unless i misunderstood you. it would be great if there was another, better way to achieve what i want. the MCU takes a rising edge and produces a high or low output, like a shift register, except the length of the register and the values in the shift register can be changed
