Jump to content
L.R.A

Tiva PWM module TM4C1294NCPDT

Recommended Posts

So this is folowing this on e2e http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/357157.aspx?pi307171=1

 

This actualy works the same for the TM4C123 but you have to take into account it has not 1, but 2 PWM modules and the pins are diferent

Actualy this is not quite right, according to igor, thank you for the info:

 

It should not work the same on the TM4C123, since the libraries and constants are different.

(At least if it does work, that is surprising).

 

Specifically:

TM4C1294 uses PWMClockSet(base, divider)

TM4C123 uses SysCtlPWMClockSet( divider )

(Clock get calls are also different).

 

The divider constants also have different names, e.g.: 

TM4C1294: PWM_SYSCLK_DIV_1

TM4C123: SYSCTL_PWMDIV_1

 

 

 

Finally i found out why my code didn't work on some outputs, so here it is the working code

 

This code should output a frequency of about 250hz in the PF_1 port, it was made using Energia.

/*


*/
#define PART_TM4C1294NCPDT
#include "driverlib/pin_map.h"
#include "driverlib/pwm.c"
#include "inc/hw_ints.h"
#include "driverlib/pwm.h"
#include "driverlib/interrupt.c"
#include "driverlib/sysctl.c"
#include "driverlib/Timer.c"
#include "driverlib/gpio.c"

void setup()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlDelay(10);

GPIOPinConfigure(GPIO_PF1_M0PWM1);

GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);

PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_8);

PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

    uint32_t freq = 1 / 250 * (F_CPU/8);
    uint32_t duty = freq * 0.5;
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, freq);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, duty);

PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
 
void loop() {
// put your main code here, to run repeatedly:
} 

My problem was i didn't know that i had to specify the generator, and tought that i could use wichever i chosed

I attached the image explaining. It's from the datasheet of tm4c1294ncpdt page 1680.

post-2405-14264605455727_thumb.png

Share this post


Link to post
Share on other sites

So i have here a code also for the TM4C1294 that it's made with intent to control a servo with extra resolution, 4000 diferent positions in theory of course it depends on the servo ability to recognize this. But it's the idea it's to prove the advantage of using this module.

The value of the duty should be betwen 1000 and 5000 wich is 0.5ms and 2ms.

 

This is untested since i don't have a single servo right now and not gona have for a while but would apreciate anyone testingit

/*


*/
#define PART_TM4C1294NCPDT
#include "driverlib/pin_map.h"
#include "driverlib/pwm.c"
#include "inc/hw_ints.h"
#include "driverlib/pwm.h"
#include "driverlib/interrupt.c"
#include "driverlib/sysctl.c"
#include "driverlib/Timer.c"
#include "driverlib/gpio.c"

void setup()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlDelay(10);

GPIOPinConfigure(GPIO_PF1_M0PWM1);

GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);

PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_64);

PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

uint32_t freq = 1 / 50 * (F_CPU/64); // 37500
uint32_t duty = freq * 0.5;  //Max resolution here is 0,5 micro-seconds.
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, freq);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, duty);

PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}

void loop() {
// put your main code here, to run repeatedly:
} 

Share this post


Link to post
Share on other sites

With a cheap chinese towerpro SG90 clone the second code didn't quite work.

The servo twitches enough that you can feel an ever so faint vibration as you hold it on board reset, not quite a full blown spasm, even the haptic feedback from my phone is more noticeable. After awhile it will center and stay there.

 

I won't blame the code without a proper logic analyzer or oscilloscope to test the output though. Ultimately the servo did something and it is hardly a high quality known brand so it could itself be the fault here (its actually a very cheap and nasty servo, I have no branded ones)

Share this post


Link to post
Share on other sites

 

This actualy works the same for the TM4C123 but you have to take into account it has not 1, but 2 PWM modules and the pins are diferent

 

It should not work the same on the TM4C123, since the libraries and constants are different.

(At least if it does work, that is surprising).

 

Specifically:

TM4C1294 uses PWMClockSet(base, divider)

TM4C123 uses SysCtlrPWMClockSet( divider )

(Clock get calls are also different).

 

The divider constants also have different names, e.g.: 

TM4C1294: PWM_SYSCLK_DIV_1

TM4C123: SYSCTL_PWMDIV_1

 

One of those places, like setting the clock, where the libraries differ, but the tools give you little help in finding it out.

Share this post


Link to post
Share on other sites

It should not work the same on the TM4C123, since the libraries and constants are different.

(At least if it does work, that is surprising).

 

Specifically:

TM4C1294 uses PWMClockSet(base, divider)

TM4C123 uses SysCtlrPWMClockSet( divider )

(Clock get calls are also different).

 

The divider constants also have different names, e.g.: 

TM4C1294: PWM_SYSCLK_DIV_1

TM4C123: SYSCTL_PWMDIV_1

 

One of those places, like setting the clock, where the libraries differ, but the tools give you little help in finding it out.

 

Thanks, i forgot they were diferent, sometimes i lose track betwen uControlers tiny diferences

Share this post


Link to post
Share on other sites

With a cheap chinese towerpro SG90 clone the second code didn't quite work.

The servo twitches enough that you can feel an ever so faint vibration as you hold it on board reset, not quite a full blown spasm, even the haptic feedback from my phone is more noticeable. After awhile it will center and stay there.

 

I won't blame the code without a proper logic analyzer or oscilloscope to test the output though. Ultimately the servo did something and it is hardly a high quality known brand so it could itself be the fault here (its actually a very cheap and nasty servo, I have no branded ones)

It's possible that the servo can't recognize the signal well, and the duty is betwen values for the servo readings? Maybe try using other values to check?

 

Thank you for testing :)

Share this post


Link to post
Share on other sites

About the code for controling the servo

 

I was testing  with the logic analyzer and the wave it seems everytigh alright.

The wave had a frequency of about 49.80Hz. The duty values to be used aren't actualy from 1000-5000, they were 100ms over, so the values need to be a bit lower.

They should be 937 for about 0.5ms positive width and 4688 for about 2.5ms 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...