DMA write to timer/counter period register

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

cross mob
soma_3858611
Level 1
Level 1
First like given

I need to use DMA to read from flash/ram and write to timer/counter period register. Using software API to write the period register works until the period (cycle time) gets smaller than a few micro-seconds.

Is there a way to do this on the provided timer/counter components for PSoC 5/6? I need this for high speed stepper / servo control.

Please help.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

songtaoma,

Attached is RAM-DMA-Timer demo, which shows DMA configuration for 16,24 and 32-bit. The Timer must be reset for new RegValue to take immediate effect. Various schematic arrangements are possible depending on Timer_1 clock speed. You need to find best fit at high speed. Remember that DMA transfer takes time (~10 BUS_CLOCK), and its nrq output synced only with BUS_CLOCK, so it has to be synced with Timer_1 clock. Also, to reset Timer_1, the reset signal is synchronous and has to last long enough to catch Timer_1 input clock.

/odissey1

RAM-DMA-Timer_01a.png

RAM-DMA-Timer_01b.png

View solution in original post

7 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

songtaoma,

please specify bit size of the counter (8,16,24,32) for DMA transfer. Note that writing period to the counter does not change period until the counter rolls over.  So if previous period is long, you have to wait until counter reaches period and flips over. Check KBAs:

Dynamically Changing the Period Value of Timers, Counters, and PWMs in PSoC® 3/4/5LP – KBA88172

Best Practices to Reload the Compare and Period Values of Timer/PWM/TCPWM/Counter Component - KBA905...

High Signal on Compare Output When Period Is Changed in Firmware – KBA89231

It is always advised to upload your demo project showing the issue (1. Build->Clean. 2 File->Create Archive bundle->Minimal. 3. Delete Generated_Source folder in created ZIP to reduce space)

/odissey1

0 Likes

odyssey1,

Thanks for the quick reply.

I can settle for 16-bit timer/counter to start with. Eventually I would like to use 24-bit or 32-bit if not too much trouble to do so.

Unfortunately, KBA88172 tells about using API function to write the period register, which I have been using that method since 2014, but it is not what I am asking. The only thing I am interested in is to update/write the period register by DMA, not API functions. The reason is, as I have mentioned, API update may fail as the period (cycle time) is only a few micro-seconds.

KBA90554 makes me feel bad: if period register (of a timer/counter) is only supposed to be updated after timer/counter is stopped, how can I use PSoC counter/timers to generate constant acceleration speed ramp up pulses (e.g. for high speed steppers) up to or above 100k steps or micro-steps per second? I know I can do this easily with FPGA (have done that with FPGA for more than 10 years).  For constant acceleration (or constant deceleration), the timer/counter period register needs to be updated once for each every cycle.

Is there a way to get around this? If not, I have to look for something else.

0 Likes

Have you solve the 32- bit question?

I think if you can separate the case question one by one, it may be solved higher efficient?

0 Likes
lock attach
Attachments are accessible only for community members.

songtaoma,

Attached is RAM-DMA-Timer demo, which shows DMA configuration for 16,24 and 32-bit. The Timer must be reset for new RegValue to take immediate effect. Various schematic arrangements are possible depending on Timer_1 clock speed. You need to find best fit at high speed. Remember that DMA transfer takes time (~10 BUS_CLOCK), and its nrq output synced only with BUS_CLOCK, so it has to be synced with Timer_1 clock. Also, to reset Timer_1, the reset signal is synchronous and has to last long enough to catch Timer_1 input clock.

/odissey1

RAM-DMA-Timer_01a.png

RAM-DMA-Timer_01b.png

This looks exactly as what I need, thank you very much for the timely reply. I have just downloaded the ZIP file, and I will try it out as soon as possible.

0 Likes

I have just modified the project a little bit to run it on my CY8CKIT-050 PSoC 5LP kit, it runs as expected, thank you very much.

My next step is to create a VCS (Variable Cycle Stepping) pulse generator (for linear speed acceleration/deceleration) based on this great example of yours.  To do so, I need a 16-bit counter in stead of timer, but I am pretty sure the same principle applies as is.

Best Regards,

Songtao

0 Likes

songtaoma,

Timer and Counter are practically the same component, so it should work fine.

/odissey1

0 Likes