|
Forum Index : Microcontroller and PC projects : Simple 1 Bit data sampler
| Author | Message | ||||
| phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 3407 |
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: NetherlandsPosts: 6168 |
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 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |