Jump to content
Sign in to follow this  
Mastaan

PWM Signals at 50Hz

Recommended Posts

Hi, 

I need to generate 4 pwm signals at 50 HZ, they need to run with out interruption. I know the TM4C123G6PM has 2 pwm blocks, but is it possible to access them through Energia? 

 

can I use Analog.write(); ?

 

Someone please help.

 

Thank you.

Share this post


Link to post
Share on other sites

Yes and no.

analog write does use the timer/pwm function. However, 50Hz is much too low to use under default settings. Such a long period cannot be accomodated for.

You better run a timer and toggle the PWM signals in an ISR.

Share this post


Link to post
Share on other sites

Ok I solved it, because I need to generate only 50 Hz signals, I went to wiring_analog.c, there I found 

 
void analogWrite(uint8_t pin, int val) {
    //
    //  duty cycle(%) = val / 255;
    //  Frequency of 490Hz specified by Arduino API
    //
    PWMWrite(pin, 255, val, 50);
}
 
and I just changed 490 to 50 and boom solved...
 
If you want different frequencies, at different pins you can use PWMWrite (pin, resolution, val, freq); function, but make sure to #include wiring_analog.c.
 
You can download this software from TI to look at what pins can do what, and visually plan out your pins. The pin #s aren't the same as Energia, just cross check.
 

Share this post


Link to post
Share on other sites

Yes and no.

analog write does use the timer/pwm function. However, 50Hz is much too low to use under default settings. Such a long period cannot be accomodated for.

You better run a timer and toggle the PWM signals in an ISR.

 

tm4c123gx micro-controllers has builtin PWM blocks, that does all the proper duty cycle and frequency division from the clock cycle without the use of the processor, all you need to do is set the right control and status registers, and I am pretty sure the PWM function in energia uses these PWM blocks to generate the signal.

 

Thank you.

Share this post


Link to post
Share on other sites

@@Mastaan The MSP430 has Timer blocks that allow them to be configured as PWM outputs, I suspect those in the TM4C are similar in behaviour. Still, I think 50Hz is too low for them to reach, since they're basically counting clock cycles from any system clock. You could manage it when using an external 32kiHz crystal, since you'd have to count only 32768/50 cycles (655.36 cycles, roughly 655) to get to 50 Hz.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×