Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:03 23 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 : COUNT and max frequency for PicoMite?

Author Message
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 856
Posted: 03:24pm 18 Nov 2024
Copy link to clipboard 
Print this post

Do we have a definitive number for this?
 
ElectroPI
Newbie

Joined: 27/04/2012
Location: Australia
Posts: 31
Posted: 12:14am 22 Nov 2024
Copy link to clipboard 
Print this post

Hi,
I'm also interested in what the max count is when using an I/O line as a COUNT input. Since I read the value into an integer like
i% = PIN(GP6)
and integers are 64-bit is it correct to assume the max count is (2^64)-1?
And is this the same for all versions of MMBASIC ie for PicoMite, PicoMiteVGA, Micromite Plus and the Micromite?
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2134
Posted: 01:01am 22 Nov 2024
Copy link to clipboard 
Print this post

Since the manual doesn't set a maximum assuming 64 bits seems safe.

To test try pre-setting i% to (2^64 - 16) then start counting and see what happens.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6094
Posted: 01:51am 22 Nov 2024
Copy link to clipboard 
Print this post

Try signed 32 bit so 2147483647

 '
 OPTION DEFAULT INTEGER
 
 DIM i,k
 SETPIN GP6, CIN
 SETPIN GP7, DOUT
 PIN(GP6) = 2^31 - 10
 PRINT PIN(GP6)
 DO
   i = PIN(GP6)
   PULSE GP7, 1
   PRINT i
   INC k
 LOOP UNTIL k >20


VK7JH
MMedit   MMBasic Help
 
ElectroPI
Newbie

Joined: 27/04/2012
Location: Australia
Posts: 31
Posted: 06:24am 22 Nov 2024
Copy link to clipboard 
Print this post

Hi phil99
presetting i% to a value wouldn't work because as soon as you execute
i% = PIN(gp6)
it'll overwrite i% with whatever is in the counter.

Hi TassyJim
I didn't realise that running
PIN(gp6) = 2^31 - 10
allows you to preset the counter to some value. There's no mention of this in any of the manuals.

So using your idea I ran 2 programs ....



I'm printing 18 hex digits and it's pretty obvious that the counter is 16 hex digits or 64-bit ie the same as a signed 64-bit integer.

Hi PhenixRising
Re max frequency for the PicoMite....
P33 of the PicoMite manual (5.08.00) mentions that counting pulses is accurate up to 200KHz. So I wonder if this also applies to measuring frequency?
P39 of the Micromite manual (5.05.05) is similar. It mentions the max count rate is 800KHz depending on the load on the processor but is normally around 300KHz. When you think about it measuring frequency is just counting pulses but over a fixed time period of 1 sec.

cheers
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2134
Posted: 06:53am 22 Nov 2024
Copy link to clipboard 
Print this post

Interesting, so if you need more than 31 bits:-
> setpin gp6,cin
> pin(gp6)= -(2^31)
> setpin gp2,pwm
> pwm 1,100000,50
> ? pin(gp6)
-2145157319
> ? pin(gp6)
-2144146087
> ? pin(gp6)
-2139827601
> do:? pin(gp6):pause 100000:loop
-2133966670
-2123966649
-2113966632
-2103966616
-2093966601
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6094
Posted: 07:08am 22 Nov 2024
Copy link to clipboard 
Print this post

  Quote  it's pretty obvious that the counter is 16 hex digits or 64-bit ie the same as a signed 64-bit integer.


Your first example shows a 32 bit signed number going negative.
The counters are 32 bit internally but get changed to 64 bit when accessed.
The sign bit gets extended.
VK7JH
MMedit   MMBasic Help
 
ElectroPI
Newbie

Joined: 27/04/2012
Location: Australia
Posts: 31
Posted: 07:38am 22 Nov 2024
Copy link to clipboard 
Print this post

OK I see what you mean. If the counter was 64-bit then my first example would have gone

000000007FFFFFFD
000000007FFFFFFE
000000007FFFFFFF
0000000080000000
0000000080000001
0000000080000002
etc

But because the sign bit was extended after 7FFFFFFF it means it's a 32-bit counter but read as a signed 64-bit integer.
Thanks for the clarification, it makes a lot of sense now.

regards
 
ElectroPI
Newbie

Joined: 27/04/2012
Location: Australia
Posts: 31
Posted: 08:02am 22 Nov 2024
Copy link to clipboard 
Print this post

Just to complete the topic and out of curiosity, do you know if the counters are hardware counters or just implemented in firmware using interrupts?
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6769
Posted: 08:08am 22 Nov 2024
Copy link to clipboard 
Print this post

Pins defined as counter pins on the PicoMite have hardware interrupts to reduce the problem of lost edges. The Micromite is probably using one of the PIC chip counters driven from a pin. The two are probably not really comparable. Whether MMBasic on the Pico is reading a hardware register to get the value or is responding to the interrupt to update the counter itself I don't know.

The Pico can count *very* fast using the PIO. If it's count source is taken from the clock and gated by a CPU (or a different state machine) you cam measure some impressive frequencies with it.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
ElectroPI
Newbie

Joined: 27/04/2012
Location: Australia
Posts: 31
Posted: 08:28am 22 Nov 2024
Copy link to clipboard 
Print this post

So as PhenixRising asked in the original post, does anyone know what the max freq is when measuring freq using the PICO?

Footnote added 2024-11-22 18:30 by ElectroPI
Running MMBASIC of course.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 856
Posted: 08:31am 22 Nov 2024
Copy link to clipboard 
Print this post

Referring to the documentation:

MMite (@48MHz?): Typically 300KHz but can be up 800KHz

PicoMite (@126MHz): 200KHz

Just dawned on me that I can use a PWM to test max FIN.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6769
Posted: 08:52am 22 Nov 2024
Copy link to clipboard 
Print this post

Don't attempt to test count speed while writing to the screen. PRINT will slow everything down. TEXT will slow everything down even more. :)

Set a time window and count during that time then just display the result - frequency measurement, in fact.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9100
Posted: 08:57am 22 Nov 2024
Copy link to clipboard 
Print this post

In the latest release you can use pin GP1 for very fast frequency measurement

SETPIN GP1,FFIN ' set GP1 for fast frequency input
'Connect gp1 to gp3
SETPIN GP3,PWM
PWM 1,val(mm.info(cpuspeed))/4,,50 'this is the fastest PWM can run
? pin(gp1)
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 856
Posted: 09:16am 22 Nov 2024
Copy link to clipboard 
Print this post

Oh perfect  
But I'm 5 hours away from my Picomite    
 
ElectroPI
Newbie

Joined: 27/04/2012
Location: Australia
Posts: 31
Posted: 05:48am 23 Nov 2024
Copy link to clipboard 
Print this post

Thanks Peter. I do recall you posting about the high speed frequency measurement a while back.

Back to the counter input - it seems silly to have counts go negative once it passes 7FFFFFFFH (2147483647). A work-around is to zero the upper 32 bits so the integer never goes negative. The following 2 examples seem to work:



Peter, for a future release could this be fixed so the count always stays positive? It would make more sense. Not sure what should happen if the count goes past max but with the programs above it continues counting from zero again.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6094
Posted: 06:23am 23 Nov 2024
Copy link to clipboard 
Print this post

Getting past the negative range will only double the count.
If you aren't resetting on a regular basis, you need to handle the problem yourself.

Back when we only had 32 bit floating point, the internal counter was 32bit integers so I kept my own rollover:
do while scale > 1000000 ' keep the value within the floating point range
   scale = scale - 1000000
   mega = mega + 1
   pin(count) = scale
 loop

That gave me sufficient range to last a few years ~ 3000 megalitres

Jim
VK7JH
MMedit   MMBasic Help
 
Print this page


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

© JAQ Software 2024