Measurering intervals between pulses ??

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Measurering intervals between pulses ??

Post by ksor »

I have made a program for COUNTING revolutions and RPM measurement and it's working fine - EXCEPT ...

in the RPM mode the display is very unstable because of noise (I plug/unplug a power adapter in the outlet besides the power adaptor to my HW).

When I do NOT make noise this way the display is very, very stable - and I have made it even more stable by displaying the average of the last 5 readings.

I have tried a lot of things in the HW - big caps, 10K from my RB0 interrupt pin to ground, SmithTriggers - but still I can introduce noice (=flickering numbers in the display) by plug/unplug a power adaptor. :evil: :evil: :evil:

I still have my HW on a breadboard - but setup reaseable with short wires, caps across the power, x-tal nearby the PIC and so on.

Can I do something in the software ? - something like - just loose thinking:

I have an incomming puls on interrupt RB0 and I want to measure the time between two incomming pulses - and IF NOISE is introduced, then the next puls (the noise puls) must come faster than "normal" and I can then neglate this "too fast comming puls".

To allow acceleration and deceleration I'll have to accept a "gap" in the time measurering.

From a STABLE reading I can calculate the exspected time interval to the next REAL puls (+/- something) - if a puls comes faster (it's a noise puls) and I'll have to neglate this puls.

How can I use timers for this purpose - like a stopwatch - and without loosing any "real" pulses on the input - I allready use TMR0.

Maybe it's completely non-sense to try cure noise problems this way - then STOP me right away ! :lol:
Best regards
KSor, Denmark

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Measurering intervals between pulses ??

Post by Benj »

Hello Ksor,

Its best to stop noise before it gets into the system if at all possible, Software workarounds are always a little flawed.

Have you tried using a combination of a large electrolytic capacitor with a small ceramic capacitor. The large electro filters out any large spikes and the ceramic will take out all the high frequency and RF noise.

If this is still not working then maybe try making a filter using a resistor and capacitor. You can find frequency calculators that will help you to find a good set of values for your components.

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Measurering intervals between pulses ??

Post by ksor »

Hi again

Combiing SmithTrigger and RC's has rouled out the noise failure completely ! 8) 8) 8)
Best regards
KSor, Denmark

ksor
Posts: 126
Joined: Mon Oct 23, 2006 3:50 pm

Re: Measurering intervals between pulses ??

Post by ksor »

But anyway I need to measure the time between two pulses - how do I use a timer for that ?

I allready use TMR0.
Best regards
KSor, Denmark

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Measurering intervals between pulses ??

Post by Benj »

Hello Ksor,

Best way is to configure the timer using C code to work on a certain prescaler etc.

t1con = 0x09; //T1 on with 1:1 prescaler

Firstly detect the first pulse maybe using a edge triggered interrupt and then use C code to initialise the timer count registers to 0.

tmr1l = 0x00;
tmr1h = 0x00;

Next time you get the interrupt edge save the timer count registers into a variable.

FCV_INT_VAR = tmr1h << 8;
FCV_INT_VAR = FCV_INT_VAR | trm1l;

The device datasheet has a section on the timers which should help you.

Hope this helps.

Post Reply