SM32F4 variable frequency generation with PWM w

Discussion created by karpavicius.linas on Jun 14, 2018
Latest reply on Jun 14, 2018 by cedric Hottier

I am making balancing robot project, where i need to drive Trinamic stepper drivers as my main motors. ( i can have 200x256/rot resolution )


It gives much advantages and single disadvantage, it needs quite high stepping frequency in order to make motors turn smoothly. First i was thinking about doing this in software at 100KHz systic speed, but granulation will be so low..


So i want to use hardware of PWM, with TIM1 i could make frequency sweep, i just can't figure out how to make prescaller work in linear fashion
with TIM2 i can have 32b period register, but for some reason i can't change it, it is stuck after configuration, i can change width no problem, but not counter period. Any one know why it is happening ?

       TIM2->CCR1=CCR; // fixed for 200ns impulse
       TIM2->ARR =P; // should give me 32b of frequency resolution, it would be perfect, but i can't change it

IF any one knows how to make this work, please put out me  of misery