Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic interrupt frequancy ? Pulse width ?

Status
Not open for further replies.

max_imum2000

New Member
hello
in previous post i attached a simple circuit that i connected a slotted optical switch to a pic to count revloutions of a motor shaft.
i used RB0 external interrupt on a pic16f628A to count the rising edges of the incoming signal.
the signal coming out form the switch wasnt enought so i put a small 555 to act as a trigger and it worked and the pic started counting
now the problem
if i rotate the motor by hand the counting is correct
however when i increase the speed , it looses counts and increasing the speed more the more i lose counts
for 1 rev of motor the switch is triggerd 4 times.
i think it has something to do with the pulse width , the more it is narrow the more it losses counts. (thats my guess , although i can be wrong)
or maybe the ext interrupt frequancy cant exceed certain level ??

i will appricate any help

thanks
 
Without seeing your code it's hard to be sure but I would guess that your ISR code is taking too long. You mention in your other post a LCD, are you writing to this in your ISR? Even a motor running at 30,000 RPM with 4 pulses per rev would give a frequency of 30000/60*4 = 2000Hz - well within the capabilities of the pic.

Mike.
 
well actually i am using a compiler, (mikroelektronika basic) and the code is really straight forward
check for interrupt, if found, go to the interrupt routine, increase counter and display it

but maybe you have a point here as compliers generate large code .
i will try to see into this

any other ideas might help
thanks
 
check for interrupt

Are you polling for the interrupt?

Your interrupt code should only increment the counter. Your main code should check if the counter has changed and display it if necessary.

Mike.
P.S. Can you post your code?
 
You could download the Lite version of proton+ and use the following. Sure you loose the functionality of being able to do things for a certain period of time with this command, but you only need to sample the signal then scale it up.

Syntax
Variable = COUNTER Pin , Period

Overview
Count the number of pulses that appear on pin during period, and store the result in variable.

Operators
Variable is a user-defined variable.
Pin is a Port.Pin constant declaration i.e. PORTA.0.
Period may be a constant, variable, or expression. (In milliseconds)

an example would be;

Dim Variable as Word

Main:

Variable = Counter, PORTA.0, 100
Print At 1, 1, "RPM = ", Counter * 100

Goto Main


To improve accuracy, simply increase the sample time.
 
If it was me, i would prefer to use internal Counter... TMR0 on RA.4 OR TMR1 on RB.6. Simpler, faster, better. Using INT0, you could indeed miss some pulse.

ClearTimer
StartTimer
Sampling time delay
StopTimer
Read Timer register

Make sure your pulse amplitude match the minimum PIC requirement. Some kind of hardware debouncing/filtering/conditionning could be implemented too...
 
You say you display the count inside the ISR routine? im guesing that means you write somthing on LCD...

this is generaly not a good idea to do inside an interupt routine as it may take some time to do the writing...

Try to move the code that updates the LCD display elsewhere ... in the main loop maybe (usualy you dont need to update the lcd display all that often ... 10 times per second should be plenty)

Im guesing your controller is working very hard to update the LCD display ... the way it sounds like you have it now, it would update lcd faster as speed increases ... this will cause exactly what you describe , it will loose pulses.

I find it is better to work with interupts thru flags. When an interupt is triggered, set a certain flag (like bool bCounterPulseTriggered). Then in the main loop of your program, check if this bool flag is set. If it is set, reset it and do whatever you need doing. This usualy makes for a safer code then doing a bunch of things inside the ISR routine.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top