This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
#include <msp430.h>
#include <stdio.h>
float volt_hex, volt_hex1, volt_hex2;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12ON + ADC12MSC ; // Sampling time, ADC12 on
ADC12CTL1 = 0x7000+ADC12SHP + ADC12CONSEQ_1; // Sample and Hold Mode
ADC12IE = 0x80; // Enable interrupt for channel 7
ADC12MCTL0 |= ADC12INCH_0;
ADC12MCTL1 |= 0x07 + ADC12EOS;
P6SEL |= 0x70; // P6.7 ADC option select
P6DIR &= 0x7F;
P1DIR |= BIT0;
P6SEL = 0X01; //P6.0 ADC option select
P1DIR |= 0x01; // P1.0 output
while(1)
{
ADC12CTL0 |= ADC12ENC; //Enable conversion
ADC12CTL0 |= ADC12SC; // start conversion
__bis_SR_register(LPM0_bits | GIE); // Enter Low Power Mode 0 + Global Interrupt Enable
}
}
// ADC ISR
#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:break; // Vector 6: ADC12IFG0
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:
volt_hex1 = ADC12MEM1; // Read converted value for channel 7. This clears the interrupt flag
volt_hex2 = ADC12MEM7;
volt_hex = volt_hex1 - volt_hex2;
__bic_SR_register_on_exit(LPM0_bits); // Quit Low Power Mode 0 on exit to enable CPU for next Start Conversion operation
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;
}
}
You shall try source code examples which are available in the product page of nearly every msp. Example MSP430F55xx_adc_08.c is one you would want to look at.
Thank you for replying. it's okay. I try the code you mention already but, I am using build in LCD MSP430F5529 experimental board which doesn't have the pin P6.0 to P6.3. I try using other pin by changing the channel it's not working. Please help me finding the right pin because I have spent more then three weeks trying to find it. Only hope for me is TI-forum about finding right solution. I am getting one ADC12 conversion by uisng below code from pin6.7.
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = 0x7000 + ADC12SHP; // Sample and Hold Mode
ADC12IE = 0x80; // Enable interrupt for channel 7
ADC12MCTL7 |= 0x07;
But I try changing the code and used different pin but, it's not showing any reading on LCD. Please help me.....
> board which doesn't have the pin P6.0 to P6.3
Then which P6 port pins _are_ there?
>But I try changing the code and used different pin but, it's not showing any reading on LCD
Are you able to measure and display internal channels like VCC divider or thermistor?
I am not sure that you are following source code example I suggested:
B2 Khat said:WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC12CTL0 = ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = 0x7000 + ADC12SHP; // Sample and Hold Mode
ADC12IE = 0x80; // Enable interrupt for channel 7
ADC12MCTL7 |= 0x07;
It is not that ieasy to convert MSP430F55xx_adc_06.c to other ADC inputs, you shall just use your head.
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_15;// Turn on ADC12, set sampling time
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1; // Use sampling timer, single sequence
ADC12MCTL0 = ADC12INCH_7; // ref+=AVcc, channel = A7, pin 6.7
ADC12MCTL1 = ADC12INCH_9+ADC12EOS; // ref+=AVcc, channel = A9, pin 5.1 end seq.
ADC12IE = 0x02; // Enable ADC12IFG.1, end channel
ADC12CTL0 |= ADC12ENC; // Enable conversions
while(1)
{
ADC12CTL0 |= ADC12SC; // Start convn - software trigger
__bis_SR_register(LPM4_bits + GIE); // Enter LPM4, Enable interrupts
__no_operation(); // For debugger
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void)
#else
#error Compiler not supported!
#endif
{
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: break; // Vector 6: ADC12IFG0
case 8: // Vector 8: ADC12IFG1
float volt1 = ADC12MEM0; // Move results, IFG is cleared
float volt2 = ADC12MEM1; // Move results, IFG is cleared
__bic_SR_register_on_exit(LPM4_bits); // Exit active CPU, SET BREAKPOINT HERE
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;
}
}
Actually I used my head many time, but it's not working. The code seems working but it's not giving actual reading in LCD board. I know the input pins are correct as per the manual. I believe we need to use delay to get simultaneously sampling reading. Can any one help doing it.
Thanks
B2 Khat said:Actually I used my head many time, but it's not working.
Good. You init sequence to read A7 and A9 channels, but wait for interrupt from A0 and A1 channels, read from A0 and A1 channel result registers. Of course interrupts of A0 and A1 never arrive, thus ADC channels most probably are measured but results are never read out of corresponding registers.
You shall process ADC12IFG7 and ADC12IFG9 interrupts instead, read from ADC12MEM7 and ADC12MEM9.
#include <msp430.h> #include "HAL_Dogs102x6.h" #include <stdio.h> #include <stdlib.h> float volt_hex1, volt_hex2; int main(void) { WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_15;// Turn on ADC12, set sampling time ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1; // Use sampling timer, single sequence ADC12MCTL6 = ADC12INCH_6; // ref+=AVcc, channel = A6, pin 6.6 ADC12MCTL7 = ADC12INCH_7+ADC12EOS; // ref+=AVcc, channel = A7,pin 6.7 end seq. ADC12IE = 384; // Enable (ADC12IFG.7 + ADC12IFG.6)= 256+384, end channel while(1) { ADC12CTL0 |= ADC12ENC; // Enable conversions ADC12CTL0 |= ADC12SC; // Start convn - software trigger __bis_SR_register(LPM4_bits + GIE); // Enter LPM4, Enable interrupts __no_operation(); // For debugger } } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=ADC12_VECTOR __interrupt void ADC12ISR (void) #elif defined(__GNUC__) void __attribute__ ((interrupt(ADC12_VECTOR))) ADC12ISR (void) #else #error Compiler not supported! #endif { 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: break; // Vector 6: ADC12IFG0 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: // Vector 20: ADC12IFG7 volt_hex1 = ADC12MEM6; // Move results, IFG is cleared volt_hex2 = ADC12MEM7; // Move results, IFG is cleared __bic_SR_register_on_exit(LPM4_bits); // Quit Low Power Mode 0 on exit to enable CPU for next Start Conversion operation // break; 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; } }
**Attention** This is a public forum