In this publication we will see another example of the 12-bit ADC, we will use the potentiometer of this board, on the screen we will show the ADC bits and the corresponding voltage.
Firmware:
The first task was to get a function to move from floating to array, i used the InDevice version, I have added those functions to a couple of files, called special.h and special.c, that will be where you have some common functions for MSPs and it is easier to add them to our projects.
The code that makes this possible:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
* | |
* MSP-EXP430F5529_005: Leer y mostrar el voltaje del ADC | |
* | |
******************************************************************************* | |
* 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: Pequeño ejemplo para mostrar el numero de bits y el voltaje | |
* presentes en el ADC. | |
******************************************************************************* | |
* Rev. Date Comment | |
* v0.01 10/10/2017 - Creación del firmware | |
******************************************************************************/ | |
#include <msp430.h> | |
#include <stdlib.h> | |
#include "HAL_Dogs102x6.h" | |
#include "special.h" | |
static const uint8_t mrchunckueeLogo[] = { | |
0x66, // Image width in pixels (102 pixels) | |
0x08, // Image height in rows (1 row = 8 pixels) | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x01 , 0x03 , 0x01 , 0x08 , 0x1C, | |
0x3E , 0x7F , 0x3F , 0x1F , 0x0F , 0x06 , 0x00 , 0x01, | |
0x03 , 0x01 , 0x06 , 0x0E , 0x1F , 0x3F , 0x7F , 0x3F, | |
0x1E , 0x0C , 0x00 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x03 , 0x07 , 0x0F , 0x0F , 0x07 , 0x63, | |
0xF1 , 0xF8 , 0xFC , 0xFE , 0xFC , 0x79 , 0x33 , 0x07, | |
0x8F , 0x9F , 0x3F , 0x7F , 0xFF , 0xFF , 0xFF , 0xFF, | |
0xFF , 0x7F , 0x3F , 0x9F , 0x8F , 0x17 , 0x33 , 0x79, | |
0xFC , 0xFE , 0xFC , 0xF9 , 0x73 , 0x27 , 0x0F , 0x0F, | |
0x07 , 0x03 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01, | |
0x03 , 0x01 , 0x08 , 0x1C , 0x3E , 0x7F , 0x7F , 0x3F, | |
0x1F , 0x8E , 0xC4 , 0xF1 , 0xF3 , 0xE7 , 0xCF , 0x9F, | |
0x3F , 0x7F , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF, | |
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF, | |
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0x7F, | |
0x3F , 0x9F , 0xCF , 0xE7 , 0xF3 , 0xE1 , 0xC4 , 0x8E, | |
0x1F , 0x3F , 0x7F , 0x3F , 0x1E , 0x0C , 0x01 , 0x03, | |
0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x60 , 0xF0 , 0xF8 , 0xFC , 0xFC, | |
0xFC , 0x79 , 0x33 , 0x07 , 0x8F , 0x9F , 0x2F , 0x60, | |
0xE0 , 0xE0 , 0xE0 , 0xE0 , 0xEF , 0xEC , 0xE7 , 0xE3, | |
0xE1 , 0xE0 , 0xFF , 0xFF , 0xFE , 0xFE , 0xF0 , 0xE0, | |
0xE6 , 0xE6 , 0xE0 , 0xE0 , 0xE3 , 0xFE , 0xFC , 0xFC, | |
0xFC , 0xFF , 0xEF , 0xEF , 0xE0 , 0xE0 , 0xE0 , 0xE0, | |
0xE7 , 0xE7 , 0xE0 , 0xE0 , 0xE0 , 0x60 , 0x31 , 0x9F, | |
0x8F , 0x37 , 0x73 , 0xF9 , 0xFC , 0xFC , 0xF8 , 0xF0, | |
0x60 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x03 , 0x07 , 0x0F , 0x1F , 0x3F , 0x9F , 0xCF, | |
0xE6 , 0xF0 , 0xF8 , 0xF8 , 0xF2 , 0x03 , 0x03 , 0x03, | |
0x03 , 0x03 , 0x7B , 0x13 , 0xF3 , 0xE3 , 0xC3 , 0x83, | |
0xFF , 0x0F , 0x07 , 0x03 , 0x03 , 0x63 , 0x63 , 0x67, | |
0x0F , 0x1F , 0x0F , 0x07 , 0x43 , 0xE3 , 0xE7 , 0xCF, | |
0xFB , 0xFB , 0x03 , 0x03 , 0x03 , 0x03 , 0x1B , 0x1F, | |
0x0F , 0x07 , 0x03 , 0x82 , 0xC0 , 0xE1 , 0xF0 , 0xE4, | |
0xCE , 0x9F , 0x3F , 0x1F , 0x0F , 0x07 , 0x03 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x80 , 0xC0 , 0xE0 , 0xC0 , 0x88 , 0x1C , 0x3E , 0x7F, | |
0xFF , 0xFE , 0x7C , 0x39 , 0x93 , 0xC7 , 0xE7 , 0xF3, | |
0xF9 , 0xFC , 0xFE , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF, | |
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF, | |
0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF, | |
0xFF , 0xFE , 0xFC , 0xF9 , 0xF3 , 0xE7 , 0xC7 , 0x83, | |
0x31 , 0x78 , 0xFC , 0xFE , 0xFF , 0x7E , 0x3C , 0x18, | |
0x80 , 0xC0 , 0xC0 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0xE0 , 0xF0 , 0xF8 , 0xF8 , 0xF0 , 0xE3 , 0xC7 , 0x8F, | |
0x1F , 0x3F , 0x9F , 0xCF , 0xE6 , 0xF0 , 0xF9 , 0xFC, | |
0xFE , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFE, | |
0xFC , 0xF9 , 0xF0 , 0xE4 , 0xCE , 0x9F , 0x3F , 0x3F, | |
0x1F , 0x8F , 0xC7 , 0xE2 , 0xF8 , 0xF8 , 0xF0 , 0xE0, | |
0x40 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x80 , 0xC0 , 0xC0 , 0xC0, | |
0x98 , 0x3C , 0x7E , 0xFE , 0xFE , 0xFC , 0x78 , 0x30, | |
0x80 , 0xC0 , 0xC0 , 0x80 , 0x30 , 0x78 , 0xFC , 0xFE, | |
0xFE , 0x7E , 0x3C , 0x18 , 0x80 , 0xC0 , 0xC0 , 0x80, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00, | |
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 | |
}; | |
char adcValueLCD[20], adcVoltsLCD[20]; | |
int adcValue = 0; | |
double adcVolts = 0; | |
/********** P R O T O T Y P E S *************/ | |
void MCU_Init(void); | |
void MCU_Delayms(int16_t time); | |
void ADC_Init(void); | |
int16_t ADC_Get(void); | |
/** | |
* main.c | |
*/ | |
void main(void){ | |
MCU_Init(); | |
// Display MrChunckuee Logo | |
// and welcome message | |
Dogs102x6_imageDraw(mrchunckueeLogo, 0, 0); | |
MCU_Delayms(2000); | |
Dogs102x6_clearScreen(); | |
Dogs102x6_stringDraw(1, 0, " MSP-EXP430F5529 ", DOGS102x6_DRAW_NORMAL); | |
Dogs102x6_stringDraw(3, 0, " Welcome!! ", DOGS102x6_DRAW_NORMAL); | |
Dogs102x6_stringDraw(4, 0, " @MrChunckuee ", DOGS102x6_DRAW_NORMAL); | |
Dogs102x6_stringDraw(6, 0, "http://e2e.ti.com", DOGS102x6_DRAW_NORMAL); | |
MCU_Delayms(2000); | |
Dogs102x6_clearScreen(); | |
// Main loop | |
while (1){ | |
P1OUT ^= BIT0; // XOR P1.0 | |
adcValue = ADC_Get(); | |
SPECIAL_ltoa(adcValue, adcValueLCD); | |
adcVolts = adcValue*(3.6/4096.0); | |
SPECIAL_ftoa(adcVolts, 2, adcVoltsLCD); | |
Dogs102x6_stringDraw(0, 0, " MSP-EXP430F5529 ", DOGS102x6_DRAW_NORMAL); | |
Dogs102x6_stringDraw(2, 0, " ADC Value: ", DOGS102x6_DRAW_NORMAL); | |
Dogs102x6_stringDraw(4, 0, " ADC Volts: ", DOGS102x6_DRAW_NORMAL); | |
Dogs102x6_stringDraw(2, 66, &adcValueLCD[0], DOGS102x6_DRAW_NORMAL); | |
Dogs102x6_stringDraw(4, 66, &adcVoltsLCD[0], DOGS102x6_DRAW_NORMAL); | |
MCU_Delayms(500); | |
} | |
} | |
void MCU_Init(void){ | |
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer | |
// Basic GPIO initialization | |
// Configure Dogs102x6 ports | |
P5OUT &= ~(BIT6 + BIT7); // LCD_C/D, LCD_RST | |
P5DIR |= BIT6 + BIT7; | |
P7OUT &= ~(BIT4 + BIT6); // LCD_CS, LCD_BL_EN | |
P7DIR |= BIT4 + BIT6; | |
P4OUT &= ~(BIT1 + BIT3); // SIMO, SCK | |
P4DIR &= ~BIT2; // SOMI pin is input | |
P4DIR |= BIT1 + BIT3; | |
//General GPIOs initialization | |
P1DIR |= BIT0; // P1.0 output | |
P1OUT &= ~BIT0; //Clear LED1 | |
// Set up LCD | |
Dogs102x6_init(); | |
Dogs102x6_backlightInit(); | |
Dogs102x6_setBacklight(11); | |
Dogs102x6_setContrast(11); | |
Dogs102x6_clearScreen(); | |
// ADC Init | |
ADC_Init(); | |
} | |
void MCU_Delayms(int16_t time){ | |
int16_t delayCount; | |
for (delayCount=0; delayCount<time; ++delayCount) | |
__delay_cycles(1000); // 1ms = 1000 clocks at 1MHz | |
return; | |
} | |
void ADC_Init(void){ | |
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on | |
ADC12CTL1 = ADC12SHP; // Use sampling timer | |
ADC12MCTL0 = ADC12INCH_5; // Use A5 (wheel) as input | |
ADC12CTL0 |= ADC12ENC; // Enable conversions | |
P6SEL |= BIT5; // P6.5 ADC option select (A5) | |
P8DIR |= BIT0; // P8.0 output | |
P8OUT |= BIT0; // Set P8.0 high | |
} | |
int16_t ADC_Get(void){ | |
ADC12CTL0 |= ADC12SC; // Iniciamos la lectura | |
while (ADC12CTL0 & BUSY); // Espero mientras hace la lectura | |
return ADC12MEM0; // Regresa el valor leido | |
} |
Here is a photo showing the voltage measured with a multimeter:
Video:
Here a small video of the working temperature sensor.
Here a small video of the working temperature sensor.
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:
- InDevice, 2017, "Pantalla LCD 1602A Convertir Float a String CCS 7.0", https://www.youtube.com/watch?v=yfkzitAiEOQ
- MrChunckuee, 2017, "MSP-EXP430F5529 & CCS: Ejemplo básico del ADC12_A", https://mrchunckuee.blogspot.com/2017/09/msp-exp430f5529-ccs-002.html
- MrChunckuee, 2017, "MSP-EXP430F5529 & CCS: 102x64 LCD Basic test", https://mrchunckuee.blogspot.com/2017/09/msp-exp430f5529-ccs-004.html
- Texas Instruments, "MSP430F552x Code Examples", http://www.ti.com/lit/zip/slac300
- TI E2E Community, http://e2e.ti.com/
- Texas Intruments, "MSP430F5529 USB Experimenter’s Board", http://www.ti.com/tool/msp-exp430f5529
- Texas Instruments, 2016, "MSP430x5xx and MSP430x6xx Family", http://www.ti.com/lit/ug/slau208p/slau208p.pdf
- Texas Instrumetns, 2015, "MSP430F552x, MSP430F551x Mixed-Signal Microcontrollers", http://www.ti.com/lit/ds/symlink/msp430f5529.pdf
0 Comentarios