Stellaris Launch Pad : EK-LM4F120XL CPU : LM4F120H5QR
Tool Soft CCS V5.5
I refer to "StellarisR LM4F120H5QR Microcontroller" ,
but I can not make the PWM output duty to 0 ,using the PWM mode of GPTM.
I was sure the output waveform on an oscilloscope by changing the parameters.
I changed the comment out of the parameters in order,below.
How do I parameter value?
I am not good at English,sorry.
-------------------------------------------------------------
Parameter summary
pulse cycle
4ms
pulse width
1. full ----OK
I refer to "Figure 11-6. CCP Output, GPTMTnMATCHR > GPTMTnILR" of "StellarisR LM4F120H5QR Microcontroller".
2. full ? 1 clock ----OK
3. 3ms ----OK
I refer to "Figure 11-8. CCP Output, GPTMTnILR > GPTMTnMATCHR" of "StellarisR LM4F120H5QR Microcontroller".
4. 1 clock ----OK
5. 0 ----NG
I refer to "Figure 11-7. CCP Output, GPTMTnMATCHR = GPTMTnILR " of "StellarisR LM4F120H5QR Microcontroller".
-------------------------------------------------------------
source "main.c"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_timer.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
void main(void) {
unsigned long ulCycle = 0, // PWM frequency counter
ulDuty = 0, // duty counter
ulSysClock = 0, // system clock frequency
ulDelay = 0 ; // set change delay
unsigned long ulCycleScale = 0, //freequency prescale counter
ulDutyScale = 0; //duty prescale counter
unsigned long ulPwmN = 0 ;
//SysClock frequency 40MHz
SysCtlClockSet( SYSCTL_SYSDIV_5|SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN );
ulSysClock = SysCtlClockGet() ; //40,000,000 = 40 MHz
//400,000 :1s -> 1s/100 ->*1 = 3 ms
ulDelay = ulSysClock / 1000 * 1 ;
//configure gptm
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM);
TimerControlLevel(TIMER0_BASE, TIMER_B, 0); // Timer0-A High-Active
// GPIO configure
// GPIO_PIN_2: PWM set change timing monitor blue
// GPIO_PIN_1: PWM out Timer0-A port B6 red
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, 0x00);
GPIOPinConfigure(GPIO_PF1_T0CCP1);
GPIOPinTypeTimer(GPIO_PORTF_BASE, GPIO_PIN_1);
// TimerEnable(TIMER0_BASE, TIMER_B); //Timer0 start
//PWM value SET
//PWM cycle 4ms
ulCycle = ulSysClock / 1000 * 4;
ulCycleScale = ulCycle >> 16;
ulCycle &= 0xFFFF;
TimerPrescaleSet(TIMER0_BASE, TIMER_B, ulCycleScale);
TimerLoadSet(TIMER0_BASE, TIMER_B, ulCycle);
//Pulse width SET
/* full
ulDutyScale = ulCycleScale;
ulDuty = ulCycle + 1;
*/
/* full-1
ulDutyScale = 0;
ulDuty = 1;
*/
/* 3 ms
ulCycle = ulSysClock / 1000 * 4;
ulDuty = ulCycle - ( ulSysClock / 1000 * 3 ) ;
ulDutyScale = ulDuty >> 16;
ulDuty &= 0xFFFF;
*/
/* 1
ulDutyScale = ulCycleScale;
ulDuty = ulCycle -1 ;
*/
/* 0 NG */
ulDutyScale = ulCycleScale;
ulDuty = ulCycle ;
/* */
TimerPrescaleMatchSet(TIMER0_BASE, TIMER_B, ulDutyScale);
TimerMatchSet(TIMER0_BASE, TIMER_B, ulDuty);
TimerEnable(TIMER0_BASE, TIMER_B); //Timer0 start
//set change timing monitor
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,4);
SysCtlDelay(ulDelay);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2,0);
}