2 Replies Latest reply on Jun 1, 2017 9:18 AM by gavyus_2402711

    Duty Cycle Measurement

    gavyus_2402711

      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

        • 1. Re: Duty Cycle Measurement
          user_1377889

          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

          • 2. Re: Duty Cycle Measurement
            gavyus_2402711

            thank you for the rapid response!

               

            i'll try it!