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.

MSP430 RF2500 - Use UART to alter PWM Output

Other Parts Discussed in Thread: SIMPLICITI

Hi all, 

I would appreciate some help with solving this problem. Essentially, what I would like to do is program a pair of MSP430 RF2500 boards so that Board A will output a PWM signal with a specified period and duty cycle, which is simple enough, and which I have already done. However, I would then like to be able to program Board B from my computer with a different set of values for the period and duty cycle, and send those values to Board A using the UART, where the values of TBCCR0 and TBCCR1 are changed, so the PWM changes as desired.

The code I have right now is pretty simple (copied below), basically just toggling the port with the PWM of Board B when I press the button on Board A, and does not use UART at all:

#include "mrfi.h"
#include "radios/family1/mrfi_spi.h"

int main(void)
{
BSP_Init(); // Initializes MSP430
P1REN |= 0x04; // Enables resistor for P1.2 (button)
P1IE |= 0x04; // Enables interrupts for P1.2.
MRFI_Init(); // Initializes CC2500-MSP430 Connection
mrfiSpiWriteReg(CHANNR, 0x13); // Changes channel for transmission.
MRFI_WakeUp(); // Wakes up Radio, puts in Idle state.
MRFI_RxOn(); // Switches Radio on.

P4SEL |= 0x10; // Sets P4.4 (Pin 9) to Timer B1
P4DIR |= 0x10; // Sets P4.4 (Extension Pin 9) as output

TBCCR0 = 50000-1; // (CCR0+1)/1MHz * 1000 = 50 ms
TBCCTL1 = OUTMOD_7; // OUTMOD_7 counts up to TBCCR1, then
// resets, then counts up to TBCCR0, then sets.
TBCCR1 = 20000; // (CCR1/CCR0) * 100 = 40%

BCSCTL1 = CALBC1_1MHZ; // Configures clock at 1 MHz.
DCOCTL = CALDCO_1MHZ; // Configures clock at 1 MHz.

TBCTL = TBSSEL_2 + ID_0 + MC_1 + TBCLR;
// Chooses SMCLK as source, no divider, Up-mode, clears counter

_BIS_SR(GIE + LPM0_bits); // Interrupts enabled.
}

void MRFI_RxCompleteISR() // Executes once packet is received.
{
P1OUT ^= 0x01; // Toggles Red LED on receiving board.
P4DIR ^= 0x10; // Toggles P4.4 (Extension Pin 9) as output
TBCCR1= TBCCR1;
}

#pragma vector=PORT1_VECTOR // Executes when button is pushed.
__interrupt void Port_1 (void)
{
P1IFG &= ~0x04; // Clears interrupt flag
mrfiPacket_t packet; // Initialize packet
packet.frame[0]=8+20; // Declare Useful length?
MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); // Copy and send data
P1OUT ^= 0x02; // Toggles Green LED on transmitting board.
}

As I said above, I would like to add to this code/remove what is unnecessary so that I can just alter the code on Board A with a different set of values for the period and duty cycle, and have those values sent via UART to Board B, where the PWM output will be changed accordingly. 

I've been looking through the provided examples for F2274 MSP430s that use UART, primarily msp430x22x4_uscia0_uart_01_9600.c and msp430x22x4_uscia0_uart_06_9600.c, but I'm having a lot of trouble understanding how exactly to integrate the concepts in the example into my code above. I get the feeling that it will be very simple, but for whatever reason I simply can't grasp it. Any assistance would be extremely helpful for this. 

Thanks!

  • Indeed it's quite simple.

    In your main, you put the processor to sleep at the end.

    Put this line into an endless loop (while(1)).

    Now when you received a dat apacket, wake the processor, by executing the intrinsic __bic_SR_on_exit (LPM0_bits) or a similar one (depends on compiler and there are also different variants).

    When the ISR exits, the processor will not fall into sleep again. Instead, main will continue after the _BIS_SR() instrinsic as if nothing happened. Now you knwo that you have ben awakened because a packet arrived. You can check for the content, change your PWM and the while lopp will put you to sleep again. That's all.

  • Hi Jens-Michael,

    I think I at least partially understand what you are trying to say. Essentially, I should replace

    "_BIS_SR(GIE+LPM0_bits);" with

    "while(1) {_BIS_SR(GIE+LPM0_bits);}

    on both boards, and then create an USCIAB0RX_VECTOR interrupt in Board B, within which I have

    {__bic_SR_on_exit(LPM0_bits);  

       (// next, check contents of packets)}

    correct? Just for clarification, I am using IAR workbench for this project, will the __bic_SR_on_exit intrinsic work there?

    However, I am still very confused about the code to send and receive packets between the two boards or how to check for the content that would have just arrived to Board B, because the example codes I mentioned I was working with don't really explain how the code for sending and receiving data works, instead just kind of giving it to me and saying that it works. The entirety of the wireless portions of the code in my previous post came from an example code I found, so I know it works, but really don't know how/why, or if it is of any use with this UART-based code I am trying to create now. If you could at least briefly run through the code for how to send/receive packets and interpret the contents, or point me to some example code that would explain it, it would be very helpful.

    Thanks for your help!

  • Akshay Raghu said:
    I am using IAR workbench for this project, will the __bic_SR_on_exit intrinsic work there

    I think so. I never used IAR myself. But there is a manual for IAR :)

    Akshay Raghu said:
    the example codes I mentioned I was working with don't really explain how the code for sending and receiving data works

    Yes, that's a known problem with the sample codes. They prove that it works for this particular implementation but don't tell how ,and why it is done this way.

    Akshay Raghu said:
    how to check for the content that would have just arrived

    This code is to be placed behind the __BIS_SR in the while loop. Teh CPU stops at the __BIS_SR and as soon as a packet arrived (and the ISR exited LPM), the CPU continues with the cod ebehind it, whcih has to check the packet and act, then go to sleep again.

    I have no own experience with the SimpliciTI stuff.

  • hELLO,

    DID U GET GET HTE PROGRAM RIT. i AM TRYIN TO CONTROL MY PWM IN ONE BOARD FROM ANOTHER BOARD . bUT I CAN'T DO. iF U HAVE THE CODE CAN YOU PLASE SEND IT TO MY MAIL OR POST HER!!! ITS REALLY A KIND OF URGENT DUDE!!! 

    sreenathrns@gmail.com

    THANKS,

    SREENATH

**Attention** This is a public forum