I need answer ASAP The following two programs are missing so
I need answer ASAP!!
The following two programs are missing some comments. Please complete the highlight comment areas.
Then explain what each program performs. Finally give one possible application case for each program.
//Program 1
// Global variables
unsigned int ADC_value=0;
// Function prototypes
void ConfigureAdc(void);
void main(void)
{
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz
P1SEL |= BIT3; // ADC input pin P1.3
ConfigureAdc(); // ADC set-up function call
__enable_interrupt(); // Enable interrupts.
while(1)
{
__delay_cycles(1000); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; //____________________________________
__bis_SR_register(CPUOFF + GIE); // Low Power Mode 0 with interrupts enabled
ADC_value = ADC10MEM; //____________________________________
}
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode }
}
// Function containing ADC set-up
void ConfigureAdc(void)
{
ADC10CTL1 = INCH_3 + ADC10DIV_3 ; //____________________________________
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //____________________________________
ADC10AE0 |= BIT3; //____________________________________
}
Program 2
int main(void)
{
Setup_HW();
while (1)
{
Read_Acc(); // This function reads the ADC and stores the x, y and z values
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
void Setup_HW(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL1 = INCH_2 + CONSEQ_1; //____________________________
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; //____________________________
ADC10DTC1 = 0x03; //____________________________
ADC10AE0 |= 0x03; //____________________________
}
void Read_Acc(void)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); //____________________________
ADC10SA = (unsigned int)adc; // Copies data in ADC10SA to unsigned int adc array
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
X_Axis = adc[0]; // adc array 0 copied to the variable X_Axis
Y_Axis = adc[1]; // adc array 1 copied to the variable Y_Axis
Z_Axis = adc[2]; // adc array 2 copied to the variable Z_Axis
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
}
---------------------------------------
that what in the pic
References Malings Review View Tel me what you want to do me following wo programs are missing some comments. Please complete the comment areas Then explain whateach program peroms. Finily eve one possale application case tor each //Program 1 //Global variables void main(void) //Stop WDT //Set range DCOCTL CALDco 1MHz; //ADC input pin P13 ADC set-up function call Enable interrupts //wait for ADC Ret to settle ENC ADC10SC. ADC10CTLO //Low Power Mode o with interrupts enabled ADc value. ADC10MEM; //ADc10 interrupt service routine interrupt void ADC10 (void) SR-register on exiticPuoFFk Return to active mode) //Function containing ADC set-up 3 ADc10ON ADc10E ADc10CTuo SREF.0 BIT3; English (United statestSolution
//Program 1
// Global variables
unsigned int ADC_value=0;
// Function prototypes
void ConfigureAdc(void);
/*************************************************************************************************************
In the main function we stop as usual the Watchdog timer, set up the clocks and the leds.Then we select the
input pin for the ADC module by setting the P1SEL register. After that, we initialize the ADC with
ConfigureAdc() and enable the ADC interrupt, that will let us know when a conversion has been made and its result
is ready.
void main(void)
{
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ;
BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz
P1SEL |= BIT3; // ADC input pin P1.3
ConfigureAdc(); // ADC set-up function call
__enable_interrupt(); // Enable interrupts.
/*************************************************************************************************************
After the initialization code, we wait some cycles to let the ADC voltage reference settle to a stable level
and then we start the conversion by setting the ADC10CTL0 register. Then we enter a low-power mode to save battery
juice: we\'ll have the result of the conversion directly in our \"value\" variable from the ADC10MEM register thanks
to the ADC10 interrupt. The interrupt will then return to active mode and continue with the main. At last we simply
toggle the leds on the LaunchPad according to the number stored into \"value\" (don\'t forget that we have a 10-bit
ADC module, so the maximum value will be 1023).You could do some further calculations, maybe averaging the
results to get a more precise reading.
****************************************************************************************************************/
while(1)
{
__delay_cycles(1000); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; /* Sampling and conversion start */
__bis_SR_register(CPUOFF + GIE); // Low Power Mode 0 with interrupts enabled
ADC_value = ADC10MEM; /* After conversion is complete, the MSP430 sets this
conversion value into the memory location ADC10MEM */
}
}
}
// ADC10 interrupt service routine
/*********************************************************************************************************
The next one is the ADC10 interrupt service routine, as we\'ve seen for the TimerA module.
We simply exit the low-power mode to let the main program make some computations with the result from the ADC.
***********************************************************************************************************/
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
__bic_SR_register_on_exit(CPUOFF); // Return to active mode }
}
// Function containing ADC set-up
/******************************************************************************************************
With this line we specify that the conversions results should be automatically stored in the
previously created array: in such way, there\'s no need to access the ADC10MEM register anymore.
The data will be immediately ready for calculations.
****************************************************************************************************/
void ConfigureAdc(void)
{
/*************************************************************************************************************
The ADC10 Control Register 1 is used to configure which channels will be used by the ADC10, the channels
are connected directly to the external pins of the device.This selects channel 3 as an ADC input with
the command INCH_3 and then ADC10DIV_3 is the ADC clock divider with 3 being the division value
**************************************************************************************************************/
ADC10CTL1 = INCH_3 + ADC10DIV_3 ;
/********************************************************************************************************
The internal voltage reference for the ADC module (Vcc) with SREF_0, turn it on (ADC10ON) and enable
the ADC10 interrupt (ADC10IE). connect P1.5 to the ADC module by setting the ADC10AE0 register accordingly.
Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable.
**********************************************************************************************************/
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; //from accelerometer
ADC10AE0 |= BIT3; /* ADC input enable P1.3 */
}
Program 2
int main(void)
{
Setup_HW();
while (1)
{
Read_Acc(); // This function reads the ADC and stores the x, y and z values
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
void Setup_HW(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
/******************************************************************************************************************
The channels are connected directly to the external pins of the device.This selects channel 2 as an ADC input with
the command INCH_2. CONSEQ_1 using for sampling multiple input channels.
*******************************************************************************************************************/
ADC10CTL1 = INCH_2 + CONSEQ_1; // A2/A1/A0, single sequence
/********************************************************************************************************
Turn it on (ADC10ON) and enable the ADC10 interrupt (ADC10IE). connect P1.5 to the ADC module by setting
the ADC10AE0 register accordingly. Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on,
ADC interrupt enable. MSC : Multiple Sample Conversion.Allows multiple samples to be taken automatically.
**********************************************************************************************************/
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE; // Sample & Hold Time + ADC10 ON + Interrupt Enable
ADC10DTC1 = 0x03; /* 3 conversions */
ADC10AE0 |= 0x03; /* Disable digital I/O on P1.0 to P1.2 */
}
// This function reads the ADC and stores the x, y and z values
void Read_Acc(void)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); //__ /* wait if ADC10 core is active */
ADC10SA = (unsigned int)adc; // Copies data in ADC10SA to unsigned int adc array
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
X_Axis = adc[0]; // adc array 0 copied to the variable X_Axis
Y_Axis = adc[1]; // adc array 1 copied to the variable Y_Axis
Z_Axis = adc[2]; // adc array 2 copied to the variable Z_Axis
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
}
---------------------------------------
that what in the pic





