MSP430 Pulse Genration

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

formatting link

Reply to
Nivi180
Loading thread data ...

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 
 Click to see the full signature
Reply to
Tim Wescott

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.
Reply to
Rob Gaddi

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?? 
 Click to see the full signature
Reply to
Grant Edwards

Am 07.10.2014 19:55, schrieb Nivi180:

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.

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

Reply to
Gunther Mannigel

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.