joan2937 / pigpio

pigpio is a C library for the Raspberry which allows control of the General Purpose Input Outputs (GPIO).
The Unlicense
1.43k stars 403 forks source link

Can create SPI wave in nano seconds resolution? #582

Open andyzhuang2015 opened 10 months ago

andyzhuang2015 commented 10 months ago

I use ADS8688A with the 500kSPS. It need 64 clock time per sample. However, the pigpio library use 1us as the min clock time. The max speed I can achieved is (1000 / 64) kSPS, which is much smaller than 500.

So how can modify the SPI clock to 10ns or 100ns ?

guymcswain commented 10 months ago

The hardware SPI supports a baud rate maximum of 32M.

andyzhuang2015 commented 10 months ago

The hardware SPI supports a baud rate maximum of 32M.

Yes. But when use rawWaveAddSPI , the parameter rawSPI_t's clk_us min value is 1us. This limit the clock frequency to 1M. Any workaround to improve the Wave frequency? ( I need to monitor the signal in real-time. So I use Wave to exchange data by SPI. I think spiXfer may have dubious time slot between two invoking. ) @guymcswain This blocking me too much time. Will be very appreciate for your help!

guymcswain commented 10 months ago

The construction of output waveforms is limited to 1 microsecond timing. Ie, the fastest square waveform you can generate is 500 KHz.

andyzhuang2015 commented 10 months ago

The construction of output waveforms is limited to 1 microsecond timing. Ie, the fastest square waveform you can generate is 500 KHz.

Is it possible to improve the waveforms' CLK timing to nano seconds?

guymcswain commented 10 months ago

No. Waveforms are controlled by DMA. To try to make it run sub microseconds would be futile as that would create excessive bus traffic interfering with normal activity.

Why do you not use the hardware SPI peripheral which is intended for such purposes?

andyzhuang2015 commented 10 months ago

@guymcswain I use RPI to do this because it need no other devices and I saw that the clocks can achieve 100MHz or higher for RPI peripheral. So I want to test the max ablity of the speed. @guymcswain You said hardware SPI peripheral, did you mean using FPGA DAQ card, like NI Corporation's?

guymcswain commented 10 months ago

RPi is made up of many peripherals. The 100MHz rate you mention is only achievable in certain Gpio pins via the Clock peripheral. When I mentioned the SPI peripheral I am referring to the APIs: spiOpen, spiTransfer, spiClose.

andyzhuang2015 commented 10 months ago

@guymcswain Thanks for your patience. I need to monitor the signal continuously without time gap between two data acquest. I tried spiOpen, spiXfer (I didn't found spiTransfer API), spiClose. But there is a dubious time gap between two spiXfer invoking. I think the System schedule to do other things in the time gap. Is there any workaround to avoid that?

guymcswain commented 10 months ago

Yes, spiXfer. When you specify a buffer of data it will be transferred without any gaps. Check you ADC device. If it can handle data that fast, it most likely can buffer the data.

andyzhuang2015 commented 10 months ago

@guymcswain If I want to streaming the input data without any gaps, can I use spiXfer to achieve this?