An electronic device comprising a system-on-a-chip, SOC, within a package, the SOC having, formed therein, at least: a reference generator; a matching circuit; a programmable current generator configured to generate a programmed current; a pulse width modulation controller; an overvoltage/undervoltage detection circuit configured to receive a high voltage from a third output pad; a multiplexer configured to selectively pass an input signal to a second output pad; at least one single photon avalanche diode, SPAD, having an anode coupled to receive the high voltage; and switching circuitry (S1, S2, S3, S4, S5, S6); wherein the switching circuitry is configured to, in an internal generation mode: connect an output of the reference generator to the matching circuit such that the matching circuit receives a temperature independent reference voltage generated by the reference generator in the internal generation mode; connect an output of the matching circuit to the programmable current generator so that the programmable current generator receives a matched temperature independent reference current generated by the matching circuit in the internal generation mode; connect the programmed current to the overvoltage/undervoltage detection circuit, with a feedback voltage being generated by components of the overvoltage/undervoltage detection circuit in the internal generation mode; cause the multiplexer to pass a pulse width modulation, PWM, signal at its input to the second output pad, the PWM signal being generated by the pulse width modulation controller based upon the feedback voltage, in the internal generation mode; and couple the PWM signal to a first output pad. a reference generator; a matching circuit; a programmable current generator configured to generate a programmed current; a pulse width modulation controller; an overvoltage/undervoltage detection circuit configured to receive a high voltage from a third output pad; a multiplexer configured to selectively pass an input signal to a second output pad; at least one single photon avalanche diode, SPAD, having an anode coupled to receive the high voltage; and switching circuitry (S1, S2, S3, S4, S5, S6); wherein the switching circuitry is configured to, in an internal generation mode: connect an output of the reference generator to the matching circuit such that the matching circuit receives a temperature independent reference voltage generated by the reference generator in the internal generation mode; connect an output of the matching circuit to the programmable current generator so that the programmable current generator receives a matched temperature independent reference current generated by the matching circuit in the internal generation mode; connect the programmed current to the overvoltage/undervoltage detection circuit, with a feedback voltage being generated by components of the overvoltage/undervoltage detection circuit in the internal generation mode; cause the multiplexer to pass a pulse width modulation, PWM, signal at its input to the second output pad, the PWM signal being generated by the pulse width modulation controller based upon the feedback voltage, in the internal generation mode; and couple the PWM signal to a first output pad. connect an output of the reference generator to the matching circuit such that the matching circuit receives a temperature independent reference voltage generated by the reference generator in the internal generation mode; connect an output of the matching circuit to the programmable current generator so that the programmable current generator receives a matched temperature independent reference current generated by the matching circuit in the internal generation mode; connect the programmed current to the overvoltage/undervoltage detection circuit, with a feedback voltage being generated by components of the overvoltage/undervoltage detection circuit in the internal generation mode; cause the multiplexer to pass a pulse width modulation, PWM, signal at its input to the second output pad, the PWM signal being generated by the pulse width modulation controller based upon the feedback voltage, in the internal generation mode; and couple the PWM signal to a first output pad.