Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 22:33 10 Oct 2026 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 : Simple 1 Bit data sampler

Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3407
Posted: 06:16am 09 Oct 2026
Copy link to clipboard 
Print this post

For high speed and precision PIO is the way to go, but at lower speeds this simple program is adequate.
Uses memory efficiently so long sampling runs are possible. A 10,000 element array holds 640k samples.

On a RP2350B @ 378MHz the minimum sampling interval is about 7.2µS.

Input is GP1, connected to a 18kHz PWM test signal on GP2. In the loop Pin(2) is used instead of Pin(GP1) as it is a little faster.
Dim integer n,m,d(999),e
SetPin gp1,din
SetPin gp2,pwm
PWM 1,18000,50
Dim float t

t=Timer
For n=0 To 999
 For m=0 To 63
  Inc e,e
  Inc e,Pin(2)
 Next
 d(n)=e
Next
t=Timer-t

Print t/64; " uS per sample"

Print BIN$(d(0),64)
Print BIN$(d(1),64)
Print BIN$(d(998),64)
Print BIN$(d(999),64)

End

Output
> RUN
7.19378125 uS per sample
1100011110001111000011110000111100001111000111100001111000011110
0011110000111000011110000111100001111000011110000111000011110000
0111100001111000011110001111000011110000111100001111000011100001
1110000111100001110000111100001111000011110001111000011110000111
>


Reducing the loop to one line shaves a little off.
t=Timer:For n=0 To 999:For m=0 To 63:Inc e,e:Inc e,Pin(2):Next :d(n)=e:Next :t=Timer-t

7.0845 uS per sample
Edited 2026-10-09 16:27 by phil99
 
Volhout

Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6168
Posted: 06:41am 09 Oct 2026
Copy link to clipboard 
Print this post

Hi Phill,

You definitely looked through the manual Peter made on how to make things faster.
I like your approach, but there is a catch. These loops in MMBasic do get interrupted by system tasks. Thus sample 99000 is not necessarily 99000 * 7.19378125us after start of sampling.

But it is a quick to type in piece of code, in case you need to search for a pattern or so.

Regards,

Volhout
PicomiteVGA PETSCII ROBOTS
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026