Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:41 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : catching slow pulses

Author Message
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 514
Posted: 11:58am 08 Dec 2019
Copy link to clipboard 
Print this post

When I am using setpin FIN, PIN, CIN  pin configurations
PAUSE looks to have priority and halts the functioning of these.
I am now using this sub in place of PAUSE.

Sub wait t
Timer = 0
Do
Loop Until Timer > t
End Sub

I am reading very slow pulses down to 5 pulses per minute.

FIN does ok down to 10 PPM but is off a bit going lower

PIN is working but I have to do code like this

Do 'run loop
SetPin pulse1,pin  'have to do this to get a 0 if in coming pulse is lost
SetPin pulse2,pin

wait 30000  ' a 30 sec wait just to let some time go by

p1=Pin(pulse1)
p2=Pin(pulse2)

If p1>0 Then p1=60000/Pin(pulse1)  'get ppm of pulse1
If p2>0 Then p2=60000/Pin(pulse2)  'get ppm of pulse2

Print "pulse1=";Str$(p1,1,2);" pulse2=";Str$(p2,1,2);

loop

My first though was that FIN, PIN and CIN worked in the background.

any thoughts on testing for slow signals that need to give me 0 if lost.

 Quazee137
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8516
Posted: 12:21pm 08 Dec 2019
Copy link to clipboard 
Print this post

Change the gate time on FIN and it should work.

SETPIN n,FIN, option 'option is the gate time in mSec
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 01:59pm 08 Dec 2019
Copy link to clipboard 
Print this post

Yeah, I always make my time delays passive and only use Pause for initialization stuff.

Just about to work with a new MCU and the language has no ms timer at all (!!!).
I asked the manufacturer about this and he says to use a FOR-NEXT loop...ugh..no-way.
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 705
Posted: 03:47pm 08 Dec 2019
Copy link to clipboard 
Print this post

> he says to use a FOR-NEXT loop

Isn't that what a ' pause ' translates to ?
( though the language is less eloquent )
my site
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 07:46pm 08 Dec 2019
Copy link to clipboard 
Print this post

Absolutely not.

1ms = 0.001 seconds. A FOR-NEXT loop has no time base. It is processor and code dependent.
 
Quazee137

Guru

Joined: 07/08/2016
Location: United States
Posts: 514
Posted: 10:57pm 08 Dec 2019
Copy link to clipboard 
Print this post

Using FIN I have SetPin pulse1,fin,30000


                                     _                        _
the wave form is something like  ___| |______________________| |_________ . . .


the time of high is the same width only the time of low changes.  

The end game is to read pulses from six inputs and have three 4-20ma outputs.

With SetPin n,PIN I can not get a 0 from reading the pin in a loop
unless I use SetPin is at the first part of the loop.

I may try SetPin INTH  and INTL and grab the timer value in the subs then do the
math in the main loop. Then if there is a missing pulse I will have to some how
deal with it.

I remember with ASM doing waits with nop loops with the Z80 and 874X chips.
I think there was more comments than code with the 874X chips.  

MMBasic makes for easier code development and readability.    
Edited 2019-12-09 09:09 by Quazee137
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1028
Posted: 02:26am 09 Dec 2019
Copy link to clipboard 
Print this post

Hi Q.

I use PIN to measure the period of low speed steam engines for Tachometers.
Goes down to about 15RPM which with a single pickup, means a pulse every 4 seconds.

Rightly or wrongly, I use two pins connected together; one set up for PIN & the other for the interrupt, INTL. (I couldn't get the one pin to do both :-) )

The first reading will always be a high (or incorrect) value so is ignored. This reading will not be updated until the next pulse arrives & repeated PIN calls will give the same result until it is updated.

I average the first few input pulses while the engine is starting up. Probably not really needed

I also have a SETTICK "time out" if there are no input pulses after about 5 secs else the display will just hang. (Engine stopped)

The rather crude program is shown below for an F4 board & work OK but it does seem to drop pulses every now & again. Not sure why. May be the sensor.

Obviously, you have longer time periods to deal with but the program may (or may not) be helpful if some of the parameters are adjusted accordingly.

Brian



'Armmite/ F4 TACHO program
 'Program developed to display the rotational speed of steam engines from about
 '30 RPM to 999RPM using a magnet on the flywheel & Hall Effect sensor connected
 'to an input measuring the period between the pulses.
 'The display is updated every input & readings are averaged over 3 readings while running.
 'The display RPM is reset to "000" after about 6 secs of inactivity. When restarted, the first
 'reading (which will be long) is ignored & the subsequent 5 readings are only averaged over the
 'number of mesurements recieved.

Ver$ = "Armmite Tacho_11.Bas"
 ? Ver$
 option autorun on             'Run program when started
 const DBlue = rgb(0,0,128)    'define LCD colour.
 const Font_No_1 = 5 '12    
 Const Font_No_2 = 5 '13  
 colour rgb(green), DBlue
 backlight 100                 'set backlight brightness  
 cls                           'Clear LCD panel
 dim as integer Int_avg(6), Cntr = 0 'Period value & average
 dim UD_Flag, Time_out_Flag, Pulse_in_Flag = 0   'Condition flags
 box 0, 0, MM.HRes - 1, MM.VRes - 1, 1, dblue, DBlue 'Outside box
 setpin PE4, pin                   'set pin PE3 (2) for period input
 setpin PE6, din                   'set for digital input (H-L-H from Hall Effect PU
 setpin PE6, intl, Pulse_in        'set pin for Interrupt low to high L-H
 setpin PA6, dout                  'LED D2
 setpin PA7, dout                  'LED D3
 pin(PA6) = 1                      'Turn LED off
 pin(PA7) = 1                      'Turn LED off
 RPM$ = "000"                      'Initial value
 settick 6000, No_Act, 2           '6 second timer for I/P pulses.

 text mm.hres/2, 238, "RPM", "CB", Font_No_1, 1     'print "RPM" to LCD panel

 do    'main loop
   if UD_Flag = 1 then                'wait for pulse i/p flag to set.
     Cntr = Cntr + 1                   'Ignore first reading. Will be large
     if Cntr = 1 then Int_avg(0) = 50000
     if Cntr > 1 then                          'Check not first pulse
       if Cntr > 4 then Cntr = 4               'Srt counter max value
       for x = Cntr - 1 to 1 step - 1 'Loop length depends on ctr value  5,4,3,2,1
         Int_Avg(x) = Int_Avg(x-1)         'Move values along array one posititon
         print Int_avg(x),                     'print to PC screen for monitoring
         Int_Avg(4) = Int_Avg(4) + Int_Avg(x)  'Total all values
       next x                                  'next value
       Print Int_Avg(4)                        'for PC screen
       Int_avg(0) = Int_Avg(4) / (Cntr - 1)    'average values
       Int_Avg(4) = 0                          'Reset Value
     endif
     if Int_avg(0) < 76 then Int_avg(0) = 76   ' Set max RPM    
     RPM$ = str$(60000/Int_avg(0), 3, 0, "0")  'set RPM string. 3 digits, leading 0. 1 magnet P.U.
     settick 6000, No_Act, 2               'Times out if no activity for 6 secs
     Time_Out_Flag = 0                     'Clear or reset flag
     pulse PA6, 10 'pulse LED
     UD_Flag = 0  
     print "Int " + str$(Int_avg(0)) + "  RPM " + RPM$ + "  " + Str$(cntr)  'print to monitor screen
   elseif Time_Out_Flag = 1 then                'No I/P pulses for awhile
     RPM$ = "000"
     for x = 0 to 4                          'clear average
       Int_Avg(x) = 0
     next x
     pulse PA7, 10                            'pulse LED    
     Cntr = 0                                 'reset counter
   endif  
   UD_Flag = 0                                'clear (reset flag)
   text mm.hres/2, 1, RPM$, "CT", Font_No_2, 1     'display reading
 loop
 
sub Pulse_in                         'Interrupt. Runs when trigger pulse in on PE6
 Int_avg(0) = pin(PE4)              'Get current period val in Msec
 UD_Flag = 1                        'set flag for main loop
end sub  

sub No_Act    'time out delay
 Time_Out_Flag = 1                     'time out flag
 Cntr = 0                              'reset counter
end sub

ChopperP
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5867
Posted: 05:15am 09 Dec 2019
Copy link to clipboard 
Print this post

For pulses that slow, I would use an interrupt for each input.
Each pulse simply sets a global variable with the TIMER value and does the maths to get the time difference.

To detect no pulses, a settick that checks to see how the inputs are progressing.
Read all the globals looking for one that is stale.

Jim
VK7JH
MMedit   MMBasic Help
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024