EmbeddedRelated.com
Forums
The 2026 Embedded Online Conference

MSP430 Pulse Genration

Started by Nivi180 October 7, 2014
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
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.com
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.com
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. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix.
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
Am 07.10.2014 19:55, schrieb Nivi180:
> I want to configure one of the I/O lines to generate a pulse and the
No 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 clicks
You'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
The 2026 Embedded Online Conference