CODE
//
// Set the clocking to run directly from the crystal.
//
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_6MHZ);
// SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
//////////////////////////////PWM INIT//////////////////////////////
// 1 - Enable the PWM clock by writing a value of 0x0010.0000
// to the RCGC0 register in the System Control module.
SYSCTL_RCGC0_R = 0x00100000;
// 2 - In the GPIO module, enable the appropriate
// pins for their alternate function using the GPIOAFSEL register.
GPIO_PORTB_AFSEL_R = 3; // enable alternate function
// 3 - Configure the Run-Mode Clock Configuration (RCC)
// register in the System Control module
// to use the PWM divide (USEPWMDIV) and set the divider
// PWMDIV) to divide by 2 (000).
SYSCTL_RCC_R = 0x00D03AC0; //USEPWMDIV set /2
// 4 - Configure the PWM generator for countdown mode with immediate
//updates to the parameters.
//¦ Write the PWM0CTL register with a value of 0x0000.0000.
//¦ Write the PWM0GENA register with a value of 0x0000.008C.
PWM_2_CTL_R = 0;
PWM_2_GENA_R = 0x0000008C;
PWM_2_GENB_R = 0x0000080C;
// 5 - Set the period. For a 25-KHz frequency,
// the period = 1/25,000, or 40 microseconds. The PWM
// clock source is 10 MHz; the system clock divided by 2.
// This translates to 400 clock ticks per
// period. Use this value to set the PWM0LOAD register.
// In Count-Down mode, set the Load field
// in the PWM0LOAD register to the requested period minus one.
// Write the PWM0LOAD register with a value of 0x0000.018F
PWM_2_LOAD_R = 0x0000018F; //400
// 6 - Set the pulse width of the PWM1 pin for a 25% duty cycle.
// ¦ Write the PWM0CMPA register with a value of 0x0000.012B.
PWM_2_CMPA_R = 0x0000012B; // 300
PWM_2_CMPB_R = 0x00000063; //100
// 8 - Start the timers in PWM generator 1.
// ¦ Write the PWM0CTL register with a value of 0x0000.0001.
PWM_2_CTL_R = 0x01;// update
// 9 - Enable PWM outputs.
PWM_ENABLE_R = 0x3F;
while (1)
{}
// Set the clocking to run directly from the crystal.
//
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_6MHZ);
// SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
//////////////////////////////PWM INIT//////////////////////////////
// 1 - Enable the PWM clock by writing a value of 0x0010.0000
// to the RCGC0 register in the System Control module.
SYSCTL_RCGC0_R = 0x00100000;
// 2 - In the GPIO module, enable the appropriate
// pins for their alternate function using the GPIOAFSEL register.
GPIO_PORTB_AFSEL_R = 3; // enable alternate function
// 3 - Configure the Run-Mode Clock Configuration (RCC)
// register in the System Control module
// to use the PWM divide (USEPWMDIV) and set the divider
// PWMDIV) to divide by 2 (000).
SYSCTL_RCC_R = 0x00D03AC0; //USEPWMDIV set /2
// 4 - Configure the PWM generator for countdown mode with immediate
//updates to the parameters.
//¦ Write the PWM0CTL register with a value of 0x0000.0000.
//¦ Write the PWM0GENA register with a value of 0x0000.008C.
PWM_2_CTL_R = 0;
PWM_2_GENA_R = 0x0000008C;
PWM_2_GENB_R = 0x0000080C;
// 5 - Set the period. For a 25-KHz frequency,
// the period = 1/25,000, or 40 microseconds. The PWM
// clock source is 10 MHz; the system clock divided by 2.
// This translates to 400 clock ticks per
// period. Use this value to set the PWM0LOAD register.
// In Count-Down mode, set the Load field
// in the PWM0LOAD register to the requested period minus one.
// Write the PWM0LOAD register with a value of 0x0000.018F
PWM_2_LOAD_R = 0x0000018F; //400
// 6 - Set the pulse width of the PWM1 pin for a 25% duty cycle.
// ¦ Write the PWM0CMPA register with a value of 0x0000.012B.
PWM_2_CMPA_R = 0x0000012B; // 300
PWM_2_CMPB_R = 0x00000063; //100
// 8 - Start the timers in PWM generator 1.
// ¦ Write the PWM0CTL register with a value of 0x0000.0001.
PWM_2_CTL_R = 0x01;// update
// 9 - Enable PWM outputs.
PWM_ENABLE_R = 0x3F;
while (1)
{}
даташит, страница 505 http://www.ti.com/lit/ds/symlink/lm3s811.pdf
Заметил, что если выставив биты в регистре PWM2INTEN на прерывания, регистр PWM2ISC начинает изменять свое значение, то есть появляются статусы прерывания по счетчику, равному "ZERO" и "PWM2LOAD". На выходе опять же ничего.
"PWM2INTEN - These registers control the interrupt and ADC trigger generation" - может быть он отвечает за выставление Пина в логическую единицу при достижении "ZERO" и "PWM2LOAD" ?