
A normal LED is used as a light sensitive device.
Revision 1:f4abb1d24a76, committed 2014-11-02
- Comitter:
- mdUJHS
- Date:
- Sun Nov 02 21:51:43 2014 +0000
- Parent:
- 0:bee32ed0a6b4
- Commit message:
- A normal LED is used as a light sensitive device.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Nov 01 20:29:33 2014 +0000 +++ b/main.cpp Sun Nov 02 21:51:43 2014 +0000 @@ -1,40 +1,42 @@ -// Program.: Photo_LED +// Module..: Photo_LED // Version.: 1.0 -// Chip....: STM32F4xx +// Chip....: STM32F411RE // Date....: November 2014 // Author..: UJ //----------------------------------------------------------------------------- // This program is a simple demonstration how a normal LED can be used as a -// photo diode. The hardware platform I have used is the NUCLEO 411RE, but -// the principle can be used with every modern CMOS-controller. +// photo diode. The hardware platform I have used is the NUCLEO F411RE, but +// the principle will run on every modern controller with high-impedance +// Schmitt-trigger inputs. // // Harware sketch: -// LED (20mA, green or red) -// |\ | -// | \ | -// -----| \|---- -// | | /| _|_ -// | | / | | | -// | / | | 100 Ohm -// | |___| -// | | -// | | -// - - -// |O| |O| -// - - -// Anode Pin Cathode Pin +// _____________________ +// | | +// | __|__ +// | \ / LED (20mA, green or red) +// | \ / +// | ------- +// | | +// | _|_ +// | | | +// | |100| Ohm +// | |_ _| +// | | +// | | +// | | +// Anode Pin (PC10) Cathode Pin (PC11) // // How it works: -// In the first phase the LED is turned on in it´s normal mode for 50ms. -// In the second phase the LED is driven with a reversed voltage for 10ms +// In the first phase the LED is turned on in it´s normal mode for 50ms. +// In the second phase the LED is driven with a reversed voltage for 5ms // (anode negative, cathode positive). This will charge the internal capacity // with reverse potential. Then the anode pin is configured as a high-impedance // input pin. It takes some time until the voltage at the anode pin will raise -// above the Schmitt-trigger level. This time is depending on the over all -// circuit resistance, but also very depending on the ambient light. +// above the Schmitt-trigger level. This time is depending on the over all +// circuit resistance and the ambient light. // -// Warning: +// Hint: // The capacity of the LED is very low (5..35pF). Do not place the board // to a conductive ground. Even humidity will change the blink frequency. // Do not touch the components. @@ -43,16 +45,26 @@ #include "mbed.h" //----------------------------------------------------------------------------- +#define IWDG_RESET() (IWDG->KR = 0xAAAA) +//----------------------------------------------------------------------------- + +Serial terminal(USBTX, USBRX); + DigitalInOut anode_pin(PC_10); DigitalOut cathode_pin(PC_11); //----------------------------------------------------------------------------- int main(void) { - anode_pin.output(); + unsigned char cnt; + + terminal.baud(115200); + terminal.printf("Photo LED\r\n"); while (1) { + IWDG_RESET(); + // Set normal LED operation, turn on LED for 50ms // Setup PC10 as output anode_pin.output(); @@ -61,13 +73,18 @@ // Set anode (PC10) high and cathode (PC11) low anode_pin = 1; cathode_pin = 0; - wait(0.05f); + + for (cnt = 0; cnt < 10; cnt++) + { + wait(0.005f); + IWDG_RESET(); + } // Apply reverse voltage to the LED for reverse charging the LED´s capacity // Set anode (PC10) low and cathode (PC11) high anode_pin = 0; cathode_pin = 1; - wait(0.01f); + wait(0.005f); // Setup anode (PC10) as input anode_pin.input(); @@ -76,6 +93,8 @@ // This time is strongly ambient light depending while (anode_pin.read() == 0) { + IWDG_RESET(); + wait(0.005f); } } }