Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:32 27 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 : PicoMite Pulse counter

     Page 1 of 3    
Author Message
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 09:37am 09 Nov 2023
Copy link to clipboard 
Print this post

Hi All

I am contemplating a design to count pulses upto a rate of 20khz.
Pulses are 50% duty cycle.
The count variable would be incremented on each pulse for 1 minute, then
immediately start incrementing another variable.

The first variable is then sent to a Rpi Zero W2 and then erased.
That is all the Pico has to do 24/7.

Has anyone any experience with possible pulse rates using either interrupts or polling ?
I don't know if the command OPTION COUNT pin1... is using Interrupts or polling.

Secondary question is what configuration of Pico would best suit this application.

Regards
Regards
Hervey Bay Qld.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 862
Posted: 10:09am 09 Nov 2023
Copy link to clipboard 
Print this post

I would recommend the LS7366R in X1, non-quad mode. Easy to use SPI.
It has the added benefit of optional noise filtering.


LS7366R.pdf
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9118
Posted: 10:18am 09 Nov 2023
Copy link to clipboard 
Print this post

The COUNT function uses interrupts and will easily do what you want. Count pins are automatically set up with hysteresis to avoid noise.

Easily proven. Connect GP0 to GP8.

SETPIN GP0,pwm
setpin gp8,cin
pwm 0,20000,60
settick 60000,myint
do
loop
sub myint
a%=pin(gp8)
pin(gp8)=0
print a%
end sub

Edited 2023-11-09 20:18 by matherp
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 10:36am 09 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Many thanks for the quick responses.
Will investigate both, but like the idea of not using any additional hardware.

I dont have a Pico yet, just trying to clarify it's suitability.

@matherp
I am proficient in FreeBasic but
just so I understand correctly.
Pin0 creates the pulse fed into Pin8

myint is called after 60 secs

In myint a% becomes 1 (or is it incremented by 1, in FB it would be a% +=pin(gp8))
Is pin(8)=0 cancelling the irq? otherwise why is is setting it to 0,
when it goes to zero automatically at the end of the pulse. ?
What would print a% show.

What I thought was that the code would call the interrupt routine every pulse.
Then the variable incremented and printed.

EDIT: Although I guess printing at 20khz is not a good idea.We're going to miss pulses.
Edited 2023-11-09 20:45 by Dinosaur
Regards
Hervey Bay Qld.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9118
Posted: 10:44am 09 Nov 2023
Copy link to clipboard 
Print this post

The count happens totally transparently in the background under H/W interrupt control
I am setting a PWM pulse to output on GP0 at a rate of 20000Hz to mimic your application and connecting that pin to GP8 which I've set up as a counting pin
I'm then setting a Basic interrupt to fire every 60000mSec (1 minute)
In that interrupt I read the current count and reset it to 0 and then print the value
- easy


 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 10:57am 09 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Ok got, that's a lot better then me incrementing a variable on every pulse.

Many thanks for that, will order the bits and then look into how to get MMBasic into it.
Regards
Hervey Bay Qld.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 862
Posted: 11:01am 09 Nov 2023
Copy link to clipboard 
Print this post

  Dinosaur said   but like the idea of not using any additional hardware.


Oh, I was thinking RPi Zero + LS7366 (but I know nothing about the RPi Zero)

Not the cheapest solution, though.
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 11:11am 09 Nov 2023
Copy link to clipboard 
Print this post

Hi All

@PhenixRising

The Rpi Zero is very busy reading 4 LiPo4 battery cells (on I2C),
controlling charge & Load and updating a 7" LCD.
Then using Wifi to send status information to my Ute GPS (OSD) every 5 minutes.

I just fear that any further hardware may compromise the accuracy of the count.
Whereas a cheap Pico dedicated to counting hopefully will be very accurate.
Regards
Hervey Bay Qld.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 862
Posted: 11:20am 09 Nov 2023
Copy link to clipboard 
Print this post

  Dinosaur said  Hi All

@PhenixRising

The Rpi Zero is very busy reading 4 LiPo4 battery cells (on I2C),
controlling charge & Load and updating a 7" LCD.
Then using Wifi to send status information to my Ute GPS (OSD) every 5 minutes.

I just fear that any further hardware may compromise the accuracy of the count.
Whereas a cheap Pico dedicated to counting hopefully will be very accurate.


I suspect a misunderstanding; The LS7366 maintains the 32bit count and the count is read at leisure via SPI. I have setups where the LS7366 has a separate PSU which means that the MCU can be powered-down/up, re-open the SPI and the count is preserved.
 
scruss
Regular Member

Joined: 20/09/2021
Location: Canada
Posts: 86
Posted: 06:18pm 09 Nov 2023
Copy link to clipboard 
Print this post

I don't have MMBasic code to demonstrate, but via the Pico's PIO I'm able to pulse count to at least 16 MHz. The PIO routine effectively increments a 31-bit counter without CPU involvement. It's reading the output of a slightly grotty oscillator, and does it well.

I don't understand how it works in the slightest, but the PIO routine is short, so someone here might: pio_pulse_counter.py
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 07:29pm 09 Nov 2023
Copy link to clipboard 
Print this post

Hi All

It seems that either way I go I need to communicate with the Rpi Zero to update the total count.

At the moment SPI seems the most suitable as I am already using a Wifi Hotspot from the Zero, using I2C , hdmi and the usb port.

Without studying the LS7366 in detail, it does seem to offer one possible advantage.
When the current in my Battery control goes to discharge instead of charge,
I need to start decrementing the count. I had envisaged a single io bit as the "direction" bit.
If the LS7366 is used for stepper motor control, then that feature should be there.

Will investigate further and see if this chip shows it's ugly head in ready made Rpi add-ons.

Thanks guys.
Regards
Hervey Bay Qld.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6792
Posted: 07:56pm 09 Nov 2023
Copy link to clipboard 
Print this post

If you are playing with SPI, the PicoMite only works as a master device under MMBasic. That's tripped me up previously, just thought I'd mention it. :)
Mick

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

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 08:07pm 09 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Thanks Mick , and the LS7366 is slave mode only.
The plot thickens.

EDIT: and the Rpi is only Master, so talking via spi to a Pico is out.
Edited 2023-11-10 06:31 by Dinosaur
Regards
Hervey Bay Qld.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 862
Posted: 09:25pm 09 Nov 2023
Copy link to clipboard 
Print this post

  Dinosaur said  Hi All

Thanks Mick , and the LS7366 is slave mode only.
The plot thickens.

EDIT: and the Rpi is only Master, so talking via spi to a Pico is out.


Note also that the 7366 features a power fail flag which is useful if it's battery-backed. RPi can make a quick check rather than assume that the count is valid.
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6792
Posted: 09:37pm 09 Nov 2023
Copy link to clipboard 
Print this post

Would I2C be too slow? The PicoMite can handle that as master or slave.
Mick

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

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 10:17pm 09 Nov 2023
Copy link to clipboard 
Print this post

Hi All

As I am already using I2C for the ADC's, it would mean changing the wiring (not a big deal) and then of course, either the 7366 or MMBasic must be able to change address.
It is fast enough though.

On the bigger picture, at night I turn off the Rpi Zero and all electronics that do the battery management with the only load being lights.
If I use the Pico, I can make it completely free standing separately powered still recording the pulses. (The pulses equate to Coulombs depending on frequency)

Another option is to bit bash. Use 6 bits, 0-3 as BCD , 4 as DRDY, 5 as Direction.
The Pico would set those bits in MMBasic regardless of whether the Rpi Zero is powered up or not. If the Zero is off, the Direction will be 0 and thus means discharging.
Simply set the BCD in sequence for 4 digits.Speed does not matter here.
Regards
Hervey Bay Qld.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 862
Posted: 11:15am 10 Nov 2023
Copy link to clipboard 
Print this post

  Dinosaur said  
I am proficient in FreeBasic


Ah, this is what piqued my interest but forgot to ask:

Is this on the RPi Zero?
If so, I'd be interested to learn more about this.
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 07:29pm 10 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Yes it is.
Latest Debian Bookworm as the OS for Rpi
Geany as the Editor
The 32 bit FreeBasic compiler either from :
https://users.freebasic-portal.de/stw/builds/linux-armv6-rpi/
or
The 64 bit FreeBasic compiler from FB forum:
https://www.freebasic.net/forum/viewtopic.php?t=32202
look for Raspberry Pi Binaries.

I have been running 32 bit in GUI mode on Debian Bullseye for about a year,
then when I was happy all was working well changed to 64bit Bookworm Lite (no gui).
This meant compiling the program (text based interface) on a GUI version (10 Gb image)
and then transferring it to the cli version.(4Gb image)
Both versions worked perfectly, BUT i could not get my screen formatting to use the complete 7" lcd in the cli.
So gave up and went back to GUI interface.

Let me know if there is something specific you were interested in.
Regards
Hervey Bay Qld.
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 862
Posted: 10:58am 11 Nov 2023
Copy link to clipboard 
Print this post

Not a Linux guy but was wondering if there was a way to simply power-up-and-go or is there a bunch of setup involved?
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 12:03pm 11 Nov 2023
Copy link to clipboard 
Print this post

  PhenixRising said  Not a Linux guy but was wondering if there was a way to simply power-up-and-go or is there a bunch of setup involved?

Depends what you mean...

If I guess a bit what you mean, it's fairly easy to boot Linux straight into a program and it can appear to the user that it's the only thing running.

In that sort of use you might want a minimal "distro" (*) with or without the GUI stuff , ditto network stuff, etc, and presumably without unused device drivers and user programs.  (Depends mainly on how small & fast you want.)

(*) distribution, meaning (roughly) collection of boot code + kernel + programs

You can tailor your own distro if you wish, though most people can't be bothered so just pick one that's "small enough".

By way of example, I've huge amounts of stuff on a laptop running Linux but there's rather less on a router handling my network, though even that's nothing like a small as you can go.

John
Edited 2023-11-11 22:12 by JohnS
 
     Page 1 of 3    
Print this page
© JAQ Software 2024