1
\$\begingroup\$

In the current project, we're decoding a digital signal with an STM32F103C8 microcontroller. Channel 1 of timer 2 is configured in input capture mode and DMA is set up to write the captured timer values into a circular buffer. This works except it only records the rising edge.

Unlike other STM32 microcontroller, the STM32F103C8 does not seem to be able to capture on both edges. In the TIM_CCER register, bit CC1P selects either the rising or the falling edge. There is no option for both edges.

enter image description here

enter image description here

Have we overlooked something, and it is possible after all?

Or what are our options to achieve it some other way (preferably without additional external components)?

Triggering an interrupt for each edge won't work as the signal is too fast (600kbit/s).

\$\endgroup\$
2
  • \$\begingroup\$ You'll have to read further in the manual to figure out if it supports setting both bits at once. If not possible, maybe use 2 channels rising + falling? Though you'd need to trigger somehow to sync them. \$\endgroup\$
    – Lundin
    Commented Apr 14, 2023 at 12:40
  • \$\begingroup\$ @Lundin Thanks. We've implemented it with 2 pins, 2 timer channels and 2 DMA channels. Synchronization isn't a problem for this particular protocol. \$\endgroup\$
    – Codo
    Commented Apr 15, 2023 at 14:51

1 Answer 1

1
\$\begingroup\$

From this link: AN4776 - General purpose timer cookbook for STM32

Configure the active edge polarity. Some of the STM32 microcontrollers embed timers with inputs sensitive for either falling, rising or both edges (like STM32F2 microcontrollers); other STM32 families embed timers that have their inputs only sensitive for either rising or falling edges (like STM32F1 microcontrollers).

So it seems to be a limitation of the family STM32F1. Without changing the hardware (using more pins or external components), I can't think of any solution.

\$\endgroup\$
4
  • \$\begingroup\$ So what are our options now? Using more pins is okay, using additional external components would be the last resort. \$\endgroup\$
    – Codo
    Commented Apr 15, 2023 at 13:14
  • \$\begingroup\$ If you have enough timers and DMA channels do it twice (one for rising and one for falling). As you will always have a falling after a rising edge, if you properly use the DMA (proper increments), you will have the output correctly ordered in the circular buffer. \$\endgroup\$
    – MF3
    Commented Apr 15, 2023 at 13:21
  • 1
    \$\begingroup\$ So we went with 2 pins, 2 timer channels and 2 DMA channels. Unfortunately, increments are not configurable. So the 2 circular buffers must be merged in software. \$\endgroup\$
    – Codo
    Commented Apr 15, 2023 at 14:53
  • \$\begingroup\$ STM32 is dangerous like that, features you'd expect any MCU to have aren't always present. I think it is because there's so many STM32 and some are quite dated by now... although at the time I still designed with HCS08 8-bitters in new projects (over 10 years back), they always had the option to trigger on both edges. \$\endgroup\$
    – Lundin
    Commented Apr 17, 2023 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.