adc_Sar_seq programming of 8-channel

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
feme_285141
Level 4
Level 4

 Hi all I have the CY8CKIT-050 kit and I have been programming but any errors I am using adc to measure eight different signals usbUart I would like to use it to pass data to my computer for analysis. Someone could help me ?? here is the program that been doing:

   
        
   
    
     #include <project.h>    
    
          
    
     #define CANAL_1    (0u)    
    
     #define CANAL_2    (1u)    
    
     #define CANAL_3    (2u)    
    
     #define CANAL_4    (3u)    
    
     #define GANANCIA   (1u)    
    
          
    
     static void EnviarCanalDeVoltaje(uint8 canal, int16 volts);    
    
          
    
     int main()    
    
     {    
    
         int16 adcVal[4u];    
    
         int16 mVolts;    
    
         uint8 canal = CANAL_1;    
    
         /*activa la interrupciones globales*/    
    
         CyGlobalIntEnable;    
    
             
    
         /*Iniciamos los modulos*/    
    
         ADC_Start();    
    
         UART_Start();    
    
             
    
         /*Iniciamos la convercion del adc */    
    
         ADC_StartConvert();    
    
             
    
          
    
             
    
         for(;;)    
    
         {    
    
             adcVal[CANAL_1] = ADC_GetResult(CANAL_1);    
    
             adcVal[CANAL_2] = ADC_GetResult(CANAL_2);    
    
             adcVal[CANAL_3] = ADC_GetResult(CANAL_3);    
    
             adcVal[CANAL_4] = ADC_GetResult(CANAL_4);    
    
             canal++;    
    
             mVolts = ADC_CountsTo_mVolts(canal, adcVal[canal]);    
    
                 
    
                 
    
             EnviarCanalDeVoltaje(canal,mVolts);    
    
              
    
         if(canal > CANAL_4)    
    
         {    
    
             canal= CANAL_1;    
    
         }    
    
         }    
    
     }    
    
          
    
     static void EnviarCanalDeVoltaje(uint8 canal,int16 volts)    
    
     {    
    
             
    
         UART_UartPutString("Canal");    
    
             
    
         canal++;    
    
             
    
         canal += CONVERT_TO_ASCII;    
    
             
    
         UART_UartPutChar(canal);    
    
             
    
         UART_UartPutString("=");    
    
             
    
         UART_UartPutChar((volts/1000u)+ CONVERT_TO_ASCII);    
    
         volts %= 1000;    
    
         UART_UartPutChar((volts/100u) + CONVERT_TO_ASCII);    
    
         volts %= 100;    
    
         UART_UartPutChar((volts/10u) + CONVERT_TO_ASCII);    
    
         volts %= 10;    
    
         UART_UartPutChar(volts + CONVERT_TO_ASCII);    
    
         UART_UartPutString("mV");    
    
         UART_UartPutCRLF(0u);    
    
     }    
   
0 Likes
12 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Post an archive of the project, makes it easier to look at

   

problems and see the whole picture.

   

 

   

    

   

          

   

“File”                                                             Creator

   

“Create Workspace Bundle”

   

Use Firefox or IE, not chrome to post.

   

 

   

 

   

Regards, Dana.

0 Likes
feme_285141
Level 4
Level 4
0 Likes
feme_285141
Level 4
Level 4
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are using your global variable "canal" from different places which will produce errornous results.

   

The line

   

canal += CONVERT_TO_ASCII;

   

will change your index-variable to something that is not in the range of 1..4 or 0..3 whatever you think you expect, apart from the fact that I cannot see what CONVERT_TO_ASCII is defined.

   

Use local variables and / or paremeters to your function(s) to better perform what you want. Avoid global variables and never change them at different places. Here is a link to my favourite C-handbook: publications.gbdirect.co.uk/c_book/

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Do NOT use chrome. Use ms internet explorer and when the respond window is a very small one, set the "Compatibility Mode". Not your fault, but bad forum software.

   

 

   

Bob

0 Likes
feme_285141
Level 4
Level 4

I have the CY8CKIT-050 kit and I have been programming but any errors I am using adc to measure eight different signals usbUart I would like to use it to pass data to my computer for analysis. Someone could help me ?? here is the program that been doing:

   
        
   
    
     #include <project.h>    
    
          
    
     #define CANAL_1    (0u)    
    
     #define CANAL_2    (1u)    
    
     #define CANAL_3    (2u)    
    
     #define CANAL_4    (3u)    
    
     #define GANANCIA   (1u)    
    
     #define ASCII          (0x30)    
    
          
    
     static void EnviarCanalDeVoltaje(uint8 canal, int16 volts);    
    
          
    
     int main()    
    
     {    
    
         int16 adcVal[4u];    
    
         int16 mVolts;    
    
         uint8 canal = CANAL_1;    
    
         /*activa la interrupciones globales*/    
    
         CyGlobalIntEnable;    
    
             
    
         /*Iniciamos los modulos*/    
    
         ADC_Start();    
    
         UART_Start();    
    
             
    
         /*Iniciamos la convercion del adc */    
    
         ADC_StartConvert();    
    
             
    
          
    
             
    
         for(;;)    
    
         {    
    
             adcVal[CANAL_1] = ADC_GetResult(CANAL_1);    
    
             adcVal[CANAL_2] = ADC_GetResult(CANAL_2);    
    
             adcVal[CANAL_3] = ADC_GetResult(CANAL_3);    
    
             adcVal[CANAL_4] = ADC_GetResult(CANAL_4);    
    
             canal++;    
    
             mVolts = ADC_CountsTo_mVolts(canal, adcVal[canal]);    
    
                 
    
                 
    
             EnviarCanalDeVoltaje(canal,mVolts);    
    
              
    
         if(canal > CANAL_4)    
    
         {    
    
             canal= CANAL_1;    
    
         }    
    
         }    
    
     }    
    
          
    
     static void EnviarCanalDeVoltaje(uint8 canal,int16 volts)    
    
     {    
    
             
    
         UART_UartPutString("Canal");    
    
             
    
         canal++;    
    
             
    
         canal += ASCII;    
    
             
    
         UART_UartPutChar(canal);    
    
             
    
         UART_UartPutString("=");    
    
             
    
         UART_UartPutChar((volts/1000u)+ ASCII);    
    
         volts %= 1000;    
    
         UART_UartPutChar((volts/100u) + ASCII);    
    
         volts %= 100;    
    
         UART_UartPutChar((volts/10u) + ASCII);    
    
         volts %= 10;    
    
         UART_UartPutChar(volts + ASCII);    
    
         UART_UartPutString("mV");    
    
         UART_UartPutCRLF(0u);    
    
     }    
   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

No need to repeat everything, just post your complete project so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file (do NOT use chrome, that still may not work).

   

 

   

Bob
 

0 Likes
lock attach
Attachments are accessible only for community members.
feme_285141
Level 4
Level 4
0 Likes
feme_285141
Level 4
Level 4

I would like to see as uartUSB step to get the data and I have an error adc_countsTo_mVolt (channel, adcVal [channel]) function is not that ???

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

This -

   

 

   

        mVolts = ADC_CountsTo_mVolts(channel, adcVal[channel]);

   

 

   

should be changed to -

   

 

   

ADC_SAR_Seq_CountsTo_mVolts( adcVal[channel] );

   

 

   

You have 9 UART functions that are typed as UART_UARTxxxxxxx, the typing should be

   

UART_xxxxxxx

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Check the APIs, probably you looked into some datasheets from PSoC4. Names are UART_PutChar() and not UART_UartPutchar. Same applies to the number of parameters for the ADC_CountsTo_mVolts(),#

   

 

   

Bob

0 Likes
feme_285141
Level 4
Level 4

Thanks served me advice

0 Likes