-
Notifications
You must be signed in to change notification settings - Fork 1
Description
I've had issues a clean image capture from the OV5640 with the RP2350. With the current default configuration, the images capture by the RP2350 look like this:
So, I wrote the following debug code. In short, it makes the camera output a single frame of the built-in test pattern, it manually controls the DMA and PIO state machine to ensure they're configured correctly before each frame, and ensures nothing else is happening while the image is being captured.
import time
# Force camera into a test mode
camera.writeRegister(0x503D, 1 << 7) # Test pattern
camera.writeRegister(0x3008, 0x42) # Software power down
camera.release() # Disable VSYNC handler
camera.sm.active(True) # Keep PIO state machine active
camera.dma.config(count = 320*240*2//4) # Ensure DMA count is correct
# Makeshift VSYNC handler, run between frames
camera.dma.active(False) # Stop DMA so it can be reconfigured
camera.sm.restart() # Clear the PIO state machine ISR
camera.buffer[:] = 0 # Wipe the camera buffer
camera.dma.write = camera.buffer # Reset the DMA write address
camera.dma.active(True) # Re-activate DMA to be ready for next frame
# Capture 1 frame and display it
camera.writeRegister(0x3008, 0x02) # Enable camera
time.sleep(0.026) # Wait for 1 frame (may need to adjust)
camera.writeRegister(0x3008, 0x42) # Disable camera
print("dma.count:", camera.dma.count) # Print number of bytes remaining
display._write(None, camera.buffer) # Display captured image
It prints dma.count: 24254 , and the following image is captured:
If I drop the XCLK frequency from 25MHz to 7.5MHz (camera.xclk.freq(7_500_000)) and sleep for 87ms (long enough for 1 frame at these settings), it prints dma.count: 3590 and the following image is captured:
The first ~5 rows look fine, but there's clearly multiple desyncs happening during the frame. If I drop the XCLK frequency to 5MHz (camera.xclk.freq(5_000_000)) and sleep for 131ms (long enough for 1 frame at these settings), it prints dma.count: 0 and the test image is captured correctly:
So, the problem appears to be that the camera is just outputting data too fast for the RP2350 to handle. But this is odd to me, because the HM01B0 outputs 79056 bytes in just under 30ms, or about 2.7MBps (with default settings), and the RP2350 handles it just fine. Whereas running the OV5640 at 7.5MHz XCLK, it outputs 153600 bytes in just over 80ms, or about 1.9MBps, and it misses bytes. Something doesn't add up here, why does the slower data transfer miss bytes?



