cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1

Anonymous
Not applicable

 Good morning,

   

I don't manage to find a solution to measure the duty cycle in a PWM signal . I have to measure firstly a constant duty cycle for one signale, secondly i have to treat a signal with variable duty cycle ( such as a sine turned into a PWM modulation) ? How to solve the problem ?

0 Likes
26 Replies
Bob_Marlowe
Expert II

Easiest approach will be to use a timer that counts on a given internal frequency. The capture input of the timer will save the actual count which you can read-out in a connected interrupt where you reset the timer again.

   

When using two of these construct you are able to measure both the high-time and low-time of your signal.

   

 

   

Bob

0 Likes
ETRO_SSN583
Esteemed Contributor

Something like this ? D produces a high pulse = period width of PWM inout, its ISR

   

reads and resets counter.

   

 

   

Set capture on - edge, with ISR enabled in component, capture width

   

of PWM high time when ISR fires and capture register read.

   

 

   

Resolution clk show = 1 uS measurement resolution, 16 bit counter

   

can count a period up to ~65K us.

   

 

   

I think you can replace D and its inverter with a T F-F, just did not look at this.

   

 

   

Regards, Dana.

   

 

   

0 Likes
ETRO_SSN583
Esteemed Contributor

One mod, move PeriodISR to falling edge of period indicator from D, eg. the output

   

of inverter / data input to D.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

hello Dana , i need the PWM measurement too. I will give your schematic a try, but i miss some detail info about the proper Counter configutration.

   

maybe you even have this as little creator project at hand to share.  b.r. Markus

0 Likes
ETRO_SSN583
Esteemed Contributor

I have a project, but not working. Seems interrupts not working the way

   

I wanted, so stumped at the moment, and today have other commitments

   

so cannot work on it.

   

 

   

The project is PSOC 3 based, runing on -030 board, so you would have to

   

change device, and should compile into PSOC 5 OK, or so I think.

   

 

   

Note I fixed all re-entrant errors in project, so on PSOC 3 compiles w / no

   

errors or warnings.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

thanks Dana for sharing your project.

   

i did porting to kit LP050 and some code workaround (and both ISR).

   

but results are still not the way i want. 😞

   

i have no possiblity to change PeriodISR to falling edge as mentioned.

   

the result i want to get for lcd is:1st line: D.C.xx.yy %

   

                                                   2ndline : Frequency:xx.yy kHz

   

can you pimp my projectcode for doing so ?

   

my test signal is TTL 1.02kHz fixed frequency and 0.01 to 99.90% variable duty cycle

   

from a 2D-rotation hallsensor(360° in 12bit-PWM_angle resolution).

   

need the correct duty-cylcle value for further calculations of position-change speed..

   

b.r Markus

0 Likes
ETRO_SSN583
Esteemed Contributor

The period ISR taken off the D output, then inverted, is effectively falling

   

edge, end of the period. The D high time, or its low time for that matter, either width, is =

   

period of the input signal. So you set the period ISR to rising edge, the D and inverter

   

take care of the rest.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

Attached is a basic project you can modify to suit your needs. Measures pulse width

   

and duty cycle. It does this not on every input cycle as it is not a pure HW approach

   

and I chose to do it with one timer. With two timers you could do it on a per cycle basis,

   

or use Verilog for an optimal; solution.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

hello dear dana,

   

thank for your reviewing my project and make it work.

   

best regards Markus

0 Likes
Bob_Marlowe
Expert II

@Markus

   

Where are you located? I live near Bremen, Germany

   

 

   

Bob

0 Likes
ETRO_SSN583
Esteemed Contributor

Here is another approach, using a continuously running fixed function counter,

   

takes less resources, simpler.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

@Bob

   

I live near Augsburg and work in Kaufbeuren (Allgäu).

   

greetz from southern Bavaria.  Markus

0 Likes
Anonymous
Not applicable

hello dear dana,

   

thank you for sharing your simplified project. As it works fine on PSoC5LP so far, I like to port your latest Creator-project to

   

PSoC4000 ( CY8C4013SXI-410) device for having a very small and low-cost solution for wanted flow-meter application comunicating via I2C to host device (PSoC3 based).

   

unfortunately there is no logic inside the small PSoC400 device, so i consider to use external inverter

   

and two pins for inputig the PWM-test signal.

   

PSoC'in is challenging fun.

   

best regards Markus

0 Likes
Bob_Marlowe
Expert II

You may use a CY8C4245xxx which you can get for $1 at this time in single quantities and that chip includes some logic.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

@Bob

   

I consider the PSoC42xx device for a more valuable flowmeter with segment LCD drive, also but later to come.

   

The PSoC4000 device family came to my mind, while it is the tinyest part with low-pincount (SOIC-8) Cypress offers,

   

also operating from  same +5Volt voltage rail as Hall sensor IC.

   

planned PCB will have round shape with only 17mm diameter carrying a 4-Pin Molex picoblade (1.25mm) Conector, Hallsensor IC (SOIC-8), PSoC and bypass capacitors to fit the flowmeter hardware. Parts will be mounted on both sides of a doublesided PCB.

   

Size matters in this particular case, to keep design simple and cheap.

   

Otherwise i would like to use the more powerful PSoC's of course.

   

I dont want to use an old 8-bit PIC for new design....so i give the PSoC4000 family a try.

   

have a nice weekend. greetz  - Markus

0 Likes
ETRO_SSN583
Esteemed Contributor

Possibly you could use the pin configurable interrupt (it has a falling edge

   

selection) to get the  - edge interrupt for the high time measurement.

   


   

Regards, Dana.

   

 

   

0 Likes
ETRO_SSN583
Esteemed Contributor

Looks like part cost is 40% less -

   

 

   

0 Likes
ETRO_SSN583
Esteemed Contributor

Paste did not work -

   

 

                                                                                            
CY8C4013SXI-410In ProductionNPSoC 4000SOIC-40 - 85DatasheetUS$0.60
0 Likes
Anonymous
Not applicable

hello dear Dana

   

I gave your suggestion for the pin with interrupt generation ( falling edge ) a try, but got only ridiculous readings.

   

any idea what to change to make it work like your solution with inverter included ?

   

regards  Markus

0 Likes
ETRO_SSN583
Esteemed Contributor

You may be affected by oring of GPIO for interrupts, and not clearing

   

ISR. Take a look at this thread, towards the bottom -

   

 

   

    

   

          http://www.cypress.com/?app=forum&id=2232&rID=74969

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Esteemed Contributor

Attached is project using pin ISR connection, only real change was

   

clearing interrupt of pin in the pulse high falling edge ISR.

   

 

   

Regards, Dana.

0 Likes
ToVa_285016
Contributor
0 Likes
ToVa_285016
Contributor
        Hi, I am having trouble typing in the 'description' box in Chrome to begin with... But what I really want to ask is how to implement this fine example program with a PSOC 4 series. There is no fixed 16b counter module, and my substitution of the Timer Counter in the PSOC 4 components is not working. The data values are erratic, producing duty cycles well over 1. Please take a look if you can. Thanks in advance, Tom   
0 Likes
ToVa_285016
Contributor
        Never mind, I changed it to a 1mhz clock, and it is counting them correctly. Tom   
0 Likes
Anonymous
Not applicable

Hi,

well, I apologize for warming this up again, I am new to PSoC and I am trying to port this project to a PSoC 4 (4245 Chip) and I am loosing hair at an alarming rate. Please, can someone help me or point me in the right direction as I am having to use an UDP counter.

Many Thanks

0 Likes
Vasanth
Moderator
Moderator

Hello Kayle,

We recommend you to create a new thread with your query with the right key word as subject rather than adding your query as comment to an old thread. You might not get the attention from our contributors when you comment on an old thread and also we recommend to keep the discussion aligned with the question asked in the thread, so that it will be helpful for other members who are searching for answers.

Best  Regards,
VRS

0 Likes