I got this example for msp430l092 and I have modified for getting photodiode sensor value. I have tried that when channel A2 is greater than 150 (integer value), P1.6 is high and P1.5 is low. When channel A2 is less than 150 value, P1.5 is high and P1.6 is low. I experienced that if I provide flash light to photodiode, sensor value would be greater than 150 (integer value). Unfortunately, I realised that after five minutes, my project is broken down. P1.5 and P1.6 are blinking arbitrarily. Is my code correct for reading photodiode sensor value. Do I need to use " P1DIR &= ~BIT6; " for setting input direction P1.6. I am a little bit confused reading sensor value. Can someone help me please? Thanks in advance
/* Description: Multiple ADC Channels*/
/****************************A_POOL ADC Conversion *******************************/
/* */
/* */
/* +----L092---+ */
/* |*1 14 | */
/* | 2 13 | */
/* | 3 12 |<- Channel A0(0-256mV) */
/* | 4 11 | */
/* | 5 10 | */
/* Channel A2 (0-256mV)-> | 6 9 | */
/* Channel A1 (0-256mV)-> | 7 8 | */
/* +-----------+ */
/* */
/* D.Dang/ D.Archbold/ D.Szmulewicz */
/* Texas Instruments Inc. */
/* Built with IAR Version 5.10.4 */
/*********************************************************************************/
#include <msp430.h>
int ChannelA0, ChannelA1, ChannelA2;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR = (BIT5 | BIT6); // Set P1.0 to output direction
// Begin Configuration of the A-POOL registers
APCTL = 0; // Clear APCTL register
APCNF = CMPON+DBON+CONVON+EOCBU+APREFON+CLKSEL_MCLK; // Configure A-POOL elements, Select MCLK as A-POOL Clock Source
APINT = 0x00; // Clear ADC-DAC-REG
while(1)
{
/*
APIE = EOCIE; // Enable Interrupt for End of Conversion
APINT = 0x00; // Clear ADC-DAC-REG
APCTL = OSEL+CBSTP+RUNSTOP+APNSEL_0+APPSEL_5; // Set Channels and Start Conversion
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts enabled
ChannelA0 = APINT; // Get Result for A0
*/
/*
APIE = EOCIE; // Enable Interrupt for End of Conversion
APINT = 0x00; // Clear ADC-DAC-REG
APCTL = OSEL+CBSTP+RUNSTOP+APNSEL_1+APPSEL_5; // Set Channels and Start Conversion
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts enabled
ChannelA1 = APINT; // Get Result for A1
*/
APIE = EOCIE; // Enable Interrupt for End of Conversion
APINT = 0x00; // Clear ADC-DAC-REG
APCTL = OSEL+CBSTP+RUNSTOP+APNSEL_2+APPSEL_5; // Set Channels and Start Conversion
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts enabled
ChannelA2 = APINT; // Get Result for A2
// __no_operation(); // Place breakpoint here
if(ChannelA2<150){
P1OUT |= BIT5;
P1OUT&= ~BIT6;
}
else if(ChannelA2>150){
P1OUT |= BIT6;
P1OUT&= ~BIT5;
}
else{
P1OUT&= ~BIT5;
P1OUT&= ~BIT6;
}
}
}
//A_POOL Interrupt Service Routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=APOOL_VECTOR
__interrupt void A_POOL(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(APOOL_VECTOR))) A_POOL (void)
#else
#error Compiler not supported!
#endif
{
APIFG = 0; // Clear Interrupt Flag
__bic_SR_register_on_exit(LPM0_bits); // Exit Active to Sample next Channel
}