Hi guys
I'm tryng to realize a pwm modulation to drive a servo motor and I have found something strange.
The following code works well as you can see in image1.
//This code will PWM the leds
#define PART_LM4F120H5QR true
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/pin_map.h"
int main(void) {
unsigned long ulPeriod_led_f1, dutyCycle_led_f1, ulPeriod_led_f2, dutyCycle_led_f2, ulPeriod_led_f3, dutyCycle_led_f3;
unsigned long ciao;
// 40 MHz system clock
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
ciao = SysCtlClockGet();
//ulPeriod_led_f3 = 20000;
//dutyCycle_led_f3 = 11500;
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinConfigure(GPIO_PF2_T1CCP0);
GPIOPinConfigure(GPIO_PF3_T1CCP1);
GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_2 );
GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_3 );
// Configure timer 0 this timer outputs to pf1 (led)
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
TimerConfigure(TIMER1_BASE, (TIMER_CFG_SPLIT_PAIR|TIMER_CFG_A_PWM|TIMER_CFG_B_PWM));
TimerControlLevel(TIMER1_BASE, TIMER_BOTH, 0);
TimerPrescaleSet(TIMER1_BASE, TIMER_A, 0);
TimerMatchSet(TIMER1_BASE,TIMER_A, 400);
TimerLoadSet(TIMER1_BASE,TIMER_A, 800);
//24000
ciao = TimerLoadGet(TIMER1_BASE,TIMER_A);
TimerEnable(TIMER1_BASE, TIMER_BOTH);
while(1) {
// TimerMatchSet(TIMER1_BASE, TIMER_A, dutyCycle_led_f2 = dutyCycle_led_f2+1);
// TimerMatchSet(TIMER1_BASE, TIMER_B, dutyCycle_led_f3 = dutyCycle_led_f3+2);
// if (dutyCycle_led_f2 >= ulPeriod_led_f2 - 1) dutyCycle_led_f2 = 0;
// if (dutyCycle_led_f3 >= 1000) dutyCycle_led_f3 = 0;
}
}
A simple variation in the prescaler (1 instead of 0) causes a different behaviour as you can see in image2.
TimerPrescaleSet(TIMER1_BASE, TIMER_A, 1);
what's wrong?
Can you help me?
Thank you so much
Matteo