Comples PWM calculation

5 views
Skip to first unread message

David VB

unread,
Dec 3, 2025, 10:29:29 AMDec 3
to jallist
Hi there,

I have to compute a PWM value (PWMcal) (on 10 bits), depending on 4 values:
  • PWMprg = Value asked by the program [0..1023]
  • VALamb = Value of an LDR (from ADC) [0..1023]
  • PWMmax and PWMmin = values between which the final value (PWMcal) must be proportional to and within those two boundaries [PWMmin..PWMMax].  Those boundaries are word constants.
Examples: 
  • If PWMprg = 0 and VALamb=0, then PWMcal=PWMmin
  • if PWMprg = 512 and VALamb = 512 then PWMcal=[(PWMmax-PWMmin)/1024]+PWMMin  (= Half Way between PWMmin and PWMmax)
  • if PWMprg=1023 and VALamb=1023 then PWMcal=PWMmax

I'm not a genious on maths and can't make head or tales from it....
Any help welcome !

Thank you

David

Rob CJ

unread,
Dec 4, 2025, 1:40:04 PMDec 4
to jal...@googlegroups.com
Hi David,

Just some thoughts.

I think it is the easiest if PWMmin = 0.

I then it has to be something like this: PWMcal =  ((VALamb * PRMprg) / (1023 * 1023)) * PWMmax

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens David VB <pinhe...@gmail.com>
Verzonden: woensdag 3 december 2025 16:29
Aan: jallist <jal...@googlegroups.com>
Onderwerp: [jallist] Comples PWM calculation
 
--
You received this message because you are subscribed to the Google Groups "jallist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallist+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jallist/f3e84189-dc32-4fc4-8ff3-b2bb5cbae61bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages