I want to configure one of the I/O lines to generate a pulse and the frequency of the pulse should be determined by push button input. That is the number of times it is pressed. it's been a while since I worked with MSP430 and I understand TimerA can be used for PWM but I want to be able to control the frequency through push button clicks --------------------------------------- Posted through http://www.EmbeddedRelated.com
MSP430 Pulse Genration
Started by ●October 7, 2014
Reply by ●October 7, 20142014-10-07
On Tue, 07 Oct 2014 12:55:18 -0500, Nivi180 wrote:> I want to configure one of the I/O lines to generate a pulse and the > frequency of the pulse should be determined by push button input. That > is the number of times it is pressed. it's been a while since I worked > with MSP430 and I understand TimerA can be used for PWM but I want to be > able to control the frequency through push button clicksSo, figure out how to generate a pulse with a settable frequency. Then set that aside and figure out how to correctly register push button clicks (which isn't trivial, thanks to contact bounce). Then put 'em together. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●October 7, 20142014-10-07
On Tue, 07 Oct 2014 15:15:04 -0500 Tim Wescott <seemywebsite@myfooter.really> wrote:> On Tue, 07 Oct 2014 12:55:18 -0500, Nivi180 wrote: > > > I want to configure one of the I/O lines to generate a pulse and the > > frequency of the pulse should be determined by push button input. That > > is the number of times it is pressed. it's been a while since I worked > > with MSP430 and I understand TimerA can be used for PWM but I want to be > > able to control the frequency through push button clicks > > So, figure out how to generate a pulse with a settable frequency. > > Then set that aside and figure out how to correctly register push button > clicks (which isn't trivial, thanks to contact bounce). > > Then put 'em together. > > -- > > Tim Wescott > Wescott Design Services > http://www.wescottdesign.comPersonally, I'm always a fan of only checking the sucker 50 times a second or so. That and a single past data point seems to debounce a switch beautifully with the correct amount of effort, assuming anyone other than Barry Allen as the operator. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.
Reply by ●October 7, 20142014-10-07
On 2014-10-07, Rob Gaddi <rgaddi@technologyhighland.invalid> wrote:> Tim Wescott <seemywebsite@myfooter.really> wrote: >> On Tue, 07 Oct 2014 12:55:18 -0500, Nivi180 wrote: >> >>> I want to configure one of the I/O lines to generate a pulse and the >>> frequency of the pulse should be determined by push button input. >>> That is the number of times it is pressed. it's been a while since I >>> worked with MSP430 and I understand TimerA can be used for PWM but I >>> want to be able to control the frequency through push button clicks >> >> So, figure out how to generate a pulse with a settable frequency. > >> Then set that aside and figure out how to correctly register push >> button clicks (which isn't trivial, thanks to contact bounce). > > Personally, I'm always a fan of only checking the sucker 50 times a > second or so. That and a single past data point seems to debounce a > switch beautifully with the correct amount of effort, assuming anyone > other than Barry Allen as the operator.I always found that polling as slow as 10-20 Hz seemed to introduce no user-experience problems and proved quite immune to bounce. If you use a button with some mechanical hysteresis, you can probably go even slower. -- Grant Edwards grant.b.edwards Yow! TONY RANDALL! Is YOUR at life a PATIO of FUN?? gmail.com
Reply by ●October 8, 20142014-10-08
Am 07.10.2014 19:55, schrieb Nivi180:> I want to configure one of the I/O lines to generate a pulse and theNo problem. Choose one of the TAx.x or TBx.x out of the device datasheet as output pin. The datasheet will tell you how to set PxSEL and PxDIR.> frequency of the pulse should be determined by push button input. That is > the number of times it is pressed. it's been a while since I worked with > MSP430 and I understand TimerA can be used for PWM but I want to be able to > control the frequency through push button clicksYou'll need TxCCR0 for frequency control and another TxCCR for duty cycle. Let's say TACCR0 = n and TACCR1 = n/2. Timer in up mode TA0CTL = TASSEL_2 | ID_0 | MC_1 |TACLR; TACCR0 = n; TACCR1 = n>>1; TA0CCTL0 = 0; TA0CCTL1 = OUTMOD_3; // set/reset pwm Use the button input to decrement / increment n and set TACCR0 and TACCR1. You may wish to syncronise to the timer overflow. As mentioned before you have to debounce the button input. Using a timer interrupt is good practise for that. cheers Gunther







