6 Replies Latest reply on Jun 28, 2013 12:28 AM by nivedhitha.selvakumaran

    Analog MUX switching problem

    nivedhitha.selvakumaran

       hi 

         

      I have written a code for sampling two pins distinctly and feeding it to the same ADC+UART module, but only one pin connected to the AMUX is being properly sampled. for the other pin I am getting a default (very small) value in the hyperterminal screen. Please help ASAP, I have a deadline for this project.

         

      Program:

         

      //----------------------------------------------------------------------------

         

      // C main line

         

      //----------------------------------------------------------------------------

         

       

         

      #include <m8c.h>        // part specific constants and macros

         

      #include "PSoCAPI.h"    // PSoC API definitions for all User Modules

         

      #include "stdlib.h" 

         

       

         

      void main(void)

         

      {

         

      //  // Uncomment this line to enable Global Interrupts

         

      // Insert your main routine code here.

         

      int data;

         

      int i; 

         

      int iStatus;

         

      float fScaleFactor;

         

      float volt;

         

      char *str2;

         

      char *str3;

         

      char str1[] = " approaching resolution limit ";

         

      int count = 0;

         

      //char * strPtr;                        // Parameter pointer

         

          

         

          UART_CmdReset();                      // Initialize receiver/cmd

         

                                                // buffer

         

          UART_IntCntl(UART_ENABLE_RX_INT);

         

      Counter8_Start();                     // Turn on baud rate generator   // Enable RX interrupts

         

       

         

          UART_Start(UART_PARITY_NONE);         // Enable UART

         

      PGA_Start(PGA_MEDPOWER);

         

      //LCD_Start();

         

      //LCD_Position(0,2);

         

      //LCD_PrString(str1);

         

      M8C_EnableGInt ;

         

      ADCINC_Start(ADCINC_HIGHPOWER); 

         

      //ADCINC_GetSamples(0);

         

      fScaleFactor = (float)2/(float)4096;// Apply power to the SC Block

         

      while(1)

         

      {

         

      AMUX4_Start();

         

       

         

      count++; 

         

      if((count%2)==0)

         

      {

         

      AMUX4_InputSelect(AMUX4_PORT0_3);

         

      UART_CPutString(" from POT3 ");

         

      }

         

      else

         

      {

         

      AMUX4_InputSelect(AMUX4_PORT0_1);

         

      UART_CPutString(" from POT1 ");

         

      }

         

       

         

      ADCINC_GetSamples(50);                 // Have ADC run continuously 

         

       

         

      for(i=0;i<50;i++){ 

         

      while(ADCINC_fIsDataAvailable() == 0);   // Loop until value ready  

         

      data = ADCINC_iClearFlagGetData();              // Clear ADC flag and get data 

         

      volt = fScaleFactor * (float)data;

         

      if (volt > 1) 

         

      UART_PutString(str1);

         

      str2 = ftoa(volt,&iStatus);

         

      UART_PutString(str2);

         

      UART_CPutString("\r\n");  

         

      UART_PutString(itoa(str3,data,10));

         

      UART_CPutString("\r\n");  

         

      UART_CmdReset();                          // Reset command buffer  

         

      }

         

      }

         

      }