Hi everyone,
The example code for Tiva C LaunchPad Kit (EK-TM4C123GXL ) following:
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
#include "driverlib/pin_map.h"
int main(void)
{
uint32_t ui32Period;
uint32_t ui32DutyCycle;
//Clock Setup
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
ui32Period = 1000;
ui32DutyCycle = 0;
//PWM
//GPIO Configuration
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
// Configure PB6 as T0CCP0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinConfigure(GPIO_PF1_T0CCP1);
GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_1);
//Timer Configuration
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR|TIMER_CFG_B_PWM);
TimerLoadSet(TIMER0_BASE, TIMER_B, ui32Period -1);
TimerMatchSet(TIMER0_BASE, TIMER_B, ui32DutyCycle);
// PWM
TimerEnable(TIMER0_BASE, TIMER_B);
while(1)
{
TimerMatchSet(TIMER0_BASE, TIMER_B, ui32DutyCycle++);
if(ui32DutyCycle >= ui32Period - 1)
ui32DutyCycle = 0;
SysCtlDelay(50000);
}
}
With above configuration for timer, will it count down or count up?
***********
In the document TM4C123G_LaunchPad_Workshop_Workbook.pdf , a sentence to explain for TimerLoadSet(TIMER0_BASE, TIMER_B, ui32Period -1); following:
Note that you have to subtract one from the timer period since the interrupt fires at the zero count.
I don't really understand :( Someone can explain it clearly, pls?!
**********
In the description of TimerLoadSet() and TimerMatchSet function, the parameters ui32Value is the load value and match value.
So, what are load value and match value?
Thanks so much and best regard!