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.

Autorange rpm counter

Status
Not open for further replies.

Compasscard_be

New Member
Hello all,

I need your help on this one.
I have a bench drill that is driven by a frequency drive, but it doesn't show the rpm's that the drill is making. Secondly, I need to connect some switches to the pic to stop/start the drill and make it left/right turning.
A code disc with black and white marks (18 per rotation) has been put on the spindle axis and is read by an optical reflection sensor.

The first approach that I made was counting the pulses of a code disc in a time frame. This works excellent at high rotation speed. However, when I want to cut thread, I need very very low rpm's. In that case, pulse counting won't work.
Then I used the pulsin command that is available in proton+
I tried it with the code shown below and it seems to work decently for high and low speeds (10 a 14 rpm -> 4000 rpm).

I've read about autoranging the rpm calculations, for low rpm, use period measuring and for high rpm's use pulse count. Anyone applied this yet ?

Now the real issue is that I need to capture also the buttons if they are pressed. I suppose I need interrupts for measuring the period and scan the buttons in a loop.
Does someone know how to do this. Sample code would be appreciated !
A second question is: how can I make continous averages and not each 3 pulses



Device=16F877A
Declare XTAL 20
Declare LCD_TYPE = ALPHA
Declare LCD_DTPIN PORTD.4
Declare LCD_ENPIN PORTD.1
Declare LCD_RSPIN PORTD.0
Declare LCD_INTERFACE 4
Declare LCD_LINES = 4


Dim period As Word
Dim rpm As Float
Dim c As Byte
Dim rpm2 As Float
Cls
c=0 'Set the attributes to 0
rpm2=0

LOOP:
PulsIn PORTB.0, 0, period 'Read the pulse
c=c+1 'Increase a counter
rpm = 1000000 /(72 * period) 'blocks * edges * 2µs(freq) = 18*2*2
rpm= rpm*60
rpm2=rpm2+rpm 'make a sum for later averaging
If c=3 Then
rpm=rpm2 / 3 'calculate average
rpm2=0 'set to 0 for next 3 calculations
c=0
Cls
Print At 1,1,"f: ", Dec rpm 'Output data to display
Print At 2,1,"p: ",Dec period
DelayMS 200
Else
GoTo LOOP
End If
GoTo LOOP



A lot of questions in a first post isn't it !
Thank you in advance and also sorry for the bad english...


David Thijs
Lembeek
Belgium
 
I can't help with the autoranging part as I don't know the basic involved. However, I would suggest two separate loops that you switch between, if the reading is too low in the pulsein loop then goto the count pulses loop and vice versa.

For the average part, you can use a running average.

NewAverage=OldAverage*2/3 + NewReading/3

Or if you want a more averaged reading,

NewAverage=OldAverage*0.9 + NewReading/10

Mike.
 
Status
Not open for further replies.

Latest threads

Back
Top