Duty Cycle Measurement

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

i am using a demo board of CY8CKIT-043 with very low resources (32 macro-cell)
could you write a short code the do the folowing:
input= digital INPUT, random behaviouer of 0 or 1
output, digital= error1, error2
Period= every 50mS
clock=1MHz (or equvivalent)
( a 50mSec period has 50,000 pulses of 1MHz clk)
for each period
start with count=0
for each clk:
if INPUT=1, count=count+1
if INPUT=0, count=count (no change)
at period end:
if count is <30% , then error1="1" [30% of 50,000]
if count is >36% , then error2="1" [36% of 50,000]
else error1=error2="0"
repeat period endlessly

thank you!!!!
Itzhak Gavyus

0 Likes
2 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum.

   

We usually do not solve your projects by programming them.

   

But we can give you some hints:

   

Use a timer/counter (TCPWM) to get your cycle-time of 50ms

   

Use a second TCPWM and configure the "count" input, connect that to your INPUT.

   

At tc of the first timer, stop the second one, read its current value,clear counter and start again. Signal your main() infinite loop that a cycle is ready and the new value might be inspected.

   

You may play a bit with capturing the 2nd counter etc.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

thank you for the rapid response!

   

i'll try it!

0 Likes