You are here

Changing out timer 5 in timer.c

2 posts / 0 new
Last post
Teslafly
Offline
Last seen: 1 year 6 months ago
Joined: 2017-09-21 08:55
Posts: 17
Changing out timer 5 in timer.c

I am trying to free up some pins for auxiliary pwm for fans / brake lights.
As timer 5 is mostly clobbered by critical pins, and timer 1,3,4,8 are also in use. timer 2 seems like the best bet as 3/4 outputs are available in my pinout.

I would like to switch over chibios systick to tim5 off tim2 so I can use tim2 for aux pwm. Is this a really bad idea?

I see vesc-fw is using timer 5 for general timing of functions, but with the only possibly critical function being in "update_rpm_tacho()" from mcpwm.c. So it seems like it may be ok to switch timer.c to a less used /lower resolution timer (tim10/11). Considering the isr durations should be quite fast, they should have no problem fitting in the 16 bit timer. (max ~0.8ms at sysclk/2). The update_rpm_tacho() may overflow that timer at the fastest clock though.

Anything critical I'm missing that timer.c does?
I'll probably disable it completely (return 0 for everything) to test switching around the timers before fixing it up to use a different one.

Perhaps replacing timer.c with the chibios virtual timers would be a better idea? http://www.chibios.org/dokuwiki/doku.php?id=chibios:book:kernel_vt

Teslafly
Offline
Last seen: 1 year 6 months ago
Joined: 2017-09-21 08:55
Posts: 17

Looks like this was moved to timer 5 from 12 when timer.c was created. so should be safe to put it back on timer 12/another 16 bit timer.
https://github.com/vedderb/bldc/commit/65298263b6ff09791b014d36d787632e9...