PDA

View Full Version : Frequency reducer



retepsnikrep
- 14th February 2013, 12:42
I have a 12F683 pic recieving a stream of pulses from a device.

The mark space ratio is always 50% but the speed of the pulses varies from say 1hz upto 150hz.

Now what i want to do is time/measure the incoming pulses duration somehow and output on a different pin new pulses with the frequency reduced by say 30%

I thought about pulsin/pulsout but that won't work as you miss the start of the next pulse if you increase the length of the pulse you are sending out using that IIRC.

Any bright ideas? Or anyone done anything similiar before? Thanks

retepsnikrep
- 14th February 2013, 14:46
Looks like i need some sort of background interrupt on pin change driven service measuring the length of the incomming pulses and updating a variable with the pulse length.

The main program needs to look at this variable and then caluclate the length of the pulse it needs to sends out.

Once that pulse has been sent it then looks again at the length variable and adjusts itself accordingly as the incomming pulse freq changes.

A divide by 2 logic device might do the trick if i opt for a 50% reduction in frequency vbut how to do that with a pic?

HenrikOlsson
- 14th February 2013, 16:32
A divide by 2 logic device might do the trick if i opt for a 50% reduction in frequency vbut how to do that with a pic?
50% isn't hard (though a hardware flip/flop is even easier). Just wire the input signal to INT0 for example, set it up to interrupt on the rising (or falling) edge, toggle the output signal each interrupt. If you need anything but 50% you really need to measure the frequency/pulsewidth, calculate the new frequency/period and either adjust the period of a timer interrupt or use the CCP module to generate the desired output frequency.

/Henrik.

retepsnikrep
- 14th February 2013, 16:58
Henrik

Thanks i did try 50% and that works fine but I really need a divide by 1.5 rather than divide by 2, so will have to think further along the lines you suggest.

Acetronics2
- 14th February 2013, 17:18
Divide by 1.5 is to multiply per 2 and divide by 3 ...

Easily done vith "old" logic TTL or 4000 ...

Alain

retepsnikrep
- 17th February 2013, 07:28
Well I have DT Instant interrupts plumbed in with a flag now changing to indicate change of the pulse input pin (low to high) So i can measure the length of the full pulse length, but I'm a bit stuck now on how to use a timer to do that and have a timer running in the background keeping track of the extended output pulse. :?