Now I am measuring the current voltage and also photo effects of red and green LEDs. Below is a summary.
1. I am using 560R as the series current limiting resistor for each of the 8 segments. Both digital and moving coil current meter measure around 1.8 mA. I am not sure if I should multiply this by 4 because the duty cycle is 1/4. Or if the current meter is measuring the root mean sequare, then I should multiply by 1.4. I forgot all these basic electrical theory because it was too long time ago I studied it in college and almost never use it after graduation.
2. I used a scope to measure the voltage at the output of GPi. I found that without and with current passing a segment, the voltage is about 2.8V and 2.4V. In other words, the voltage drops from 2.8V to 2.4V when passing a current of around 2mA. Since the XC9572XL's max current sink is 4mA. So I guess I am not overloading the CPLD, which would cost me HK$12 if burnt. So I forget about using HC573 or ULN2803 to buffer the segment currents.
3. I found the green led a bit more pleasant to my eyes, but not to my cheap Sony digital camera, which could barely detect the green light if using camera flash. If not using camera flash, the green led digits look sharp, while the red digit look blurred. But if not using camera flash, the background object look too dark. So my conclusion is that for better camera pictures, it is better to use red LEDs.
// Display Guzunty Pi 4 LED digits - tlfong01 2013apr22hkt1001
#include <unistd.h>
#include <gz_spi.h>
#include <gz_clk.h>
const unsigned char font[10] =
{
0x3f, 0x06, 0x5b, 0x4f, // 0, 1, 2, 3
0x66, 0x6d, 0x7d, 0x07, // 4, 5, 6, 7
0x7f, 0x6f // 8, 9
};
const unsigned char SevenSegmentPatternDigit0 = ~0x3f;
const unsigned char SevenSegmentPatternDigit1 = ~0x06;
const unsigned char SevenSegmentPatternDigit2 = ~0x5b;
const unsigned char SevenSegmentPatternDigit3 = ~0x4f;
const unsigned char SevenSegmentPatternDigitSpace = 0xff;
const unsigned char SevenSegmentPatternDigitAlOn = 0x00;
int main()
{
gz_clock_ena(GZ_CLK_5MHz, 0xfff); // turn on RPi clock
unsigned char SevenSegmentPatternDigitList[4];
gz_spi_set_width(4); // pass blocks of 4 bytes on SPI
SevenSegmentPatternDigitList[0] = SevenSegmentPatternDigit0;
SevenSegmentPatternDigitList[1] = SevenSegmentPatternDigit1;
SevenSegmentPatternDigitList[2] = SevenSegmentPatternDigit2;
SevenSegmentPatternDigitList[3] = SevenSegmentPatternDigit3;
gz_spi_write(SevenSegmentPatternDigitList);
sleep(2);
SevenSegmentPatternDigitList[0] = SevenSegmentPatternDigitSpace;
SevenSegmentPatternDigitList[1] = SevenSegmentPatternDigitSpace;
SevenSegmentPatternDigitList[2] = SevenSegmentPatternDigitSpace;
SevenSegmentPatternDigitList[3] = SevenSegmentPatternDigitSpace;
gz_spi_write(SevenSegmentPatternDigitList);
sleep(2);
SevenSegmentPatternDigitList[0] = SevenSegmentPatternDigitAlOn;
SevenSegmentPatternDigitList[1] = SevenSegmentPatternDigitAlOn;
SevenSegmentPatternDigitList[2] = SevenSegmentPatternDigitAlOn;
SevenSegmentPatternDigitList[3] = SevenSegmentPatternDigitAlOn;
gz_spi_write(SevenSegmentPatternDigitList);
sleep(600);
gz_spi_close(); // close SPI channel
gz_clock_dis(); // turn off clock
return 0;
}
//.END
No comments:
Post a Comment