9 Replies Latest reply on Jun 22, 2016 7:57 AM by ionascu.marianemanuel_1654946

    ADC SAR Sequencer - proper way to be used

    ionascu.marianemanuel_1654946

      Hello everybody,

         

      I am new to PSOC 4 BLE and to Bluetooth in general and because we will use in the future the products from cypress I want to learn as much as possible. In one of the first test projects that I was working on in order to measure some parameters of the board I hit a problem regarding the ADC Seq. I am not able to put the code here(even if it is a test one) because of copy right issues but I will explain the project and how I conclude that the problem is with the ADC.

         

      At the core the project has the examples from application note AN92584 : http://www.cypress.com/documentation/application-notes/an92584-designing-low-power-and-estimating-battery-life-ble

         

      In the design (.cysch) I have the following: a RTC, a Pin for LED(SW), the ADC SAR and of course the BLE.

         

      The BLE is Peripheral, Server and has a custom service with a big characteristic of 80 char values.

         

      The RTC: is configured to generate an interrupt at every 32 seconds and uses the WCO Low Power and the Timer 2 WDT2.

         

      The ADC SAR: has 4 input pins sets to (P3.0, P3.1, P3.2, P3.3) set as high impendence analog, VRef is internal 1.024 volts, single ended negative set to Vref, free running, Clock frequency 1kHz all using A clcks, INJ is not check as enabled.

         

      The app should to the following: init ADC, and Disable the IRQ for ADC, init RTC; Process BLE events updates the characteristic of BLE and notify, and as a code for the RUN part of AN92584 do the following:

         

      ADC_StartConvert();

         

      ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);

         

      ADC_StopConvert();

         

      Then read all 4 adc chanels , process the values, and go to Deep sleep if possible(depending on the BLE). Every time the RTC elapses(32s) the above 3 lines of code + the reading of the adc and processing the value are executed.

         

      I have observed that the ADC blocks at IsEndConversion and never exits. Why? I hope you will explain me if what I was doing is ok. It is a best practice to start and stop the ADC after each conversion + disable its interrupts? Are the pins for Analog correct set?

         

      In all the examples that I saw the first 2 lines of code was executed before the infinite loop and then only the get result was called, but I do not need to have the ADC converting all the time but only at 32 s. Should I use the trigger mode and maybe someone can explain how?

         

      I want to mention also that the code was tested without the ADC and it behaves ok, I can read the characteristic(of course I cannot see if it is correctly modified since the adc is not working), it enters correctly the sleep modes. the RTC sends correctly the interrupt at 32 s.

         

      Thank you very much and hopefully I was clear in my text!

        • 1. Re: ADC SAR Sequencer - proper way to be used
          user_1377889

          Welcome in the forum!

             

          Probably only guesses possible, there are too many possibilities. I would suggest you to get in contact with Cypress directly and send them a complete project archive. Cypress will keep your project information confidential.

             

          To do so, at top of this page select "Design Support -> Create a Support Case" and describe your problem.

             

          in Creator->File->Create Workspace Bundle (minimal)
          and attach the resulting file.

             

           

             

          Bob

          • 2. Re: ADC SAR Sequencer - proper way to be used
            ionascu.marianemanuel_1654946

            Hello Bob,

               

            Thank you very much for the advise, I will do so! It is very strange because even if I run the simplest example project involving the ADC and a BLE module, using the application note for power consumption, after a disconnect from BLE the code stops in ADC but I do not know exactly why. Thanks again! 

            • 3. Re: ADC SAR Sequencer - proper way to be used
              cjoachim_1597296

              I've been using the ADC in free running mode (ADC_StartConvert()) and just read the channel I need with ADC_GetResult16(uint32 chan) . I have not had any problem with that (but maybe I have been doing something wrong?).

              • 4. Re: ADC SAR Sequencer - proper way to be used
                ionascu.marianemanuel_1654946

                I've found something in an example and also in datasheet:
                            /* Note: Calling ADC_Sleep twice will disable ADC. ADC_Start function
                            *  should be called instead of ADC_Wakeup function to re-enable the ADC
                            */

                   

                Maybe this cause the problem but I have also removed the call to Sleep and the problem persists.

                   

                In response to speedycat: I do not need the ADC to work permanently, I only want to trigger a conversion from SW when my RTC triggers an alarm and in any other situation I need it stop/sleep.

                • 5. Re: ADC SAR Sequencer - proper way to be used
                  ionascu.marianemanuel_1654946

                  Hello everybody,

                     

                  It seems that the code is now working somehow b adding a check for the issue states in my last comment but there are also some other problems. One of them that I found is the following and I want to ask you if there is something wrong with my thinking:

                     

                  I have tested the application using only let say values for the ADC: GND, VCC, and open connection since I do not have an potentiometer or other tools to try multiple values and I have observed that some inputs are linked together. For example if I apply GND to ADC input 1 then also the input 2 is put on GND and other combinations like this.

                     

                  My input pins are P3[0],P3[1], P3[2], P3[4]. I have also managed to obtain the permission to attached the code. Maybe there is something I forget.

                     

                  The idea of the project is : initialize a structure and initialized the BLE characteristics with some values(vInitSensors function). as a processing there is a arithmetic mean made of last 10 conversions and is sent to another BLE characteristics. As I explained in other posts there application uses the AN about sleep conditions for BLE.

                     

                  Here it is:

                  • 6. Re: ADC SAR Sequencer - proper way to be used
                    user_1377889

                    Unconnected analog input pins tend to float, thus picking up any voltage.

                       

                    You use

                       

                                ADC_StartConvert();
                                ADC_StopConvert();  
                                ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);

                       


                    The StopConvert() will halt the ADC's functionality before any valid conversions have been made.

                       

                    I would suggest to have the ADC free running by putting the StartConvert() before your infinite loop and removing the StopConvert.

                       

                    Before reading the results use IsEndConversion() as you already did.

                       

                     

                       

                    Bob

                    • 7. Re: ADC SAR Sequencer - proper way to be used
                      ionascu.marianemanuel_1654946

                      Hello Bob,

                         

                      Indeed they are floating but I do not understand why putting one at GND or VCC causes the same result for other ADC inputs. I expected that only the pin that has applied the GND or VCC to go to -1 (since it is a singed) or 2048 respectively. 

                         

                      Also regarding to your comment about StopConvert according to datasheet: Forces the ADC to stop conversions. If a conversion is currently executing, that conversion will complete, but no further conversions will occur. Therefore that is why I put the stop immediately after start. I moved it after the isEndConversion call but there is the same "connection" between ADC inputs. I will also try to buy some potentiometers or other components to test the ADC. Maybe you are completely right and the problem resides in the fact that all of the connection are floating.

                         

                      I did not put the start converting before my infinite loop because I try to only process data when a timer elapses(RTC timer) once at 32 seconds, and in the rest to keep the system in deep sleep, of course if the BLE permits this.

                         

                      The main reason for this test is to see how much power does it consumes and how much time does the processing( ADC conversion+read, average of the values, some computation over the values(there is an old formula commented), write and notify the client) take to finish. Of course this is for comparison reason to see if PSOC 4 BLE, CY8C4248LQI-BL583(483) consumes less then a combination of an ARM M0+ microprocessor + the nRF8001 Nordic Bluetooth. In this moment the results are not so in favor for PSOC but I still insist because I personally like it more!

                      • 8. Re: ADC SAR Sequencer - proper way to be used
                        user_1377889

                        Did you read AN92584? That will give you some hints for low power applications.

                           

                         

                           

                        Bob

                        • 9. Re: ADC SAR Sequencer - proper way to be used
                          ionascu.marianemanuel_1654946

                          Hi Bob,

                             

                          Yes I used that in my design. I did many tests using simple BLE application. The one presented here just wants to evaluate the board with processing at 32 s and as much as possible deep sleep.