Part Number: MSP430FR6989
Other Parts Discussed in Thread: MSP430G2231
Dear all,
I'm a new microcontroller programmer and I found it is so confusing to me to understand how the registers of the microcontroller work, and how to know which pin and PINSEL I have to chose when using timer A0, is there a table that shows the relations between pin's name and its functions, the user guide is confusing me, there are many tables with a lot of pins and numbers, so my first question is a detailed reference with examples to how to use this microcontroller, my second question is regarding my code, I want to read 9 analog values through ADC then I saved it and mutilpied by other number ( for some reason) to use it as duty cycle of 9 PWM , the main goal of this code is to read an analog value, process it then convert it back to analog throgh PWM+ RC filter, I'm not sure what I'm doing is right I keep my code simple with only reading o ne value for testing purposes:
#include <msp430.h>
//#pragma PERSISTENT(FRAM_data)
//#include <msp430G2231.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
//#define BIT2 0x0F
//volatile uint16_t ADCResults = 0;
void ADC_SETUP(void); // Used to setup ADC12 peripheral
const int x1=1;
const int x2=1;
volatile int multiplied_value;
main()
{
PM5CTL0 = ENABLE_PINS; // Enable inputs and outputs
P1DIR =BIT0; // Set RED LED to output
ADC_SETUP(); // Sets up ADC peripheral
while(1)
{
ADC12CTL0 = ADC12CTL0 | ADC12ENC; // Enable conversion
ADC12CTL0 = ADC12CTL0 | ADC12SC; // Start conversion
multiplied_value = (ADC12MEM0);
//P1OUT=multiplied_value;
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 |= BIT1; // P1.2 to output
P1SEL1 |= BIT1; // P1.2 to TA0.1
// P1SEL2 &= ~BIT6; // P1.7 to TA0.1
TA0CCR0 = multiplied_value; // PWM Period
TA0CCTL1 = OUTMOD_7; // CCR1 reset/set
TA0CCR1 = multiplied_value ; // CCR1 PWM duty cycle
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;
}