Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:53 25 Nov 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 : More than 4 count Inputs with Webmite ?

Author Message
Gerad
Regular Member

Joined: 10/01/2024
Location: Germany
Posts: 42
Posted: 10:24pm 28 Mar 2024
Copy link to clipboard 
Print this post

Hello Everybody
Is it possible to define more than 4 count inputs with Webmite ?

Gerad
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6783
Posted: 10:31pm 28 Mar 2024
Copy link to clipboard 
Print this post

Not actual high speed counter inputs, no. If you only need low speed then you can use any pins and use them to trigger interrupts if you like. They are a lot slower though.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Gerad
Regular Member

Joined: 10/01/2024
Location: Germany
Posts: 42
Posted: 10:45am 29 Mar 2024
Copy link to clipboard 
Print this post

Hi Mick
I thought so. Then I probably have to use 2 picomite as count slave controllers for another 8 count inputs.

Thank you very much for your information

Gerad
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 12:43pm 29 Mar 2024
Copy link to clipboard 
Print this post

Hi Gerad.

You can use PIO. In the normal pico you have 8 PIO state machines, each can count 1 input. In the VGA pico, you can use only 4 PIO state machines, since the other 4 are used for creating VGA.

And, in case they are slow changing inputs, you can count in MMbasic.

What is your application, What are you counting ?

Regards,

Volhout
Edited 2024-03-29 22:43 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Gerad
Regular Member

Joined: 10/01/2024
Location: Germany
Posts: 42
Posted: 03:04pm 29 Mar 2024
Copy link to clipboard 
Print this post

Hi Volhout

Unfortunately, I have absolutely no idea how the PIO state machines work

I count pulses from 12 water flow meters. between 90 and 350 impulses/sec each.


Regards,

Gerad
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 03:32pm 29 Mar 2024
Copy link to clipboard 
Print this post

  Quote  I count pulses from 12 water flow meters. between 90 and 350 impulses/sec each.

Assuming these are clean "non-bouncing" 50% duty cycle signals then you could easily do this in a loop with a port function reading the inputs and comparing with the previous reading. You could do this in say a 1mS timer loop which should catch everything.

Something like:

settick 1,readpins
do
'whatever
loop
'
sub readpins
 a%=port(pin spec)
 new%= (a% XOR last%) and a% 'pins that have changed to ON
 last%=a%
 for i%=0 to nummeters%-1
   if new% and 1 then inc counter%(i%)
   new%=new%>>1
 next i%
end sub
 
Gerad
Regular Member

Joined: 10/01/2024
Location: Germany
Posts: 42
Posted: 08:57am 30 Mar 2024
Copy link to clipboard 
Print this post

Thanks matherp
for the example. I'm trying to understand it.
It makes me uncomfortable, but I have a small question:
what does “%” mean, e.g. “new%)?

Gerad
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 09:19am 30 Mar 2024
Copy link to clipboard 
Print this post

% is the syntax that specifies the variable is an integer - see the manual for more details
%=integer, !=float, $=string
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6783
Posted: 09:21am 30 Mar 2024
Copy link to clipboard 
Print this post

It makes the variable "new" an integer.

Another way is to use
DIM INTERGER new

then "new" will always be an integer variable, even without the % symbol.

Some people prefer to always use the symbols, others prefer to use DIM to set the type.

This stuff is in the manual, it's just a case of finding it. :) Look under "Variables and expressions". Probably around page 40-ish depending on your manual.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Gerad
Regular Member

Joined: 10/01/2024
Location: Germany
Posts: 42
Posted: 10:15am 30 Mar 2024
Copy link to clipboard 
Print this post

Hello matherp , Hello Mick

many thanks for your help.
I wish you a nice Easter.

Regards
Gerad
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 03:49pm 30 Mar 2024
Copy link to clipboard 
Print this post

Hi Gerad,

Peter's proposal works, but requires OPTION CPUSPEED 252000 or OPTION CPUSPEED 378000 to manage 12 count inputs in MMBasic. The standard picomite speed of 133000 is not sufficient for 12 inputs.

Below is the program to test this:

 'count events on 12 GPIO pins
 
 nummeters%=12
 dim counter%(nummeters%-1)
 openpins
 
 'measurement speed
 settick 1,readpins
 
 'main loop
 do
   'just simulating all the math for 100ms
   pause 100
   'print how much time the interrupt routine takes (out of 1ms tick)
   'print t
 loop
 
 'read all the pins
sub readpins
 't=timer
 a%=port(1,2,4,4,9,4,14,2)   'GP0...GP11
 new%= (a% XOR last%) and a% 'pins that have changed to ON
 last%=a%
 for i%=0 to nummeters%-1
   if new% and 1 then inc counter%(i%)
   new%=new%>>1
 next i%
 't=timer-t
end sub

 
sub openpins
 setpin 1,din
 setpin 2,din
 setpin 4,din
 setpin 5,din
 setpin 6,din
 setpin 7,din
 setpin 9,din
 setpin 10,din
 setpin 11,din
 setpin 12,din
 setpin 14,din
 setpin 15,din
end sub
 


When you "un-comment" lines 15,20,28  it gives you the time consumed in the interrupt routine. At 252MHz (CPUSPEED 252000) that is 62% (0.62ms of 1ms), and that will be barely enough to run a responsive main program.

Most time is consumed in this section of the interrupt routine 0.5ms of 0.62ms.

 for i%=0 to nummeters%-1
   if new% and 1 then inc counter%(i%)
   new%=new%>>1
 next i%


Maybe there is a faster way of doing this, that would be good. But I have no alternative yet. Minor speed up can be achieved by

NEXT

in stead of
NEXT i%


And defining nummeters% as 11 (in stead of 12) to ommit the math in the interrupt routine.
 for i%=0 to nummeters%

in stead of
 for i%=0 to nummeters%-1


That would bring you to 0.56ms (from 0.62ms) every 1ms interrupt


Volhout


EDIT: this brute force interrupt routine is faster (0.44ms)....

sub readpins
 t=timer
 a%=port(1,2,4,4,9,4,14,2)
 new%= (a% XOR last%) and a%
 last%=a%
 inc counter%(0),(new% and 1=1)
 inc counter%(1),(new% and 2=2)
 inc counter%(2),(new% and 4=4)
 inc counter%(3),(new% and 8=8)
 inc counter%(4),(new% and 16=16)
 inc counter%(5),(new% and 32=32)
 inc counter%(6),(new% and 64=64)
 inc counter%(7),(new% and 128=128)
 inc counter%(8),(new% and 256=256)
 inc counter%(9),(new% and 512=512)
 inc counter%(10),(new% and 1024=1024)
 inc counter%(11),(new% and 2048=2048)
 t=timer-t
end sub

Edited 2024-03-31 02:22 by Volhout
PicomiteVGA PETSCII ROBOTS
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 11:01pm 26 Apr 2024
Copy link to clipboard 
Print this post

To shave off a few more uS use single character variable names and try to squeeze loops into a single line with minimum white-space. Every character takes time to read.
new% caused an error as New is a keyword, changed to newm%.

for i%=0 to nummeters%-1
  if new% and 1 then inc counter%(i%)
  new%=new%>>1
next i%

Becomes
Dim Integer i, m, n, c(nummeters%-1)
m = nummeters%-1 : n = newm%
'...
For i=0To m:If n And 1 Then:Inc c(i):EndIf:n=n>>1:Next


Edit.
If the number of meters is always the same replace the variables nummeters% and 'm' with the number.
Looking up the value of variables / constants takes time.
For i=0To 11:If n And 1 Then:Inc c(i):EndIf:n=n>>1:Next


timer=0:For i=0To 11:If n And 1 Then:Inc c(i):EndIf:n=n>>1:Next:?timer
0.335
> ? mm.info(cpuspeed)
378000000
>


PS. You can remove the space before 'To' but not the one after it.
Edited 2024-04-27 10:53 by phil99
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 07:44am 27 Apr 2024
Copy link to clipboard 
Print this post

INC N,N

is a fair bit faster than

N=N>>1
Edited 2024-04-27 17:46 by matherp
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 07:48am 27 Apr 2024
Copy link to clipboard 
Print this post

Hi Phil,

Avoiding the loop is faster. See my post before.
I get 0.44 ms at 252Mhz. That would be 0.29 at 378Mhz.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Gerad
Regular Member

Joined: 10/01/2024
Location: Germany
Posts: 42
Posted: 07:29pm 01 May 2024
Copy link to clipboard 
Print this post

Thank you very much for all the good suggestions and examples.  

Regards
Gerad
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3800
Posted: 07:44pm 01 May 2024
Copy link to clipboard 
Print this post

  matherp said  INC N,N

is a fair bit faster than

N=N>>1

The point is well made, though I think that would be instead of N=N<<1

John
 
Print this page


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

© JAQ Software 2024