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.

PWM debug on Keil for TM4C123

Hi All,
I am sorry for throwing this post about display PWM signal on Logic Analyzer in Keil again.
I did some search but it seems the problem has not solved yet. I generated PWM signals on TM4C123
(following Dr. Valvano's course ) and I could observe the PWM signal in a real oscilloscope. However,
when I tried to display PWM on Logic Analyzer in Keil, there were some errors about writing to/reading from
registers and these seemed weird. For example, the orginal code for activating PWM0 is:
     SYSCTL_RCGCPWM_R |= 0x01; // 1) activate PWM0-orginal
and this was error when I used step in (F11) to debug.
If the above code is replaced by
     SYSCTL_RCGC0_R |= 0x00100000; // 1) activate PWM0
then there is no error any more.
These two lines of code should be the same but I did not understand why it caused error. I also checked
the address and everything seems correct.
After fixing this problem, any actions to PWM0 is an error
     PWM0_0_CTL_R &= 0x00000000; // 4) re-loading down-counting mode
    PWM0_0_GENA_R = 0xC8; // low on LOAD, high on CMPA down
     // PB6 goes low on LOAD
     // PB6 goes high on CMPA down
     PWM0_0_LOAD_R = period - 1; // 5) cycles needed to count down to 0
     PWM0_0_CMPA_R = duty - 1; // 6) count value when output rises
     PWM0_0_CTL_R |= 0x00000001; // 7) start PWM0
     PWM0_ENABLE_R |= 0x00000001; // enable PB6/M0PWM0

Can anyone share some experience on this issue? I attach all my project files (zipped in a .zip file)for detail.
Any recommendations are appreciated.
Thanks,
Tuan

void PWM0A_Init(uint16_t period, uint16_t duty){
SYSCTL_RCGC0_R |= 0x00100000; // 1) activate PWM0
// SYSCTL_RCGCPWM_R |= 0x01; // 1) activate PWM0-orginal
SYSCTL_RCGCGPIO_R |= 0x02; // 2) activate port B
while((SYSCTL_PRGPIO_R&0x02) == 0){};
GPIO_PORTB_AFSEL_R |= 0x40; // enable alt funct on PB6
GPIO_PORTB_PCTL_R &= ~0x0F000000; // configure PB6 as PWM0
GPIO_PORTB_PCTL_R |= 0x04000000;
GPIO_PORTB_AMSEL_R &= ~0x40; // disable analog functionality on PB6
GPIO_PORTB_DEN_R |= 0x40; // enable digital I/O on PB6
SYSCTL_RCC_R = 0x00100000 | // 3) use PWM divider
(SYSCTL_RCC_R & (~0x000E0000)); // configure for /2 divider
PWM0_0_CTL_R &= 0x00000000; // 4) re-loading down-counting mode
PWM0_0_GENA_R = 0xC8; // low on LOAD, high on CMPA down
// PB6 goes low on LOAD
// PB6 goes high on CMPA down
PWM0_0_LOAD_R = period - 1; // 5) cycles needed to count down to 0
PWM0_0_CMPA_R = duty - 1; // 6) count value when output rises
PWM0_0_CTL_R |= 0x00000001; // 7) start PWM0
PWM0_ENABLE_R |= 0x00000001; // enable PB6/M0PWM0
}

PWM_4C123_Tcode.zip

  • Hello Tuan,

    As far as I understand, the only issue you are facing is with the tool from Keil. If this is the case, Keil should be able to address this issue better than us. I have never used this tool so can't comment on the best way to use the tool.

    However, you would most likely have to use an appropriate debugging adapter like J-Link or ULink2 to be able to interface with their Logic Analyzer. The Stellaris ICDI (present on LaunchPads) will not work. You might also have to configure J-Link or ULink2 to use the SWD interface so that the trace functionality can be used.

    Thanks,
    Sai
  • Hi Sai,
    Thanks for your suggestion. I downloaded codes to real board and watched the PWM output with an oscilloscope and it was as expected. It just some issues in Keil and I want to know how to fix since debug in Logic Analyzer in Keil will save a lot of time for me.
    Thanks,
    Tuan
  • And - should not such issues fall under the course designer, or instructor - and not convert this forum to, "Dumping Ground" for course short-falls?

  • Hi Sai,
    Thank you so much for your recommendations. I actually tested codes with real board and the PWM output displayed as expected on an oscilloscope. The issue only came when I debugged in Keil simulator. I will try to see how to fix this since it will save time in the future before going to real circuit.
    Best,
    Tuan
  • Hi cb1,
    The course was great and fun. If you search course "Shape the world" in edx.org, I am sure you will have same opinion. I just want to figure how to fix the issue I met.
    Thanks,
    Tuan
  • Re: course is great...I doubt that my friend. Do not MANY course users land here (just like you) - having crashed/burned? How "great" is that? Would not a "great" course "anticipate" and provide (some) guidance - to remedy such?

    Minus (any) interest in your course - it's (unusual) for many (most) simulators to, "look deeply" into the MCU's peripherals - instead they focus greatly upon the MCU's core.

    My firm uses "pro/paid" version of IAR (multi-seats) - what I've described holds true there - I suspect w/Keil, as well.

    Indeed simulators have value - yet there ARE limitations - I suspect you've encountered one. And a "great" course would have noted such - isn't that true?

    And "great" course would have (noted) the speed, ease, efficiency of, "Tried, True, Tested" vendor API - as opposed to (always & only) forcing the use of DRM! (untried, untrue, untested - each/every application!)