Mastaan 0 Posted March 8, 2015 Share Posted March 8, 2015 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. Quote Link to post Share on other sites
roadrunner84 466 Posted March 9, 2015 Share Posted March 9, 2015 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. Quote Link to post Share on other sites
abecedarian 330 Posted March 9, 2015 Share Posted March 9, 2015 Not sure how appropriate it would be since it's 50% duty, or if it would run 4 channels, but there is the tone(pin, frequency [, duration]) function in Energia. http://energia.nu/reference/tone/ http://energia.nu/guide/tutorial_tone/ Quote Link to post Share on other sites
Mastaan 0 Posted March 11, 2015 Author Share Posted March 11, 2015 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. http://www.ti.com/tool/tm4c_pinmux Quote Link to post Share on other sites
Mastaan 0 Posted March 11, 2015 Author Share Posted March 11, 2015 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. Quote Link to post Share on other sites
roadrunner84 466 Posted March 11, 2015 Share Posted March 11, 2015 @@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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.