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.

TM4C129EN PWM Configuration

Other Parts Discussed in Thread: TM4C129ENCPDT

Hello

I am trying to get the M0PWM3 output on my TM4C129ENCPDT device to work with no luck.  Just using it as continous freq output to drive a buzzer. I have been through lots of examples and cannot see anything I am missing, but something must be wrong.

Using pin 45 - PF3 - M0PWM3

Here's what I am doing, if you can advise what is wrong would be great.

Hardware pin initialisation

// Output Functions PWM

ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);

// Buzzer

ROM_GPIOPinConfigure(GPIO_PF3_M0PWM3);

 

Buzzer enable Fn

void EnableBuzzer(uint32_tfreq)

{

uint32_t ulPeriod;

ulPeriod =

SysCtlClockGet() / freq;

SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // PWM Clock is system clock

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

// Enable PWM module 0

//Configure PWM0 G1 as UP/DOWN counter with no sync of updates

ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);

ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, ulPeriod);

// set the frequency

ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, ROM_PWMGenPeriodGet(PWM0_BASE, PWM_OUT_3) / 2);

// 50% duty cycle

ROM_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, false);

ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_1);

}

Buzzer ON Function

PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true);

  • Found the answer:

    ulPeriod = SysCtlClockGet() / freq;

    Doesn't work for 4C129ENCPDT, evidently onnly for Blizzard type microcontrollers, something not mentioned in examples or the header file.

    I fixed this by setting the period to the value returned by SysCtlClkSetFreq

    also found

    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, ROM_PWMGenPeriodGet(PWM0_BASE, PWM_OUT_3) / 2);

    doesn't work, changed it to

    ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, ulPeriod/ 2);

    Now all working

  • Hi Barry,

    I'm glad you got it working. Thanks for sharing your solution with others!  Keep in mind the the Peripheral Driver Library User's Guide is an excellent source of information about using TivaWare. It is clearly stated in the SysCtlClockGet description that it is only used for the 123x (Blizzard) devices.

    Regards,

    Sue

  • Greetings Sue,

    Indeed you're right - such fact is "clearly stated" - if one is fully alert and willing to take in a wide spectrum of page data. 

    That said/agreed - what may prove even more valuable here is something beyond "clearly stated."  Suggest the use of high-lighting - and/or other means of "attention grabbing." 

    This represents a fairly significant change in that past experience w/StellarisWare (and its rebrand follow-on) actually, "sets one up" for such pitfall.  (i.e. what past worked - now fails!)

    Quite similar issue has long persisted w/famed NMI default "enjoyed" (deliberate word choice, that) by 2 MCU pins - to the "delight" of most all new users.  That's also "clearly stated."

    What seems superior is, "greatly added emphasis" - to better insure motivated users do not fall victim...

    You of course do not produce the various manuals - are in no way responsible - but may prove a most excellent vehicle to, "better illuminate the lighthouse - when seas are rough - sky jet-black - and shoreline harsh/uninviting..."  (yes, under sail again this 3 day weekend)

    And...kudos to Barry for his persistence & care for others in presenting his nicely detailed solution...

  • Hello Sue

    Sorry for long delay in getting back on this, had problems with CCS which invloved need for complete uninstall and reinstall and then lots of issues tracking down appropriate tivaware examples for use with 4CENCPDT processor.

    I have just checked this manual, which is still called STELLARISWARE USER manual despite me using TIVAWARE, hence I didn't go looking there in the first place.

    The SysCtlClockGet function doesn't mention the tempest devices, SysCtlClockSet does, so you actually have to reference two functions to find out which devices are affected. Perhaps at least a warning to indicate a possible issue exists or even a reference to the alternate function you should use for the other devices.  e.g use only if SysCtlClockSet was used, otherwise use xxx.

    When is TI going to actually have Tivaware documentation?.

  • Hi Barry,

    I'm not sure where you are getting your documentation from, but when you download TivaWare, a docs folder is created that has all the relevant documentation.  We just released TivaWare 2.1 so maybe you need to download TivaWare again.  We removed the StellarisWare User's Guide about a year ago when we released TivaWare.  You can also find the Driver Lib User's Guide here.

    Regards,

    Sue

  • Hello Sue

     

    Thanks for the reply.

    I just used the link you gave me in your answer, thanks for clarifying.

    I am using TIRTOS 1_21_00_09 which has tivaware 2.0.1.11577a associated with it, so this should be the latest shouldn't it. Also using XDC tools 3_25_03_72, have XDCtools 3_25_04_88 installed but it doesn't seem to recognise Tiva device, gives me an error when I try to use - missing Boot.aem4f.

    So I think I have all the latest, will refer to the contained documentation.

    Thanks again for the reply

    Regards

    Barry

  • Hello Sue, just one more question

     

    If I cannot use SysCtlClkGet for the 4C129 processor, how do I find the clock speed?

    Have searched everywhere and cannot find how to do this.

    All the examples which came with my dev kit use this fn?

  • Hi,

    Here, last thread: http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/324693.aspx

    Petrei

  • I tried calling SysCtlFrequencyGet() and get an undefined symbol error.

    Its not part of the functions in the latest Tivaware that I am using.

  • Hi,

    What Tiva version do you use? 

    Did you observed my writing: _SysCtlFrequencyGet - starting with underscore? It is located near the top of the functions in file sysctl.c.

    EDIT: You may have problems using this function since it is declared static but this function is used inside SysCtlClockFreqSet to return the value of the system clock frequency, which may not be the expected value.

    So take care.

  • I am using tirtos_1_21_00_09, with TivaWare_C_Series-2.0.1.11577a

    My processor is 4C129ENCPDT.

    If the function is in sysctl.c as static, it is not available external without changing the sysctl.c file.

    I don't wish to do a hack.

    I wanted to know if there is a standard function available in the library to get the frequency for the devices not supported by the StsCtlClockGet function. From you answer it would seem that TI internally use a function which may be suitable but this is not published from the library.

    I guess I can take a copy and add to my own project to test, would be good if there was a standard function I didn't need to extract and copy into my code.

  • Hi,

    Mainly you do not need a separate function to get the operating system frequency since the function SysCtlClockFreqSet returns for your use the value computed by that hidden function (And you already used that..). All you have to do is to check the returned value against the desired value. This is a change for TM4C129. 

    If you need, you make a copy of that function or ....

    And I suggest to spend five minutes to open and read the functions documentation and the code - it is not hard, does not harm. There are many hidden/unspoken useful things...

    Petrei

  • My program is under TIRTOS and as such I don't call SysCtlClockFreqSet myself the RTOS does when it sets things up.  I can use the RTOS drivers to initialise the SPI but PWM is not contained in the RTOS drivers so I use the standard tivaware functions which need to know the clock frequency.  I can hardcode this value to match what TIRTOS is configured for but that's not ideal as it can be forgotten.

    So whilst what you suggest is possible it is something that will easily break with new release of TIRTOS or change in the settings. The __SysCtlFrequencyGet function needs to be passed a crystal frequency so more hacking here.

  • Just in case anyone else wants to get the CPU frequency when running under TIRTOS

    BIOS_cpuFreq stores the frequency

    BIOS_getCpuFreq allows you to read it into your own variable.

    If your not using TIRTOS just save a copy of the returned frequency when you call SysCtlClockFreqSet