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.

Photodiode to PIC

Status
Not open for further replies.

mr. mister

New Member
i want to connect a phtotransistor to a pic to receiver a pulsed input from a transmitter. Is this connection right??

what i want is for output to pic to be high when light comes into the pic

what resistance value do i need to set?? i have added a picture of what i am trying to explain.

will i need other components to achieve this??

i am meant to set a resistor value that sets the output to the PIC as >2.8v for a high and <0.4v for a low.
 

Attachments

  • pic2_421.jpg
    pic2_421.jpg
    11 KB · Views: 349
details you might need to know about the phototransistor;

collector emitter voltage: 35v
collector current: 15mA
collector peak current (t<10us): 75mA
Photocurrent, collector to emitter (1000 lux, Vce = 5v): 5mA typical
 
Configuration 'B' would make the pin go high when light falls on the transistor, however, configuration 'A' is the way it's usually done - 'A' can pull the input closer to 0V than 'B' can to 5V.

The only difference is a very slight change in the program, so it makes sense to use 'A' rather than 'B'.

As for the resistor value, I would find it by experiment!, all you need is a few resistors and a multimeter.
 
Cheers nigel :D

i have another question though

i've got a pic program reading an input pulsed signal. clock frequency is set at 4MHz, prescaler at 16. I'm pretty sure i've read a value into the timer register which is between 2.078ms - 2.094ms. The thing is i want to set a tolerance level in my program by maybe subtracting what is in the timer register from maybe 2.1ms max and 2.05 min and checking the status register's carrier flag.

Problem is i don't know the hexadecimal value to put in for 2.05ms and 2.1ms. I do realize this may be a stupidly easy question :oops:
 
on the resistor value thing. Measure the mA with max light and no resistor (just connect it to power rails) then use v=ir or rather r=v/i to work out a resitor value.

The v to use is your max voltage, the i to use if the measured current + 10 or 15%

I get a value of 12k, so i would use a 10k resistor + a 5k pot. or similar to get some tuning range.

Lol, hope this is correct advice!
 
mr. mister said:
Cheers nigel :D

i have another question though

i've got a pic program reading an input pulsed signal. clock frequency is set at 4MHz, prescaler at 16. I'm pretty sure i've read a value into the timer register which is between 2.078ms - 2.094ms. The thing is i want to set a tolerance level in my program by maybe subtracting what is in the timer register from maybe 2.1ms max and 2.05 min and checking the status register's carrier flag.

Problem is i don't know the hexadecimal value to put in for 2.05ms and 2.1ms. I do realize this may be a stupidly easy question :oops:

You problem is caused by thinking in floating point numbers (2.05 etc.), a PIC (or any common micro) doesn't work in floating point, it works in fixed point binary.

If you're using a single register to store the reading, it can only vary from 0 to 255 (0xFF Hex), if you're using two registers it can go as high as 65,535 (0xFFFF Hex).

You simply need to find what values the readings actually are! - ignoring any silly decimal places that might be displayed, but the actual values stored in the GPR's themselves.

Assuming you are actually using floating point numbers (presumably in a high level language?), you should be aware that they are inherently inaccurate, and EXTREMELY!!!! slow, and take large amounts of program memory. There's only very rarely need to use them, by scaling the values you can use integer maths, which is 100% accurate (assuming you don't mess up!), and incredibly faster than floating point routines.

Programs like spreadsheets use integer maths to do monetary calaculations, floating point isn't good enough! - you've probably seen the old electricity bills for things like $123.64541275614384896 - instead of $123.65. That's the problem with floating point!.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top