Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > multi sample ADC (newbie question)

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



multi sample ADC (newbie question)
Moderator:
ANCY

Post Reply
Follow this topic



multi sample ADC (newbie question)

reggler posted on 28 Dec 2011 10:57 AM PST
Senior Member
18 Forum Posts

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

Thanks,

Ron
 




Re: multi sample ADC (newbie question)

Bob Marlowe posted on 28 Dec 2011 11:11 AM PST
Top Contributor
1768 Forum Posts

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

 



Re: multi sample ADC (newbie question)

reggler posted on 28 Dec 2011 02:07 PM PST
Senior Member
18 Forum Posts

 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?

Thanks,
roN



Re: multi sample ADC (newbie question)

H L posted on 28 Dec 2011 02:32 PM PST
Top Contributor
679 Forum Posts

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?



Re: multi sample ADC (newbie question)

reggler posted on 28 Dec 2011 03:10 PM PST
Senior Member
18 Forum Posts

 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!

roN



Re: multi sample ADC (newbie question)

reggler posted on 28 Dec 2011 03:14 PM PST
Senior Member
18 Forum Posts

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

Thanks,

Ron



Re: multi sample ADC (newbie question)

H L posted on 28 Dec 2011 04:00 PM PST
Top Contributor
679 Forum Posts

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



Re: multi sample ADC (newbie question)

kmmankad posted on 28 Dec 2011 05:28 PM PST
Top Contributor
268 Forum Posts

 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.

 



Re: multi sample ADC (newbie question)

Gautam Das posted on 28 Dec 2011 08:39 PM PST
Cypress Employee
742 Forum Posts

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.



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 10:33 AM PST
Senior Member
18 Forum Posts

 Hi Dasq,

 

Okay,

 

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:

 

    while(1)

    {

LCD_Position(0, 0);

   LCD_PrintString("IRfeedback       ");

        /* Place your application code here. */

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

        /* Wait for end of conversion */

        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT); 

        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;

        }

        else

        {

            /* Continue */

        }

//}

AVGfeedback = IRfeedback;

LCD_Position(0, 11); 

        LCD_PrintNumber(AVGfeedback);

    }

 

 

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!
roN
 

 



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 11:38 AM PST
Top Contributor
1768 Forum Posts

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)

Bob



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 12:04 PM PST
Senior Member
18 Forum Posts

 Can do!
Please see attached!

 

Thank you!

roN
 



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 12:18 PM PST
Senior Member
18 Forum Posts

 I don't see the attachment - retry.



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 12:22 PM PST
Senior Member
18 Forum Posts

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



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 12:33 PM PST
Top Contributor
1768 Forum Posts

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

I'm working on it...

Bob

 



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 12:44 PM PST
Top Contributor
1768 Forum Posts

Ha, you've set the ADC's conversion mode to single sample! So you can wait a fortnight for the nect sample to get ready! Question is: What did you see on your skope???

 

Bob

 



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 12:54 PM PST
Senior Member
18 Forum Posts

 Yep, Single sample = once per pulse on soc - no?

I see 5 pulses (with 60uS distance to eachg other) on the scope...



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 01:04 PM PST
Top Contributor
1768 Forum Posts

I see.

But when you set a breakpoint to the "if" and set the hit count to five, program stops after 5 ADC-conversions (on my system Kit001 CY8C5588-60 ES1)

Bob

By the way: if there are interrupts in a system the debugger behaves somtimes a bit queer and seems not to leve a breakpoint-line. removing a brekpoint and setting it to next line shows that



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 01:14 PM PST
Senior Member
18 Forum Posts

 I'm not sure which if() you're setting the breakpoint to and why also i'm not sure what you mean by "hitc ount" - could you clarify please?
Thanks!



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 01:19 PM PST
Top Contributor
1768 Forum Posts

Set breakpoint at line

  if (IRfeedback < MIN_COUNT)

 

Click right on the breakpoint and select "Hit count" and in the pop-up window set the value to five. (works similar with the breakpoint-Window, which you must activate first)

Hope this helps

Bob

 



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 01:47 PM PST
Senior Member
18 Forum Posts

Huh,  I don't get it, 

 

Now I tried to set the ADC to multi sample and inserted this code just after the ADC_GetResult16(); line:

 

ConvCnt++;

/* Disable ADC after 5 conversions */

if (ConvCnt >= 4) {

ADC_Stop();

ConvCnt = 0;

}

UI thought I want to stop the adc after 5 samples and it would get restarted by hardware when it receives a pulse on the soc pin. But this doesn't seem to work either...  

 



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 02:10 PM PST
Top Contributor
1768 Forum Posts

No, you are wrong, your design was working! But when you debug your program (Setting a brekpoint) what do you expect what your hardware does in the mean-time? it runs! It was only your program that has stopped!

Go to: Help-> Topics->Index   select "Breakpoints" and read what you may specify here.

Bob

 



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 02:50 PM PST
Senior Member
18 Forum Posts

 No, it didn't work for me. When i set the hit count to 5 and let it run, the program never stops at the breakpoint (at Single Sample mode). It is stuck in "ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);" while the hit count is at 1 only - so one conversion got read only....



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 03:03 PM PST
Top Contributor
1768 Forum Posts

This I don't have an eplanation for. Here it runs perfectly, although I had to change the device to cy8c5588-60. Are you using a Cypress-Kit or an own board?

Bob



Re: multi sample ADC (newbie question)

reggler posted on 29 Dec 2011 03:15 PM PST
Senior Member
18 Forum Posts

 I'm running on a Cypress Dev kit, the CYC8KIT-050 but I figured out what was wrong. Looks like the pulse from the ADCTimer is too short for the ADC, if I put a T-Flipflop in between, it seems to work fine - but I only get to measure every 2nd pulse...Do you have an idea how I could make that pulse from the timer a little longer otherwise?

 

Thanks  for sticking with me so far!

roN



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 29 Dec 2011 03:21 PM PST
Top Contributor
1768 Forum Posts

Well, you could use a compare output which can be set to something longer than the clock period. (take care, the timer-counter counts backwords)

The Pulse-counter tc-output is rather short as well, use the same technik here.

 

Going to bed now

Bob



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 30 Dec 2011 10:02 AM PST
Top Contributor
1768 Forum Posts

Does this one work for you? (Remember to change the device to your chip 5568)

Bob

 



Re: multi sample ADC (newbie question)

Gautam Das posted on 31 Dec 2011 04:52 AM PST
Cypress Employee
742 Forum Posts

Hi reggler,

 

After looking at your code, I have made the following observations:

1) When hardware is used to trigger the SOC of ADC, it is not required to use the "ADC_IsEndConversion(ADC_WAIT_FOR_RESULT)" API. Instead the EOC, which is triggered once the conversion is done can be made use of. An array can be declared to store the values during the burst of conversion. Once the conversion burst is over (300us), you can do all the comparison at once.

 

2) Is the logic used in assigning the minimum and maximum count right?

When the ADC value obtained is less than the MIN_Count, you are assigning

IRfeedback = MIN_COUNT;

 

And similarly, when the ADC value is greater than MAX_COUNT, you are assigning

IRfeedback = MAX_COUNT;

I didn't understand the reason behind this operation.

 

As Bob has rectified, using PWM components to feed to the AND gate instead of Timer which signals the SOC is a right choice.

If DMA is used to transfer the converted ADC data to an array in SRAM using EOC as a source of trigger, the onus on CPU will greatly reduce.



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 31 Dec 2011 05:37 AM PST
Top Contributor
1768 Forum Posts

Hi dasq,

do not torture a newbee with DMA (I'd like to put a smiley here, but the editor will crash). Right, WHEN it runs, it runs fast without CPU intervention and is looking very professional.

The MIN and MAX assignments just seem to set an interval for the values, I cannot see something wrong with those...

 

We have 9 and a half hours left this year

Bob

 



Re: multi sample ADC (newbie question)

Gautam Das posted on 31 Dec 2011 06:00 AM PST
Cypress Employee
742 Forum Posts

Hi Bob,

 

Using DMA might not be intuitive for a beginner to PSoC.

Using the EOC to read the ADC values will be advantageous in this project and there is no necessity to poll in software for the conversion to complete.

I'm thinking of an easier solution for this.

 

Wish you a happy and prosperous new year !



Re: multi sample ADC (newbie question)

Bob Marlowe posted on 31 Dec 2011 11:31 AM PST
Top Contributor
1768 Forum Posts

Yeah! My highlight for the last 3 hous this year was:

Reading data from an ADC (Clocked with 500kHz) with a DMA-channel, transfering right into a low-pass-filter and using a second DMA-channel reading the data from that filter right into a memory - array! BANG!!!!

Wishing you all the best for the next year!

And may your DMAs never stall

Bob

 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20