Monday, June 9, 2014

Arduino - Cast Int to Byte - What happens?

For a project I need to spread a 16-bit unsigned integer across one byte variable and two 1-bit variables, all of which will be written to pins. The reason is not important, but I needed to know what happens to the byte value when I cast it to the byte variable. I understand that it will be truncated, but what will? The higher 8-bits or the lower 8-bits?

To find out, I wrote a quick program with a lot of clear text output.


// cast test by Jordan
// Test truncation of variables from one type to another
// most importatntly: int to byte

unsigned int intVar = 0x4080; // will it truncate to 01000000 or 10000000?
byte byteVar = 0x33;
void setup(){
  Serial.begin(9600);
  Serial.print("hello world.");
  Serial.println();
  Serial.println();

}

void loop(){
  Serial.println("integer variable equals: ");
  Serial.println(intVar, BIN); // print variable in binary
  Serial.println();
  Serial.println("byte variable equals: ");
  Serial.println(byteVar, BIN);
  Serial.println(".");
  Serial.println("..");
  Serial.println("...");
  byteVar = (byte)intVar;
  Serial.println("byte variable now equals: ");
  Serial.println(byteVar, BIN);
  while(1){} // loop forever
}

Then I uploaded it to my Arduino Nano and opened the serial monitor. I then uploaded it to my Teensy 2.0 to double check the code across platforms. Teensy is a little different in some aspects, so I had to make sure. They both output exactly the same thing:

Serial monitor output:

"hello world.
integer variable equals:
100000010000000
byte variable equals:
110011
.
..
...
byte variable now equals:
10000000"

These are the exact results that I wanted to see. I may continue on with more programming now...

EDIT: Further testing proves that the same theory does NOT hold true with booleans. (get it? "true") I had hoped that the boolean could be used to store a 1-bit number, but it turns out they are actually some sort of integer in disguise! I will have to figure out some fast way to manipulate individual bits...

Wednesday, June 4, 2014

Repairing an LCD Monitor

I am damn cheap, and this isn't the first time I have gotten a broken monitor to use as my own. By broken, I do not mean that the LCD is cracked, but that it comes on and goes off immediately. Some even went black and had a buzzing noise. More often than not, this means some capacitors on the power board are swollen or popped. This is just a detailing of one monitor in particular, but the method is nearly identical to other modern screens. The other problem that could occur seems less common, so I will not cover it here. The less common problem is the wires connecting to the CCLF tubes coming loose.

Step 1. Open the screen.
Unplug the monitor and press the power button a few times to (mostly) discharge any good capacitors.
Find all of the screws that are visible including VGA/DVI mounting screws and remove them, keeping a good idea of which holes they came from.

Now pry apart the plastic shell carefully. I use an expansion slot cover found on the back of a PC because they are wider than a screwdriver and leave less cosmetic damage (if any at all). Once you have the plastic bevel popped all around the edges, place the screen on your surface area, or lap, face down and lift the plastic off the back. This may not be the exact way for all monitors, but it has been for the last four I repaired.

Step 2. Take note of the orientation of the wires leading from the metal shielding. THese connecto to the high voltage CCFL tubes and may or may not be polarized. Don't screw this up! Take a photo if it helps.



Remove the metal shielding from the power and logic boards. Be very careful of any ribbon cables.
You should find the power board which is suspect.



Step 3. Inspect the power board. If you find swollen capacitors, you probably found the culprit. In our case, there are two swollen capacitors. From my experience, they normally go out in pairs, but I cannot prove that. Can you see the two fatties?




Step 4. Replace the capacitors with a "good" brand. Nichicon is my favorite. Make sure that the Farads are matched exactly and that the voltage is either the same or higher. Higher is better in this case, but normally the caps become larger with a higher voltage tolerance.



Step 5. Put it back together and power it up. ta-da! Although this is not 100% to work for you, it is a common problem and an easy fix. Good luck and good modding.

-Jordan

 ps. The monitor in this example was the Westinghouse L1975NW. I replaced two 220uF 25v capacitors with two 220uF 35v capacitors.
I also repaired an Acer x193w+ with new caps and some other Acer I no longer have.
One time I found that a Dell E2K-SE198WFPF(B) by reconnecting the CCFL tube with its wire which was difficult and apparently dangerous. To do so I had to disassemble the screen itself, LCD, polarizing film, and other layers just to get at the tubes...which were well encased in rubber. It was very difficult and I don't think that I would attempt it again.