Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - help with pwm repost

(you are viewing a thread; or go back to list of threads)

help with pwm repost (by JOHN)
any ideas or suggestions for ladder code to pwm using ambient light sensor im using pic16f877a and was thinking of using a LX1971IDU light sensor to input to mcu and use pin to control mosfet just not sure if this would be simplest solution or if i should just use a completely separate circuit any help would be great my goal is to use pwm to control the brightness to a led array of 96 green leds i want it to dim as it gets darker out and get brighter as the sun comes up
Tue Feb 17 2015, 23:39:26
(no subject) (by David R)
Hi John That should be easy The best way forward would be for you to design and post your circuit here.
You need to have the light sensor drive one of the ADC pins with a nice amount of voltage swing, say 1 volt at dark and 4 volts at max light.
So when you work out what the voltage is going to be at different light levels then it will be easy to build some code around that.
kind Regards
David.
Thu Feb 19 2015, 02:55:12
CIRCUIT (by JOHN)
this is what my circuit is going to be pwm out at ? light level output to which transistor is selected
Thu Feb 19 2015, 21:52:04, download attachment Untitled-5.jpg
(no subject) (by David R)
HI John I see problems with your circuit, including the output pin for the pwm is not correct, and the high-side transistor driving is not going to work, and i do not think 6 volts is ok?.
You need to correct your circuit first.
Thu Feb 19 2015, 23:50:15
(no subject) (by JOHN)
in ldmicro you can only use pin 16 for PWM unless im doing something wrong yes 6 volts is ok all components can use 6 volts pic is rated at 6.5 max and i am manually high side driving leds this way now in the emitter out the collector of a NPN FET
Fri Feb 20 2015, 00:10:15
(no subject) (by JOHN)
sorry in the collector out the emitter
Fri Feb 20 2015, 00:11:23
(no subject) (by JOHN)
like this
Fri Feb 20 2015, 00:26:56, download attachment Tran_hss.jpg
(no subject) (by JOHN)
ok modified to 5vdd
Fri Feb 20 2015, 00:43:03, download attachment Untitled-5.jpg
(no subject) (by David R)
With the high side switching once you have 5 volts drop across the leds then there is no base-emitter current flow
Fri Feb 20 2015, 02:54:14
(no subject) (by JOHN)
dont know what you mean buy that but i know it works as i have it breadboarded working! but nevermind ill find it out on my own
Fri Feb 20 2015, 02:58:52
(no subject) (by JOHN)
i think you have NPN and PNP mixed up !
Fri Feb 20 2015, 03:03:22
(no subject) (by JOHN)
you dont always need PNP to switch + and NPN to switch -
Fri Feb 20 2015, 03:04:18
(no subject) (by Jonathan Westhues)
6 V is within the abs max rated voltage for the '877A (i.e., they promise it won't blow up), but it's not within the recommended (i.e., they don't promise it will work). See, for example, section 17.1 of

http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf

And an NPN emitter follower works, but Ve will be roughly a diode drop below Vb, so ~5 V in your application, with most of the 24 V dropped across the transistor. Have you measured with a voltmeter?
Fri Feb 20 2015, 03:21:14
(no subject) (by David R)
HI i am not mixed up!

you are showing a supply of 24v with a high side switch (NPN) driving an array of leds so i assume there is going to be say 15 volts drop across the array of leds? because you are driving them with 24v.

ok if so,

once the voltage across the leds reaches 5 volts then the emitter potential of the transistor is at the same potential as the base drive so current stops flowing,

So

Yes this will work on a bread board with 1 or 2 leds but it will not work with an array.

The conclusion of this high side circuit you have drawn is yes it will work but the output voltage is limited to 5V-(0.6 vbe)=4.4v so there is no point operating it off 24v supply
Fri Feb 20 2015, 03:22:26
(no subject) (by JOHN)
and you did this with math? or did you bread board an array like i did? sometimes book smart doesn't always mean real world! like i said i will work it out as i know the whole circuit works i just needed help with the adc to pwm calcs but ill do it on my own i didn't need a working circuit analyzed just help with logic!
Fri Feb 20 2015, 03:39:49
(no subject) (by David R)
Best of luck with the circuit,

What would you like to know about the logic?
what is the voltage at the adc when you want the PWM full on?
what is the voltage at the adc when you want the PWM full off?
Fri Feb 20 2015, 04:02:52
(no subject) (by JOHN)
never mind circuit works its on now running on breadboard! the voltage is in the JPG look where it says INPUT SCALE the transistor does nothing more than connect the leds to the 24 volt rail when input is called on the cat4104 is taking care of the volt/current settings! by the way yes my array is working with all 96 leds ON! only problem is at full brightness! hence my need for the adc to pwm from the input of the lx1971idu to the pic!
Fri Feb 20 2015, 04:28:04
(no subject) (by David R)
Please read my question again! what is the voltage from the light sensor that you want code for?
Fri Feb 20 2015, 04:30:53
(no subject) (by JOHN)
again it is clearly in the JPG .25 volt to 5 volt SCALE! but i got it im altering a few files im combining together i thought this was a forum not a laboratory with hard core proffesers
Fri Feb 20 2015, 07:50:25
(no subject) (by JOHN)
thanks for the help but in the future you should look at and examine DATA sheets on listed components in circuit before drawing conclusions not a bad thing you know
Fri Feb 20 2015, 08:06:40
(no subject) (by MGP)
Read what experience people are writing, is also not a bad thing, you know.
You can learn from it and we do this for free!

It was you who asked for a program and the least you can do is give us all the information you have.

Writing a program lasts 15min IF you have all the data.

Your circuit can not work as drawn with NPN transistors and more than 3 LEDs, read David's reaction.
Fri Feb 20 2015, 09:08:11
(no subject) (by JOHN)
i know how long writing code takes sometimes i simply just needed help with adc to pwm as i not to experienced in that area but im confused when someone tells me something wont work and i am watching it function in front of me as for the pwm dim to bright i had it on the jpg where it said .025v to 5v output from lx1971idu to the mcu
Fri Feb 20 2015, 14:13:58
(no subject) (by JOHN)
redrawn
Fri Feb 20 2015, 14:26:18, download attachment Untitled-5.jpg
update (by JOHN)
decided to skip to whole LDMICRO approach im going to use a 555 running astable mode and use my lx1971idu to adjust timing sorry this was so argumentative it wasn't to be this way i just wanted help with code not electrical engineering! i have been building circuits for years and know the artistry and the cheats as well experimenting goes a long way!!! i just cant get this MICROCONTROLLER code thing yet (im old school) but anyways cheers all!! happy book smart computing !!!!
Fri Feb 20 2015, 18:14:30
(no subject) (by MGP)
You can't make this working with a LM555...

I am also old school (61y) but practice is the clue.

The circuit around the light sensor is not suitable to connect to an ADC, read the datasheet of the 16F877A on the ADC inputs.

I don't believe neither that you can get an output between 0.25 and 5V from the light sensor.

But I made your program with lots of comments inside.
Good luck....
Sat Feb 21 2015, 02:56:56, download attachment Light_sensor.ld
(no subject) (by JOHN)
thanx for the help got it working using a 100k pot but wanted it to be automatic using light sensor ill figure it out as i always do im a loner only turned to this forum as i had gotten a head ache me 55 years old and did you peak at the lx1971idu data sheet?
Sat Feb 21 2015, 08:57:55
(no subject) (by MGP)
I have found a schematic with this light sensor (pic. is from digikey website).
The picture is not clear but good information.
Sat Feb 21 2015, 09:30:08, download attachment sensorLX1971.jpg
PWM / VOLTAGE (by JOHN)
thanx MGP still in a dilemma as to vary voltage or drive PWM with two different current drawing led circuits one being an array of leds and one being leds arranged to form a seven segment 2 character display counting down from 10-0 the current changes with each number i think PWM at the source is the best way see figure 1 this would be my ADC in to mcu and that would convert to PWM out of the mcu as your code shows ?
Sat Feb 21 2015, 15:13:27, download attachment Untitled-1.jpg
(no subject) (by MGP)
I do not know exactly what you mean, but you'll have to figure it out myself because I do not have that light sensor to try.

Your syntax without punctuation is very difficult to read.
Sun Feb 22 2015, 07:58:05
(no subject) (by JOHN)
ok cool time to blow stuff up!
Sun Feb 22 2015, 12:32:27
(no subject) (by JOHN)
why is sensor needed? nobody said that in my first posts? now im confused
Sun Feb 22 2015, 12:39:48
(no subject) (by JOHN)
okigetitnobodywantstohelpbecauseofmycriticisumbutnowwillanybodyatleastetrybeforetheycomment!!!!!!!!!!!!!!
Sun Feb 22 2015, 12:51:58
(no subject) (by MGP)
Trying What?
You have your program? and what we get? some !!!!!!!!!!!!
Thx
Sun Feb 22 2015, 16:16:12
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):