This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Cannot simulate PWM waveform on keil

Hi everyone.

I am learning TM4C123G microcontroller. I wrote a simple PWM programme and tried to simulate it on keil simulator.

But it didnt work. The waveform was just a DC straight line. It took me few days to debug but I still find no solution. Help please.

There is my PWM initialization code. Thanks

void PWMInit(uint32_t frequency, uint32_t dutyCycle){
SYSCTL_RCGCPWM_R |= 0x01; //activate PWM0
SYSCTL_RCGCGPIO_R |= 0x02; //activate GPIOB
while ((SYSCTL_PRGPIO_R & 0x02) != 0x02); //wait for GPIOB

//PB6
GPIO_PORTB_AFSEL_R |= 0x40;
GPIO_PORTB_PCTL_R &= ~0x0F000000;
GPIO_PORTB_PCTL_R |= 0x04000000;
GPIO_PORTB_AMSEL_R &= ~0x40;
GPIO_PORTB_DIR_R |= 0x40;
GPIO_PORTB_DEN_R |= 0x40;

SYSCTL_RCC_R = (SYSCTL_RCC_R & ~0x000E0000) | 0x00100000; //use PWM divider and configure for /2 divider
PWM0_0_CTL_R &= ~0x01; //re-loading down-counting mode
PWM0_0_GENA_R = 0xC8; // low on LOAD, high on CMPA down
PWM0_0_LOAD_R = (80000000 / 2 / frequency) - 1;
PWM0_0_CMPA_R = (PWM0_0_LOAD_R + 1) * dutyCycle / 100 - 1;
PWM0_0_CTL_R |= 0x01;
PWM0_ENABLE_R |= 0x01;

  • Correct me if I'm wrong here - but the Keil's uVision IDE provides just a "generic" MCU implementation as target for simulation, without any specific peripheral hardware. That means, no PWM to simulate on this target.

    For an actual test, you would need a real target.

  • Agree w/poster f.m.

    In days/years past - when MCU Eval boards were much higher cost - simulators were in favor.   Yet today - w/smaller/cheaper LPads (and the like) - use of the simulator (most always a "compromise" btw) proves, "Second Best."

    IMO - time/effort spent in "Simulator study & set-up" is better spent in exercising REAL hardware - which always - is (simulator), "compromise-free."

    Again - as f.m. notes - you may simulate code running w/out heavy (or sometimes light) ties to MCU peripherals - and just this requirement (knowing what does - what does not work under simulation) dictates the purchase of a low cost Eval Board...