1 post in this topic

I have the chip number MSP430FR6989 and I want to use it to read 10 analog DC signals then do some processing (multiply them by certain factors) after that I want to convert them back to analog using PWM and RC filter, my issue is in the second part , how to use timers( set period , duty cycles) of the MSP430 to produce PWMs from the analog inputs.  
This is the code:

#include <msp430.h>
#define ACLK 0x0100 // Timer ACLK source
#define UP 0x0010 // Timer UP mode
#define ENABLE_PINS 0xFFFE // Required to use inputs and outputs
#define ENABLE_PINS   0xFFFE // Enables inputs and outputs
void ADC_SETUP(void); // Used to setup ADC12 peripheral
const int x1=1;
const int x2=1;
volatile int multiplied_value,duty;

  PM5CTL0 = ENABLE_PINS; // Enable inputs and outputs
P1DIR =BIT0; // Set RED LED to output

ADC_SETUP(); // Sets up ADC peripheral
ADC12CTL0 = ADC12CTL0 | ADC12ENC; // Enable conversion
ADC12CTL0 = ADC12CTL0 | ADC12SC; // Start conversion
while  ( ADC12BUSY == 1){
multiplied_value = (ADC12MEM0);
if (multiplied_value > 0x800) // If input > 1.65V
P1OUT = BIT0; // Turn on red LED
else // Else input <= 1.65V
P1OUT = 0x00; // Turn off red LED

P1DIR |= BIT5;             // P1.5 to output
P1SEL1 |= BIT5;             // P1.5 to TA0.1

 TA0CCTL1 = OUTMOD_7;          // CCR1 reset/set
 TA0CCR1 = multiplied_value*65536/3.3 ;
 duty=TA0CCR1;// CCR1 PWM duty cycle
 TA0CCR0 =1000;             // PWM Period
 TA0CTL = TASSEL_2 + MC_1;   // SMCLK, up mode

 _BIS_SR(LPM0_bits);        // Enter LPM0
void ADC_SETUP(void)
#define ADC12_SHT_16 0x0200 // 16 clock cycles for sample and hold
#define ADC12_ON 0x0010 // Used to turn ADC12 peripheral on
#define ADC12_SHT_SRC_SEL 0x0200 // Selects source for sample & hold
#define ADC12_12BIT 0x0020 // Selects 12-bits of resolution
#define ADC12_P92 0x000A // Use input P9.2 for analog input
//#define ADC12_P43 0x000A
//#define ADC12_P32 0x000A
//#define ADC12_P93 0x000A
//#define ADC12_P14 0x000A
//#define ADC12_P20 0x000A
//#define ADC12_P41 0x000A
ADC12CTL0 = ADC12_SHT_16 | ADC12_ON ; // Turn on, set sample & hold time
ADC12CTL1 = ADC12_SHT_SRC_SEL; // Specify sample & hold clock source
ADC12CTL2 = ADC12_12BIT; // 12-bit conversion results
ADC12MCTL0 = ADC12_P92; // P9.2 is analog input
//ADC12MCTL1 = ADC12_P43;



I have the voltmeter, when I measure the frquency at the pin1.5 it gives me a number reanges between 14kHz to 0.11..   

I'm not sure if I used PWM correctly?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now