Saludos!! En esta publicación veremos otro ejemplo del ADC de 12 bits, con el que cuenta este microcontrolador, como ya habíamos visto en otra publicación vamos a usar el potenciometro con el que cuenta esta tarjeta, ahora mostraremos los bits del ADC en la pantalla y haremos la conversión para mostrar de igual forma el voltaje correspondiente.
La primer tarea fue conseguir una función para pasar de flotante a array (esto se logro usando la version que muestra InDevice en sus tutoriales, por cierto recomiendo su canal con muy buenos tutoriales sobre el MSP340G2553), yo he agregado esas funciones a un par de archivos, llamados special.h y special.c, ahí sera donde tenga algunas funciones comunes para los MSP y sea mas fácil añadirlas a nuestros proyectos.
El código que hace posible esto, es el siguiente:
This file contains 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 | |
} |
Aquí un vídeo en funcionamiento:
Descargas:
Aquí el enlace directo para DESCARGAR los archivos disponibles, también puedes revisar o descargar la información desde mi repositorio en GitHub, si no sabes como descargarlo puedes checar aquí, bueno por el momento es todo si tienes dudas, comentarios, sugerencias, inquietudes, traumas, etc. dejarlas y tratare de responder lo mas pronto posible.
Aquí el enlace directo para DESCARGAR los archivos disponibles, también puedes revisar o descargar la información desde mi repositorio en GitHub, si no sabes como descargarlo puedes checar aquí, bueno por el momento es todo si tienes dudas, comentarios, sugerencias, inquietudes, traumas, etc. dejarlas y tratare de responder lo mas pronto posible.
Donaciones:
Si te gusta el contenido o si los recursos te son de utilidad, comparte el enlace en tus redes sociales o sitios donde creas que puede ser de interés y la otra puedes ayudarme con una donación para seguir realizando publicaciones y mejorar el contenido del sitio. También puedes hacer donaciones en especie, ya sea con componentes, tarjetas de desarrollo o herramientas. Ponte en contacto para platicar, o puedes volverte uno de nuestros sponsors.
Pido una retroalimentación avisando cada que un enlace no sirva o tenga errores al momento de abrirlo, así también si una imagen no se ve o no carga, para corregirlo en el menor tiempo posible.
Referencias:
- 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