A novel digital constant output current controller with demagnetization-time compensation for flyback converter is proposed in this paper. The secondary winding demagnetization time [Formula: see text] is sampled from the comparison module output signal by output voltage sampling state machine. The ratio between [Formula: see text] and switching period [Formula: see text] is kept constant by bidirectional counter module to achieve constant output current based on invariable primary-side peak-current. Meanwhile, demagnetization-time compensation is proposed in order to enhance load regulation ratio. The compensation [Formula: see text] acquired from a look-up table, is utilized to compensate the impacts caused by the delay [Formula: see text] from the process of sampling the signal of [Formula: see text]. The digital controller (DC) is implemented by hardware description language Verilog HDL. Experimental results of the proposed 2A constant current output flyback converter based on FPGA(EP2C8Q208C8N) indicate that the constant current precision is within [Formula: see text]1% in a wide range of universal-input AC voltage from 110[Formula: see text]V to 240[Formula: see text]V and the voltage load range between 2[Formula: see text]V and 8[Formula: see text]V.