Hi,
I'm using the Tiva C Series to drive step motors and I try to figure out how to control my step motors step by step. I would like to be able to count the number of steps my motors are doing.
To do it, I use a timer set to the PWM period in clock ticks (not sure if this is the right way to do it). My sysclock is configured to 80Mhz:
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
And I use a 4 div PWM clock:
ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_4);
Unfortunatelly, the PWM clock is isn't 20Mhz at all. If I display in the UART the value from ROM_SysCtlPWMClockGet() I get 1,17MMHz instead. What's wrong wit ROM_SysCtlPWMClockSet() ?
If I understand, I should set my timer in sysclock period. So to set my timer to the period of sysclock, I should do:
TimerClockSourceSet(TIMER1_BASE, TIMER_CLOCK_SYSTEM); ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, 1); // should set to sysclock?
But I also set the period of the PWM from ROM_PWMGenPeriodSet() to change the speed of rotation. The period of the PWM is set in PWM clock ticks, rights? So if I set the PWM period like:
ROM_PWMGenPeriodSet(..., 1000);
It should be 1000 PWM clock ticks => 4000 timer ticks.
So to set my step counter, I do:
clockRatio = ROM_SysCtlClockGet() / ROM_SysCtlPWMClockGet(); microStepCount = microStepsToDo * pwmPeriod * clockRatio;
But with the wrong ratio it won't work. Any idea?