PDA

View Full Version : Counter per minute



debutpic
- 31st December 2005, 18:57
Hello all and good years

I will want a counter per minute with:
-count pulses in RB0
-setting tmr0 (prescaler 256) + loop but it can't works

what is wrong please


'************************************************* ***************
'* Name : Compte tour.BAS
'* Author : [set under view...options]
'* Notice : Copyright (c) 2005 [set under view...options]
'* : All Rights Reserved
'* Date : 31/12/2005
'* Version : 1.0
'* Notes :
'* :
'************************************************* ***************
Adcon1=7
Define osc 20
TRISB=%00000001 ' setting port B
TRISA=%00000000 ' setting port A

OPTION_REG=%01001111 ' inerruption RB0/INT
' Incrrase tmr0
' prescaller 256
INTCON = %10010000 ' setting INTCON


'-------------------------------------------------------------------------------

'setting LCD

DEFINE LCD_DREG PORTB ' LCD o/p on port B
DEFINE LCD_DBIT 4 ' LCD on lower 4 bits of port B
DEFINE LCD_RSREG PORTB ' LCD reset on port B
DEFINE LCD_RSBIT 3 ' LCD reset portB.3
DEFINE LCD_EREG PORTB ' LCD enable on port B
DEFINE LCD_EBIT 2 ' LCD output on PortB.2
DEFINE LCD_BITS 4 ' LCD o/p is 4 bit data
DEFINE LCD_LINES 2 ' Number of lines on LCD = 2

'-------------------------------------------------------------------------------

Compte_pulse var word
Compte_timer0 var word
Tours_minute var word


'-------------------------------------------------------------------------------


On interrupt goto Isr

'-------------------------------------------------------------------------------
Main:

If intcon.2=1 then
Compte_timer0=Compte_timer0+1
intcon.2=0
endif
if Compte_timer0=58500 then
Tours_minute=Compte_pulse*20
Lcdout$fe,1
Lcdout,#Tours_minute," Tours/mn"

'-------------------------------------------------------------------------------
Compte_timer0=0
Compte_pulse=0
endif
Goto Main
disable

'-------------------------------------------------------------------------------

Isr:

Compte_pulse=Compte_pulse+1
INTCON.1 = 0 'flag d'interruption à 0
resume
enable

crematory
- 2nd January 2006, 05:20
Hi

Its here:

Lcdout,#Tours_minute," Tours/mn"


It should be:

Lcdout #Tours_minute," Tours/mn"

debutpic
- 2nd January 2006, 10:15
thank's for your remark Crematory my question is more general
it's a good method of programming because the best resolution
is of 20 turns per mn,5 would be ideal

Acetronics2
- 2nd January 2006, 11:16
Hi DebutPic

The first question to ask is that one : you want to show 5 turns/min resolution , ok, BUT at which speed ???

Where do you want to measure these RPMs ???

There are other methods for RPM Measuring ... but depends on the use you want to do ... and mostly the pulse freq.

Ceci dit, un joyeux pneu à toi aussi !!! ( a happy good year ... )

Alain

debutpic
- 2nd January 2006, 13:10
Hi Acetronics

It's a RPM counter for a mill machine,range 0-4000 turns per mn
i want use a sensor "hall-effect" fixed on the spindle

and happy new years
mon anglais est malade mais je le soigne........

Acetronics2
- 2nd January 2006, 14:11
Hi, Debut Pic

Have a look here : http://www.parallax.com/html_pages/robotics/machining/RPM_display.asp ... funny, isn't it ???

Code directly usable ...

Alain

Acetronics2
- 5th April 2008, 13:29
http://www.parallax.com/ProductInfo/Robotics/MachiningTips/BASICMachiningRPMDisplayforyourMill/tabid/420/Default.aspx

Alain