duty cycle 50%

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm working on a project that basicly converts a number of pulses to another number of pulses.
The frequency of the incoming pulses is variable, duty cycle always 50%. Conversion factor is also a variable.
The conversion (100puls in --> 95 out, or 103out, or...) is no problem.

But the output needs also a duty cycle of 50%. Has anyone an idea on how to implement this? I prefer in assembler, but another language will do also (it's the concept i need)

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you need to better define what range of pulse frequencies will be seen as an input. This way you can make a better choice of how to implement your code that detects whether a pulsed input is present or not. For example, it would be difficult to quickly detect when you had a steady stream of pulses that ranged from 1 pulse per ten seconds to 1 pulse per second. I know this is probably an extreme scenario, but without defining a range your code can get pretty complex in order to handle too large of frequency detection range.

Also, how is the output pulse frequency selected? Based on your description, it seems like the following could be implemented:

if(pulse_freq > 100per_sec)
{
out_pulse_freq(selected_pulse_freq);
}

The function "out_pulse_freq()" could simply use the Waveform Generator function of the AVR to load the TOP count with the desired value to acheive the pulse frequency you need out and then divide the TOP count by two (shift the bits right one place) and load that value into the OCRn register to acheive the 50% duty cycle. Hope I have helped. Sounds interesting.

Oh, by the way, "selected_pulse_freq" would be the variable which would contain "TOP". Then the "out_pulse_freq()" function would load the registers with the correct values based on "selected_pulse_freq". I just used C code for sake of readability in this forum. As simple as a function this would be, assembly would definitely be better.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It sounds like the OP wants to make a count of discrete pulses at the input, make an
adjustment, and then send the new count of pulses out the output.

If this is true, you simply need to increment a counter with each input pulse,
apply the correction, and generate an output pulse, decrement the count,
and loop until the count is zero. You may need debouncing on the input
if it comes from a mechanical contact, and it seems a time reference
may be needed. For example when and for how long will you wait for
the incoming pulses before starting to send out the count-adjusted pulses?

Tom Pappano
Tulsa, Oklahoma

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, there is a lot we >>don't<< know about the problem. The frequencies involved. The precision needed. Is this a "frequency converter" with continuous input and output? If so, how fast should it respond to changes in the input signal's frequency?

Is this a "pulse train" as Tom asked? Then other questions are raised, as noted.

In any case, an AVR should be able to do the job micely up to several tens of kHz. There are several workable approaches depending on the specific requirements.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The input frequency ranges from almost 0 Hz upto 100Hz

The output frequency should be as close as possible the same as the inputfrequency. This is what it makes it difficult (to me)...

The input comes from an opto-pulser so no need to debounce.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
If so, how fast should it respond to changes in the input signal's frequency?

Back to what Lee mentioned... You need to know how fast the AVR should respond to a change in input frequency. As you said, the range is from "almost" 0Hz to 100Hz. "Almost" 0Hz could be 0.01Hz, or 1 pulse per 100 seconds. This means you would have to wait........a long time (in AVR time) to respond to a change at low frequencies. Would be good if you could limit it to 5Hz or maybe even 10Hz, but I don't know what the application is, or if that would work for you.

Clint