1 2 3 Previous Next 30 Replies Latest reply on Dec 31, 2011 1:31 PM by JoMe_264151

    multi sample ADC (newbie question)

       Hi There,




      I'm fairly new to PSoC and am not sure how i can implement the following:


      I have a 200kHz PWM that's on for 300uS occuring every 50Hz. I used timers to properly set this up and it works well. Now I would like to have an ADC that takes as many samoples as possible while the PWM is active. So it would be like a Multi-Sample but only for a specific time. If I hook my Soc pin up to the pulse to the PWM enable pin, it will just start and keep taking samples, right? How do I actually stop the ADC conversion (not in code but in the schematic)?





        • 1. Re: multi sample ADC (newbie question)

          The datasheet says "ADC conversions continue until either theADC_StopConvert() or ADC_Stop() functions are executed."


          So it doesn't look like you can stop convering in hardware.


          Regards, Bob

          • 2. Re: multi sample ADC (newbie question)

             Yep, I read this too, so if there's no possibility to stop it otherwise, can I then trigger an interrupt when one of my lines changes its state so that my program can keep sync?



            • 3. Re: multi sample ADC (newbie question)

              Can you tell us what is your requirment?


              You mentioned ADC and PWM, What line changes your are referring to? The output of the pwm? When you said Sync, you mean sync of the ADC sampling and PWM operations?

              • 4. Re: multi sample ADC (newbie question)

                 I have a timer that kicks in every 50Hz continously. That pulse again, resets another counter that will hold a line low for 300uS (in one shot mode). I invert that line to get a 300uS pulse every 20ms(50Hz). now that pulse goes into an AND gate with the PWM being on the other input and so i end up getting my 300uS PWM pulse every 20ms. Now what I wanr is, I want to take about 5 ADC measurments from a feedback line while the PWM is active. I am awaer that I can connect the ADC's soc line to the 300uS pulse to start the conversion but how do I signal it to stop again? There's no "enable" on the ADC.


                Thanks for hints & suggestions!



                • 5. Re: multi sample ADC (newbie question)

                   As a hack i probably could juast select an external clock source and only have the clock source active while I wanna sample the feedback but that doesn't seem that "clean" to me. I'm wondering if i could do it differently, i.e. by reading the 300uS line state in software and have an interrupt fired every time it goes low...?





                  • 6. Re: multi sample ADC (newbie question)

                    I can think of a few way to do this


                    1. use a counter of 5, start it at the edge of your 300uS by an interrupt signal,
                    the counter counts number of EOC from the ADC and when it reaches 5, generate an interrupt and in the ISR stop the ADC.


                    2. Same as you mentioned, stop the clock of the ADC, but I am not sure if that would have other side effects,
                     so I would not do this.
                    3. I having try this but this should work. Similar to 1 but use DMA and make it perform 5 transaction and at the end of the transaction,
                     generate an interrupt and stop the ADC in the ISR

                    • 7. Re: multi sample ADC (newbie question)

                       Apart from the methods lleung has suggested(DMA looks the cleanest),We can also use the existing ISR in the ADC.Have a pin state read there,which then calls StopConvert or Stop.


                      You could also add that change to the component itself,so you may re-use this functionality.


                      One thing we can try is modifying the schematic of the component and add an additional pin,and thats connected to an IRQ which calls the StopConvert or Stop functions,but then thats basically the same thing.


                      The stop convert function switches off power to a number of sub-blocks,by writing to various internal registers.Linking that to hardware schematics,is via an interrupt,the way I see it.

                      • 8. Re: multi sample ADC (newbie question)

                        Hi reggler,




                        There are many suggestions already provided.


                        Another way of doing is by using a Timer/Counter to trigger the SOC when the 300us pulse is present (by ANDing the Timer/Counter output with the 300us pulse output).


                        If you intend to take, say 5 readings then you would require a conversion every 60us. Hence the conversion rate of the ADC should be greater than 16.7kSPS. Make sure that the resolution you have chosen allows you the required conversion rate.




                        The EOC can be used to read the converted values. The ADC will generate an EOC pulse only when the 300us pulse is active.

                        • 9. Re: multi sample ADC (newbie question)

                           Hi Dasq,








                          I now hooked up my 300uS line to an AND gate, the other input is coming from a timer that kicks in every 60uS, then the output from that AND gate goes to the soc of my ADC which is configured to 10bits at a conversion rate of 17000 SPS in Single Sample mode. My code looks like this:










                          LCD_Position(0, 0);


                             LCD_PrintString("IRfeedback       ");


                                  /* Place your application code here. */


                          //for(i = 0; i<=2; i++){




                                  /* Wait for end of conversion */




                                  IRfeedback = ADC_GetResult16();


                          if (IRfeedback < MIN_COUNT)




                                      IRfeedback = MIN_COUNT;




                                  /* Used to remove the count beyond 8 bit value, see resolution section


                                   * in DelSig ADC datasheet */


                                  else if(IRfeedback > MAX_COUNT)




                                      IRfeedback = MAX_COUNT;








                                      /* Continue */






                          AVGfeedback = IRfeedback;


                          LCD_Position(0, 11); 














                          It seems like it's reading the value once only and then it would get stuck in ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) and not get out of there anymore but if I hook up a debug pin to the ADC's soc, I can clearly see 5 pulses with my scope. What am I doing wrong? 


                          Hints or suggestions appreciated!


                          Thank you!

                          • 10. Re: multi sample ADC (newbie question)

                            Would you mind to zip your project and upload it here so that we can check everything? (when you run a "Cleanup" before, the fil will get smaller)



                            • 11. Re: multi sample ADC (newbie question)

                               Can do!
                              Please see attached!




                              Thank you!



                              • 12. Re: multi sample ADC (newbie question)

                                 I don't see the attachment - retry.

                                • 13. Re: multi sample ADC (newbie question)

                                   Didn't seem to work again - try this instead: http://dl.dropbox.com/u/15963911/MyLRB.zip

                                  • 14. Re: multi sample ADC (newbie question)

                                    I think, here is a limit for uploads of 2MB and your Project has 11MB.


                                    I'm working on it...



                                    1 2 3 Previous Next