Announcements
IMPORTANT: Cypress Developer Community currently doesn’t allow sign-in to prepare for the upcoming transition. To learn more, check out our announcement.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1

Anonymous
Not applicable

 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
 

0 Likes
30 Replies
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

 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

0 Likes
Anonymous
Not applicable

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?

0 Likes
Anonymous
Not applicable

 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

0 Likes
Anonymous
Not applicable

 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

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

 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
 

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

 Can do!
Please see attached!

   

 

   

Thank you!

   

roN
 

0 Likes
Anonymous
Not applicable

 I don't see the attachment - retry.

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Expert II

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

   

I'm working on it...

   

Bob

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

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

   

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

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

 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!

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

 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

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Bob_Marlowe
Expert II

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

   

Bob

0 Likes
Anonymous
Not applicable

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.

0 Likes
Bob_Marlowe
Expert II

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

0 Likes
Anonymous
Not applicable

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 !

0 Likes
Bob_Marlowe
Expert II

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

0 Likes