11 Replies Latest reply on Aug 13, 2014 11:20 AM by user_14586677

    adc_Sar_seq programming of 8-channel

    user_304190885

       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);    
          
           }    
         
        • 1. Re: adc_Sar_seq programming of 8-channel
          user_14586677

          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.

          • 4. Re: adc_Sar_seq programming of 8-channel
            user_1377889

            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

            • 5. Re: adc_Sar_seq programming of 8-channel
              user_1377889

              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

              • 6. Re: adc_Sar_seq programming of 8-channel
                user_304190885

                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);    
                    
                     }    
                   
                • 7. Re: adc_Sar_seq programming of 8-channel
                  user_1377889

                  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
                   

                  • 9. Re: adc_Sar_seq programming of 8-channel
                    user_304190885

                    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 ???

                    • 10. Re: adc_Sar_seq programming of 8-channel
                      user_14586677

                      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.

                      • 11. Re: adc_Sar_seq programming of 8-channel
                        user_1377889

                        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

                        • 12. Re: adc_Sar_seq programming of 8-channel
                          user_304190885

                          Thanks served me advice