Close

Velocity Timer

A project log for The Field Stack - NEMA23/34 FOC

If we win the Hackaday price, we will make BETA give aways. FOC field-oriented control for NEMA23/34

juan-antonio-sren-epJuan-Antonio Søren E.P. 04/20/2023 at 07:570 Comments
float speed = (4 * pi / 65536) * 168000000 / ((float)timer2 - 1.0f);
 

I was able setup a secondary (slave) timer on the encoder input. This means we time/track every rising edge on one of the encoder inputs. This can also be every encoder pulse, but we need the larger range to count.  

Chat.GPT was so kind to help with the conversion to rad/s.

TIMER2 CCR1 - >  1585
Rad/s - >  20.34
TIMER2 CCR1 - >  1560
Rad/s - >  20.66
TIMER2 CCR1 - >  1621
Rad/s - >  19.88
TIMER2 CCR1 - >  1728
Rad/s - >  18.65
TIMER2 CCR1 - >  1611
Rad/s - >  20.01
TIMER2 CCR1 - >  1575
Rad/s - >  20.47
TIMER2 CCR1 - >  1550
Rad/s - >  20.80
TIMER2 CCR1 - >  1662

This is the output with a 20 rad/s target using the conversion above:

Discussions