MSP-EXP430F5529 & CCS: Basic use of ADC12_A


Following some examples with the MSP430F5529 and using CCS, it is the turn to use the ADC12_A, which has a resolution of 12 bits, this time we will use the example called "MSP430F55xx_adc_01" included in the folder MSP430F552x Code Examples.

What does this example? Basically it configures to read the voltage through port A0 and attend it by means of an interruption (the system is in LowPowerMode until the interruption takes it out of there), when the voltage in A0 is greater than 0.5 * AVcc (considering that AVcc is connected to VCC, the value should be about 3.3V approximately, I have measured it with my multimeter and walked in the 3.5V) will turn on LED1, otherwise it will remain off.

Circuit:
Now reviewing the schematic of the experimental board, we will note that pin A0 is connected to DB0 (a Touch Pad) which will not serve to demonstrate this example, therefore I have decided to use the potentiometer that has the board, this is connected to A5 (as shown in the following image), to work properly we must activate P1.8 and leave jumper JP2.


Firmware:
Considering these modifications, the code is as follows::
/*******************************************************************************
*
* MSP-EXP430F5529_002: Ejemplo básico del ADC_12
*
*******************************************************************************
* FileName: main.c
* Processor: MSP430F5529
* Complier: CCS 7.2.0.00013
* Author: Pedro Sánchez Ramírez (MrChunckuee)
* Blog: http://mrchunckuee.blogspot.com/
* Email: mrchunckuee.psr@gmail.com
* Description: ADC12, Sample A5, Set P1.0 if A5 > 0.5*AVcc
*******************************************************************************
* Rev. Date Comment
* v0.01 30/08/2017 - Testing using MSP-EXP430f5529 USB Experimental Board
* - Se usó el potenciómetro en A5, para ello se habilito
* y se puso en alto a P8.0
******************************************************************************/
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12MCTL0 = ADC12INCH_5; // Use A5 (wheel) as input
ADC12IE = 0x01; // Enable interrupt
ADC12CTL0 |= ADC12ENC; // Enable conversions
P6SEL |= BIT5; // P6.5 ADC option select (A5)
P1DIR |= BIT0; // P1.0 output
P8DIR |= BIT0; // P8.0 output
P8OUT |= BIT0; // Set P8.0 high
while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A5 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
Video
Here is a small working video:


Download:
Here the direct link to DOWNLOAD the available files, you can also check or download the information from my repository on GitHub, if you do not know how to download it you can check here, well for now it's all, if you have doubts, comments, suggestions, concerns, etc. leave them and I will try to answer as soon as possible.


Donations:
If you like the content or if the resources are useful to you, share the link on your social networks or sites where you think it may be of interest, you can also help me with a donation to continue making publications and improve the content of the site. You can also donate in kind, for example components, development boards or tools. Contact me to talk or you can become one of our sponsors.


I ask for feedback notifying each time a link does not work or has errors when opening it, as well as if an image is not visible or does not load, to correct it in the shortest possible time.

Bibliography:

Publicar un comentario

0 Comentarios