lots of text, tl;dr but driving an LED with a pwmd constant current sounds like dimming, though I probably would not do it that way but build an adjustable current drive
the key is that since LEDs are current driven what you want is to have the control loop control the current, not the voltage as it is traditionally done
lets step back a moment and look at a linear regulator like thing. you have a voltage going into an opamp, and the opamp drives a pass transistor and gets the feedback from the transistors output voltage. so that voltage at the beginning controls the voltage of the transistor
then you can change that into taking the voltage drop over a shunt resistor as an input, so it gets a current source.
well, in this case the only changes should be the LED warming up and battery draining; I've already constructed the battery measuring circuit which seems to work well, even if it's a tad inaccurate
I think I like the idea of having the current set outside of the mcu though
@PlasmaHH it's one Luxeon K2, supposedly 5W. Driven from a 6V 5-cell NiMH pack
that being said, I am not sure if the lamp itself doesn't have some additional compoents; I don't see the LED, as that's enclosed, and there are 3 wires going out. I am not even sure what the third one is for.
@PlasmaHH I mean, the LED is inside a lamp, right. So the LED datasheet doesn't mention the third wire, it's something the manufacturer might have put there
It should be not much of a problem for a µC to create some voltage between 0 and 150mV and for increased accuracy you could use a divider and have the µC create higher ranges
(if you want to use the µC pwm to create that voltage you obviously have to filter it to make it (near) DC, and if the µC has an analogue input pin you can measure that voltage too)
yes, pwm isn't a voltage itself, its just a square wave, you have to filter that to make it like DC ... if your µC has a DAC output then that would be easier though
at least anything like this will make it much easier on the coding side of the µC and it will make it possible for you to split it into two independent parts
you can program the µC to output the DC and until you get that right you can feed into your opamp some DC from another source taht is not the µC to test that and at the end connect both modules
imho much easier as a project when you are not experienced