An optical sensor system for measuring light intensity and comprising: a photodiode having a photodiode output for providing a current of a first polarity; an integrator having an integrator input selectively coupled to said photodiode output for receiving said current and an integrator output for providing an integrated output voltage; a comparator having a comparator input coupled to said integrator output and configured to compare the integrated output voltage with a threshold voltage to provide a comparison signal at a comparator output; a reference charge circuit coupled to said comparator output and to said integrator for providing charge packages to said integrator input, the charge packages having a polarity opposite to said first polarity; a reference voltage circuit having a reference voltage output for selectively providing at least a first defined voltage to the integrator input; a resistance selectively coupled between said integrator input and a reference voltage node to provide a current path between said integrator input and the reference voltage node; a control unit for (a) operating said integrator over an integration time during which period said photodiode output is coupled to said integrator input, and said reference voltage circuit does not provide said first defined voltage to the integrator input whilst said resistance does not provide said current path, (b) at the end of the integration time, disconnecting said photodiode output from said integrator input and causing said reference voltage circuit to provide said first defined voltage to said integrator input, whilst said resistance does provide said current path, until the comparison signal switches, wherein a period between the end of the integration time and the switching of the comparison signal is indicative of a residual voltage on the integrator output at the end of the integration time. a photodiode having a photodiode output for providing a current of a first polarity; an integrator having an integrator input selectively coupled to said photodiode output for receiving said current and an integrator output for providing an integrated output voltage; a comparator having a comparator input coupled to said integrator output and configured to compare the integrated output voltage with a threshold voltage to provide a comparison signal at a comparator output; a reference charge circuit coupled to said comparator output and to said integrator for providing charge packages to said integrator input, the charge packages having a polarity opposite to said first polarity; a reference voltage circuit having a reference voltage output for selectively providing at least a first defined voltage to the integrator input; a resistance selectively coupled between said integrator input and a reference voltage node to provide a current path between said integrator input and the reference voltage node; a control unit for (a) operating said integrator over an integration time during which period said photodiode output is coupled to said integrator input, and said reference voltage circuit does not provide said first defined voltage to the integrator input whilst said resistance does not provide said current path, (b) at the end of the integration time, disconnecting said photodiode output from said integrator input and causing said reference voltage circuit to provide said first defined voltage to said integrator input, whilst said resistance does provide said current path, until the comparison signal switches, (a) operating said integrator over an integration time during which period said photodiode output is coupled to said integrator input, and said reference voltage circuit does not provide said first defined voltage to the integrator input whilst said resistance does not provide said current path, (b) at the end of the integration time, disconnecting said photodiode output from said integrator input and causing said reference voltage circuit to provide said first defined voltage to said integrator input, whilst said resistance does provide said current path, until the comparison signal switches, wherein a period between the end of the integration time and the switching of the comparison signal is indicative of a residual voltage on the integrator output at the end of the integration time.