Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

signal interference when using gameboy camera and sd card

Status
Not open for further replies.

mdanh2002

Member
Hi all,

I am interfacing a PIC24FJ64GA002 with a GameBoy camera using info from this **broken link removed** in order to display the image on a graphics LCD and to save the image as bitmap to an SD card when a button is pressed using the MDD library by Microchip.

Things work almost well except that when I save the bitmap to the SD card, the gameboy camera sensor experiences interference causing "dead" pixels which will create periodic horizontal lines as part of the bitmap. For example, see the first 3 attached photos.

(The original photos were saved as bitmap and is upside-down as the bitmap format requires pixels to be saved from bottom to top, left to right, but has been flipped vertically and saved as JPEG before being uploaded)

The lines are at the same position regardless of the scene. It changes according to the time taken to write to the SD card (for example, when I change the number of bytes in the write buffer)

Without writing to SD card via fsfwrite, I am able to receive the proper photo with no interference when sending the data via UART. Once I attempt writing to sd card (whatever the data is) when fetching the pixel data , the next few hundreds pixels returned by the camera will be "dead".

The analog camera output is connected to the PIC analog input. I have verified independently that the SD card code is able to read and write files properly on its own with no problems such as corrupted data. I have also verified that the analog input is working properly during the SD card write cycles by connecting the input pin to a 1kHz 1Vpp waveform from my scope and try to take a photo - there are no horizontal stripes like above (see the second last photo)

My only conclusion is that writing to SD card is creating some sort of interference that is sensed by the Gameboy camera, resulting in a distorted image. I try various way such as covering the SD card, covering the gameboy camera with anti-static bags, or by using decoupling capacitor, to no avail. The only thing that removes the stripe is to use my finger to cover the camera lenses totally, which will generate a gray photo. (see the last photo)

Any suggestions on where the interference is coming from or how to remove it? Thanks in advance!
 
Last edited:
Are the camera and SD card on the same power supply (even if the SD card has a 3v3 conversion) ... SD cards can take a bit of power.. If the picture is reasonable before you access the card, then there may be a slight power drop causing the camera to produce this behaviour...
 
Hi Ian,

Thanks for the very fast reply!

Yes, the camera and the SD card is on the same power supply.

My connection is as follows

9V battery ---> 7805 ---> 5V (to camera)
5V from 7805 ---> 7833 --> 3.3V (to SD card and PIC)

Some pins on the PIC are set as open-drain in order to interface with the camera which works at 5V, if that gives any more info.

The image quality is fine before writing to sd card. Also, reading from sd card via fsfread does not affect the image quality!

I notice that my LCD backlight starts to flicker as the SD card is being written to. Do you think I should give the SD card an independent power supply from a different set of batteries and regulator instead? Or what is the proper way to work this out from a single power supply?
 
Just upgrade the 5v 7805 to a larger device the TO220 variety has oodles more.... If you have a different SD card try that first as some take more power than others

The spec say's they should take 75mA max when writing... But I do know some are way over that.
 
Hi Ian,

I have yet to upgrade the voltage regulator setup but I tried again today. With fresh batteries, all voltage levels are stable even during SD card write (4.92V to Gameboy camera and 3.20V to PIC and SD card). The circuit (PIC @ 32MHz w/ PLL, SD Card, Gameboy Camera, and LM386 with 8-ohm speaker connected to the PIC PWM output) is consuming 109mA normally and 113mA during when SD card is being written to.

Looking again at the image, I noticed that the stripes are not totally out of place. The pixel data is actually correct, just a bit darker than surrounding pixels. Since the gameboy camera is analog, this is a hint to me that the accuracy of the PIC analog-to-digital converter may have played a role. I config the ADCON module to use system-clock, Vref+=AVdd, VRef-=AVss. A decrease in AVdd during writing to SD card may have reduced the range, resulting in higher value for the same input voltage. However, as mentioned above, Vdd stays stable during SD write cycles. So this can't possibly be the problem.

Do you have any other suggestions? Many thanks :)
 
Last edited:
It still seems like a voltage drop to me..

We had a similar issue with our alarms on a H8 system.... The signal voltages were 4 - 3V when one of the signal went out of range the alarm would sound... The smallest of voltage drop caused the voltage to return to within range... The alarm stopped..... guess the rest... The point being, its a drop in voltage somewhere... If you are reading the analogue signal from the camera you are most likely reading the 0 -1v pk to pk signal coming in from the camera.... If you have a scope, I would watch this signal...
 
I just wasted another full day (again!) debugging the problem. No success yet. Monitoring the signal on my oscilloscope, I concluded that the issue is from the gameboy camera analog output (0..1.7V) that somehow seems to return darker intensity when the SD card is being written to, and not the PIC ADC module. I have tried to use separate regulators for each component, e.g. 1x7805 (TO-92) for the Gameboy camera, 2x7833 (TO-92) for the PIC and the SD card respectively. All regulators are connected to the same 9V supply, not a 9V battery but 6xAA Energizer batteries that should provide plenty of power. Still the problem is exactly the same. I even tried to use a separate power supply for the SD card - the problem is still there!

I also monitored the power supply with my oscilloscope as the SD card is being written. With the previous setup, there was indeed a 0.1V drop during SD card write cycles. There was none this time and the power supply is stable throughout.

The only hint is that with the new setup and no other code changes, my AD1CON3 registers (which controls the conversion clock data rate) has to be adjusted - otherwise the PIC will not get the correct intensity value (always brighter than what it should be). Not sure if this is relevant.

Any other suggestions?
 
Last edited:
The only other suggestion is to put a decoupling cap 1uf - 10uf close to the SD card power rails...

The point about the conversion clock is VERY relevant... If the sampling time isn't stable this would cause this effect.... Is the writing of the card affecting the program cycle?

What I'm getting to is... lets assume under normal conditions your program is cycling 'n' times a second and you have the wrong conversion time.. When writing to the card the program cycle will be longer.... Try one thing.... get your ADC reads into an interrupt so the read speed is constant... ( If you have already taken this into account... dis-regard this bit )
 
With limited time available (this is a hobby project) and lots of other things I wanted to try, I did a last attempt on the project last night and here are my observations:

1. The PIC ADC module is not to blame because when simulating the gameboy analog output with a signal generator, the generated image is perfect and does not exhibit such interference.

2. The delay itself when writing to SD card is also not to blame. I tried simulating the sd card write cycles by adding a delay_us(100), then sent the image data via UART and reconstructed the image on the PC. The constructed image, also did not have such interference.

3. The delay between retrieving pixels (the gameboy camera sends a new pixel upon a new rising edge on its clock line) indeed makes the image brighter (due to an increase in the exposure time). However, as I write to SD card per every pixel, and not per group of pixels - 3 bytes per each pixel for 24-bit bitmap, this would not have caused such a weird patterns of brightness in the image.

4. The distorted image is from the gameboy output itself. I recorded the output voltage using my Rigol oscilloscope, exported it to PC and write software to reconstruct the image. The same inteference effect exists!

5. The point about the ADC conversion clock and the change of the power supply configuration I discovered is somewhat relevant. With the previous shared regulator config, there were random noises when the SD card is being written to (a 7805 in TO-92 form can only deliver 100mA, while the circuit can consume up to 110-140mA). The sampling time has to be longer to reduce the effects of these noises. With the new independent regulator config, there are no longer noises, and the sampling time can be shorter. But that's all to it.

6. To answer your questions, I have also tried decoupling capacitor and moving the ADC stuff to an interrupt. I even tried a buffer of 512 bytes and only write to SD once the buffer is full. Same effect, although the interference pattern is different.

This is my ADC code:

AD1CON1bits.ASAM = 0;
AD1CON1bits.SSRC = 0b111;
AD1CON1bits.ADSIDL = 0;
AD1CON2bits.VCFG = 0b000;
AD1CON3 = 0b0001111100010111;
AD1CHS = 0;

The ADC is in manual sampling mode, I only start sampling after I send the camera the clock pulse:

int getAdcValue()
{
//start a measurement with the ADC
AD1CON1bits.DONE=0; //resets DONE bit
AD1CON1bits.SAMP=1; //start sample
while(AD1CON1bits.DONE==0); //wait for conversion to finish
AD1CON1bits.SAMP=0;

return ADC1BUF0; //get the voltage measurement
}

Although the program cycle changes when writing to the SD card, I don't see how using a delay instead does not result in the same problem. Also reading from card (via fsfread) does not cause such behaviour.

I have also tried various other SD cards, same effect.

One last question regarding connecting from the SD card to the PIC, is a direct connection sufficient, or do I need pull-up/pull down registers for SD_CS, MOSI, MISO and CLOCK? Although I don't see how writing/reading the SD card would still work properly otherwise if any required connection is missing.

Is there also a possibility that writing to SD card generates some sort of noises/inteferences that is interpreted by the camera sensor itself?
 
Last edited:
One last question regarding connecting from the SD card to the PIC, is a direct connection sufficient, or do I need pull-up/pull down registers for SD_CS, MOSI, MISO and CLOCK? Although I don't see how writing/reading the SD card would still work properly otherwise if any required connection is missing.

If both run at same voltage level I see no reason for extra resistors...

I am now looking at the ground potential.... There is definitively a problem with power levels.. If you have checked EVERYTHING else.....

The point about being able to send the image to a PC ok, said it all. The noise may be coming from the ground rail...

Can you double up all the ground connections, to ensure ground bounce is kept to a minimum.
 
Well, the problem is somehow determined to haunt me even after almost everything has been taken away! Two months ago, I decided to forget about it and played with the Microchip USB HID sample project using a PIC18F4550. Out of curiosity, I interface the Gameboy camera to the PIC and added the code for the PC client (a Microsoft .NET app) to retrieve the image from the Gameboy camera. Image data is transferred by packets of 64bytes each. Only the Gameboy source code is re-used, and guess what, everything is working, except that the captured image when transferred to PC still has the above-mentioned horizontal stripes, although much fewer, around 3-4 stripes/image! Again, transferring the image via UART to a PC serial port has no such problems.

So my (temporary) conclusion is that it has nothing to do with the SD card, but perhaps with power levels ... Hope that one day I will be able figure it out...
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top