NilanEkanayake / LaserScanningMicroscope

An stm32-based LSM
MIT License
5 stars 0 forks source link

scan problem V2 #1

Open pieroantonio opened 1 month ago

pieroantonio commented 1 month ago

I built the v2 microscope and installed everything correctly, the scan function doesn't work 75% of the time, I'm also trying to get it to work, is there any news?

pieroantonio commented 1 month ago

actually the problem appears when I change the zoom

NilanEkanayake commented 1 month ago

I think that's a client-side software bug, where the zoom does not account for resolution and position (under the hood, it sets the number of steps to skip between stop positions, reversed, so a high zoom has no skipped steps, and a low zoom has several, which creates a zoom effect in the full scanned image). This causes problems when the number of skipped steps is too high (zoom too low) and it exceeds the full scan bounds, I think. I have a fix locally, I'll publish it shortly.

NilanEkanayake commented 1 month ago

In the readme, I mentioned that V2 has a stability issue - after repeated use it stops working. I made a V3, but it had a noise issue on one of the PDIC lines, so I'm currently working on V4 (slowly, I have other projects taking my time too).

If V2 works for you long-term or you find a fix, please let me know!

NilanEkanayake commented 1 month ago

Also, please let me know how it works and any other issues you find, I'm always looking for ways to improve on the design.

NilanEkanayake commented 1 month ago

@pieroantonio I pushed a zoom fix to LSMclient.py, see if it solves the issue. I've blown through all my formerly working OPUs (overloaded the lasers and bent the VCM support wires) so I can't verify the scan quality on actual images until a new batch arrives from aliexpress. Have you gotten any good images out of the microscope yet?

pieroantonio commented 1 month ago

I'm a microscopist specializing in SEM/TEM and AFM, and I'm really excited about your project—it has tremendous potential! While I'm not an expert in electronics, I can help with the microscopy and Python aspects. Thanks for the recent client update; everything's working smoothly now. To further enhance the system, have you considered using a Blu-ray pickup? It offers four times the resolution. I'd love to collaborate on designing a new cover and maybe even mechanizing the setup for better sample scanning. Let's make this awesome!

NilanEkanayake commented 1 month ago

I settled on the HOP-150x at the start since it was both dirt cheap and had a pinout available. The idea was that once I had the rest of the system working, I could upgrade the OPU, without adding chaos at the start of the project with an unknown variable. I think if V4 works out, I'll swap out the OPU for a blu-ray one.

Currently, using a blu-ray pickup likely wouldn't result in better image quality, especially for V2's PCB design, since it has a high noise floor, and the PWM frequency would drop to handle the increased step count for higher resolutions, which would add judder.

I have a solution for this in mind, which is to use a two-part system to set the X and Y offsets and then scan within them, first having a rough 256-step digital potentiometer (or PWM/DAC + heavy filtering) to set the scan bounds/area, then a high-frequency PWM signal with a step count matched to the target resolution scanning in the selected area.

Another improvement is APC (automatic power control iirc) for the laser, again to reduce noise in the image.

Also using a larger PCB footprint - to make the PCB fit in the enclosure, I had to cram a lot into a small space, and I believe that's the cause behind the noise and stability issues (degraded signal integrity). To solve this I have an idea for a modified enclosure where the PCB is larger (2x width) and lies flat on one side of it, and the top OPU's cable is routed over the hinge to plug in instead of getting in the way when changing samples.

One idea I've been tinkering with is video-rate scanning - I've gotten poor-quality scans down to as low as 12 milliseconds per image, with decent-quality results at around 25? This requires a lot of software tuning to account for hysteresis (VCM overshooting and having a high settling time when moving at high speeds, not sure if hysteresis is the right term), and it's open-loop since I have no way to measure VCM position in real time. When doing fast scans that way, the resolution can be unlocked by using DMA for the ADC and sampling down to match the target resolution. It can do 500x500 scans in the same time as 200x200.

12ms Above is what that 12ms scan of a CD looks like.

Another small one is to add automatic focus while scanning, which would allow imaging more topographically-varying samples.

The final improvement is the hardest one to implement, but would enable a lot of things. The idea is to replace the two VCMs (sample holder and scanner) with a single custom one that can move in X, Y and Z, similar to the OIS (Optical Image Stabilization) hardware in phone cameras. This would allow normal microscope slides to be scanned, since all the moving parts would be held above the sample and used to image it. In addition, it could theoretically allow the integration of a hall-effect sensor or two, to measure VCM position, which would enable ultra-fast scanning (video-rate) without warping.

My biggest limiter is funding to buy and test parts (always choosing the cheapest shipping options from aliexpress and JLCPCB leads to a lot of waiting), so adding the hardware-changing features would take months best-case.

In terms of things that can be worked on in the meantime without new hardware, the biggest one is actually code refactoring/beautifying/cleaning. The project started out on a breadboard, and it shows in the code with how it's built. It's a pretty unreadable mess for both the client software and the STM32's. I've been meaning to do a massive clean-up to remove hardcoded resolutions and such in the client, better commenting, etc. And a near-total rewrite of the STM32's code to allow for easier modification and expansion. Right now it's just one massive mess.

NilanEkanayake commented 1 month ago

I would love to see some of the images you've been able to scan and the settings to do so if possible, they can tell me a lot about noise levels and artifacts.

As for collaboration, I've been working on this project solo for a while, so I'm not sure what it looks like to an outside perspective. If there are areas you can help with, either in the list above or others, I'd appreciate it. It seems you have experience with CAD design, which is something I fumbled through making the enclosure. Once I have a better idea for the form of V4, I can provide some dimensions if you'd be able to model the enclosure, also a better sample holder - I've been testing various designs but none of them work properly, but that may end up being redundant if I use the 3-axis VCM idea.

NilanEkanayake commented 1 month ago

I'm currently trying to polish up the C code for the STM32, maybe port over some features from V3 and take the X and Y PWM res from 4096 to 8192. Hope I can keep the noise floor similar. Should also set that stuff as configurable options from the GUI too.

How much value would faster scanning have for yours and others' use cases? I can add ADC DMA and fine-tune the hysteresis compensation as well as optimize the image transmission over USB, but from my testing it's already pretty fast and those ideas might be better off saved for a potential video mode.