This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Pulse Counting and Function Generator

Other Parts Discussed in Thread: SIMPLICITI

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 said:
    I'm having a lot of difficulty getting started on it.

    What's your problem then? THe basic concept of timers? How to use them for couting external events?

    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 Raghu said:
    I'm not sure how to define it to output the signal properly.

    That's rather a PWM signal output than a function generator.
    Here the CCR units are configured to change an output pin when the timrr counts to a certain value and change it again when the timer overflows. The relation of the first interval and the second gives the duty cycle.
    To allow finer control over the PWM frequency, one of the CCR units, CCR0, can make the timer overflow at a certain value rather than at 65535. The timer runs in up mode then, from 0 to CCR0, then overflows to 0 again.

    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.

  • 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.

     

  • Akshay Raghu said:
    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?

    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

    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 said:
     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 Raghu said:
    I think the forum stole the end of what you were trying to say there :)

    No, I was just not writing it out in detail.
    You configured P1.1 for module output, but you didn't configure CCTL0 to output something on this pin. So it remains in OUTMOD_0 which is the content of the OUT bit, which in turn ins zero by default. If you change CCTL0 to OUTMOD_7, you'll see a short (1 timer tick) pulse at the beginning (or end) of each cycle.

    P1.2 is controlled by CCTL1 and should give you the desired 50ms 40% DC signal.

**Attention** This is a public forum