I am very new to using MSP430s and am trying to work on two separate projects using it:
1) To take in an input signal from a function generator and calculate the duty cycle, frequency, etc from the signal. I know that to do this I'll have to use a timer and some type of capture, but I'm having a lot of difficulty getting started on it.
2) To use the MSP430 as a function generator itself, to create square waves with a defined duty cycle and frequency. I'm having similar trouble getting started with this one, because I know I'll have to use a timer again, but I'm not sure how to define it to output the signal properly.
I have an MSP430-F2013 and an MSP430-RF2500 that I can work with to program each of these.
Any assistance you can give would be greatly appreciated. Thanks!
Akshay Raghu I'm having a lot of difficulty getting started on it.
Basically, the timer is a counter. It counts clock pulses. When its coutner registe roverflows, it will trigger an interrupt. That's all.Now there are the Capture-Compare units. They can trigger an interrupt and/or change an output pin when the timer count reaches a certain value, or they can copy the current timer count when an external event occurs.
So get the frequency, you configure a CCR unit for capture mode. So it captures the current tiemr count when a positive (or negative, or both) edge is detected and triggers an interrupt. The difference in teh captured count for two risign edges gives you the interval T (and 1/T is the frequency).For the duty cycle, you'll have to capture both edges, and teh DC is the relation of thr time between rising and falling edge and falling and next rising edge.
Akshay RaghuI'm not sure how to define it to output the signal properly.
In any case, you'll have to configure the I/O pins for timer use. See the digital I/O chapter of the users guide. And look up which port pins are available for which CCR unit input/output in your MSPs device datasheet.
_____________________________________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.
Hi Jens-Michael,
Thanks very much for your help. I used one of the example codes about setting up a PWM output for MSP430 RF2500(F2274), and edited it slightly to generate a PWM with a period of 50ms and a 40% duty cycle. Would you be willing to take a look and recommend any changes?
In addition, using the RF transceivers in the pair of RF2500s, I would like to be able to transmit the PWM signal from one to the other. I've gone through the example code given in the SimpliciTI installation, but I still don't understand the syntax or setup for that to work very well, and I wasn't able to find any other threads in this forum that go into what code should be added to the current code to transmit from one and receive at the other. Can you point me to a tutorial or another thread in this forum that you know of that would get me started on adding code to the pair of transceivers to transmit/receive the signal?
Thanks again for your help!
#include <msp430.h> int main (void) { WDTCTL = WDTPW + WDTHOLD; // Disable Watchdog Timer P1DIR |= 0x04; // Defines P1.1 and P1.2 as outputs P1SEL |= 0x04; CCR0 = 50000 - 1; // (CCR0+1)/1MHz * 1000 = 50 ms CCTL1 = OUTMOD_7; CCR1 = 20000; BCSCTL1 = CALBC1_1MHZ; // Configures DCO clock at 1 MHz. DCOCTL = CALDCO_1MHZ; // Configures DCO clock at 1 MHz. TACTL = TASSEL_2 + ID_0 + MC_1 + TACLR; // Chooses SMCLK as source, no divider, Up-mode, clears counter __BIS_SR(LPM0_bits); }
hi,IMHO you are in a too early stage to perform wireless communication, so try study and fully grasp every example come from TI then try some more deep task and if you have a solid programmer experience you can afford analysis of simpliciTI code. Otherwise is the same as pretending to run when you born few days ago.
Regards
Roberto
Please login & click Verify Answer if this post answered your question.
Akshay Raghuedited it slightly to generate a PWM with a period of 50ms and a 40% duty cycle. Would you be willing to take a look and recommend any changes?
And, well, the 1MHz calibrated frequency isn't exactly stable 1MHz. It is only as close as the DCO in this MSP can get to 1MHz at 25°C and Vcc=3V. And only as an average over (at least) 32 clock cycles (usually, 5ms averaging time are given for the precision in the datasheet).So expect some drift with temperature change, some frequency error and also a little jitter if the PWM frequency isn't a multiple of 32 timer ticks.
For the RF2500, I don't have any experience. However, there are several threads in this forum. (I usually skip them :) )
Jens-Michael Gross It looks like it shoudl work as expected. Except one thing: P1.1 will only output a 1µs pulse every 50ms - if you set OUTMOD_7 for CCTL0 too. Currently, it will remain low
I think the forum stole the end of what you were trying to say there :). Were you trying to say that the code as I had it will output a 1µs pulse every 50ms instead of a 20ms pulse every 50ms? If so, could you explain why setting OUTMOD_7 for CCTL0 also is necessary to get the desired output?
And thanks for letting me know that the 1MHz frequency is not exact; I am aware that for a truly accurate output I would need to add a crystal between XIN and XOUT, but for the time being the 1MHz calibrated frequency should suffice.
Thanks again!
Akshay RaghuI think the forum stole the end of what you were trying to say there :)
P1.2 is controlled by CCTL1 and should give you the desired 50ms 40% DC signal.