Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

XMC™ Forum Discussions

User11870
Level 1
Level 1
Hello,
I am using xmc4800 to control stepper motors, is there any way to generate a desire amount of pulses using timers?
Thank you!
0 Likes
3 Replies
User10215
Level 4
Level 4
First like received
Hi mophong,

yes there is a way. The CCU-Slices of the XMC4800 can be interconnected with each other. Have a look at the chapter 23.8 of the XMC4800 v1.1 reference manual. This shows you what the slices of the CCU4 peripheral can be connected to or what connects to the slices.
For instance, on page 23-141 you can see that one of the inputs of the slice CCU40.CC40 is connected to CCU40.ST1 which is the status bit of slice CCU40.CC41. This status bit changes its state whenever the timer in the slice hits the programmed compare value. Have a read through the chapter about the CCU4-peripheral in order to find out how this status bit works in detail.

So, you can program a slice to count the edges on its input. The input is connected via the status bit to a slice that's producing the pulses for the stepper. By programming a value into the period register of the counting slice and enabling the period match interrupt you can also get an interrupt after your programmed number of pulses were counted.

Regards,
Niclas
0 Likes
User11870
Level 1
Level 1
Niclas, thank you for your answer.
In this way, it seems that I have to stop the pulse generator in the the counter ISR? It may not be a good way, what if the interrupt latency is too large, several unexpected pulses may be generated?
0 Likes
User10215
Level 4
Level 4
First like received
Hi mophong,

yes, in this way you'd have to stop pulse generation in the ISR. It depends on your application if this solution fits you. With deactivated FPU the Cortex-M4 processor needs 12 CPU-cycles to enter an ISR...with the 144MHz of the XMC4800 that would be 83ns. Also you'll need some CPU-cycles to stop the timer.
Let's just say the processor needs 150ns to enter the ISR and stop the timer...now it's a question of how long your pulses are? And would you be able to chose a suitable priority for the ISR because the 150ns don't take into account waiting times for higher priority ISRs.

If you look for a hardware solution maybe there's the possibility of using the status bit of the counting timer and feed it back to the pulsing timer slice where it switches off the timer. However I'm not entirely sure how the status bit behaves in a capturing timer (i.e. the counting timer) since I don't know if you can use the compare-register in that timer. That would be something you have to look up.
Also, not only the status bit can be used to link two timers together. CCU4 and CCU8-slices can be connected via the service request lines which means any event (e.g. period match, compare match etc.) that can trigger an interrupt could be used to do something in the connected timer. This information can be found in the corresponding "Interconnect"-chapter of the peripheral.
A possible hardware connection I saw with a quick glance at the reference manual would be something like this:

CCU8-slice (configured as pulsing timer) status bit ---> ERU ---> CCU4-slice configured as counter with enabled period match on a service request line that connects to the pulsing CCU8-slice.

In this configuration the ERU is only there to interconnect the CCU8-slice with the CCU4-slice since, as far as I know, there is no direct connection beetween CCU8 and CCU4. The CCU8-slice can then be configured to stop its timer once the input of that slice sees a configurable edge (that would be produced by the counting CCU4-slice).

So, to cut a long story short, the potential is there for a hardware-solution of stopping the pulsing timer. However it requires working out the correct hardware-signal-connections between the timer slices...

Regards,
Niclas
0 Likes