TI E2E Community
MSP430 Ultra-Low Power 16-bit Microcontroller Forum
adc to pwm on msp430g2231
Can i controll the brightness of four different LED by using PWM according to changing values read from four different variable POT with the help of ADC?
I think it is impossible to do it with four different channel, at least how can i do it only one channel namely let the brightness of LED changes according to a variable POT.
mehmet celikCan i controll the brightness of four different LED by using PWM according to changing values read from four different variable POT with the help of ADC?
However, you can do sort of a PWM in plain software for any number of signals you have free GPIO pins available. It will require tight coding and use a significant amount of CPU time, but it is possible.
For a single PWM output, things are relatively simple. Use the ADC to obtain an input voltage, e.g. with a pot between VCC and GND. So you'll get a value of 0..1023 for 0..100%.
Now write 1022 (!) to TACCR0 and let the timer run in up mode. Then program TACCTL1 to RESET/SET mode and configure the port pin of TA0.1 for module output.
TACCR1 gets the value from the ADC.For any ADC value x from 1 to 1023 this will result in a duty cycle of x/1023. The only exception is x=0. In this case you'll have to switch the port pin off manually.
But keep in mind that the human perception of brightness is not linear. So the optical impression of the resulting LED brightness won't be what you'd expect from the POT position.So for a better result, vreate a translation table that converts all possible 1024 ADC results into a value from 0 to 100. Write 99 to TACCR0 instead of 1022. And the 1..100 result (for 0, again you'll have to switch the port pin off manually) to TACCR1. THis allows for a fine control of the brightness according the human perception courve.
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
Thanks for your answer Michael.
Now I'm a little confused. Because there should a timer both of operation of ADC and PWM. How can I settle the timer.
mehmet celik Because there should a timer both of operation of ADC and PWM. How can I settle the timer.
A timer has a cycle time which you can control eithe rby limiting the number of ticks per cycle (using CCR0 and tierm up mode) or by changing the speed of the timer ticks (the source clock speed).However, all periodical events always happen once per cycle. If you want a timer to trigger your ADC conversions as well as producing a PWM output, you need to find a common base. The timer conversion frequency then needs to be the PWM cycle frequency. Also, the trigger signal for the timer is produced by a CCR unit, which also produces the PWM output. So you need to use a constant trigger point, e.g. the raising edge of the PWM signal at begin of the cycle. However, a PWM DC of 0 would actually stop the ADC triggering then.
Arternatively you can trigger an interrupt at tiemr overrun and manually start the conversions inside the ISR. THis will introduce some jitter ot the start of each conversion, but the average sampling frequency will still be correct.
You need to determine your exact parameters. Required PWM frequency, required sampling frequency etc. However, it is possible that you won't find a combination that fits all of your requirements. Then you have the wrong processor and need one with more timers (or with timers with more CCR units)
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.