I'm trying to make a constant current source.
The setup is as folowed:
I measure the output current and if it exceeds 2Amps I make a pwm signal high so it turns of the control IC
I thought it will get to a stable situation, but it is very instable.
I think this is caused by the way I turn on the pwm signal. but I don't know how to make it better I tried several things
I use a attiny24
My interupt is done every 1msec and than the pwm and ana1 are read and write.
I have tried to raise the speed of the interupt but this is not working also.
Can anyone help me or give me a push in the right way?
Main: ldi temp0,$00 mov pwm,temp0 ;load the pwm output (PB2) with 0V mov temp1,ana1 ;move the content of the AD into temp1 cpi temp1,overI ;compare ana1 with overI brcc constantI ;If ana1 is higher than overI jump to constant I rjmp main constantI: ldi temp0,$FF mov pwm,temp0 ;load pwm output with 5V mov temp1,ana1 ;update the AD of ana1 cpi temp1,overI ;compare ana1 with overI brcc constantI ;If ana1 is higher than overI jump to constant I rjmp main