Hysteresis Code - C/C++

cancel
Showing results for 
Search instead for 
Did you mean: 

Hysteresis Code - C/C++

4,576 Views
Contributor III

Hi, in my design I'm charging a battery using a USB connection.  

I'm using the MK22FN256VLH12 uC in my project.

I will attach my code that I wrote.  I'm adding Hysteresis so the LED doesn't blink both Green and Red at the same time when I'm at the threshold from Charged / Not Charged.  I'm not sure if it's correct. 

Any feedback would be great.

Thanks,

Brian

Labels (1)
0 Kudos
1 Reply

475 Views
NXP TechSupport
NXP TechSupport

Hi, Brian,

I do not know your application clearly. But for the Hysteresis function, pls refer to the following figure, you have to define the threshold f16HystOFF and f16HystON value, when the input variable f16In is greater than f16HystON, f16OUT=f16OUTON.  When the input variable f16In is less than f16HystOFF, f16OUT=f16OUTOFF. When the input variable f16In is greater than f16HystOFF and less than f16OUTOFF, f16OUT variable remains it's value.

This is the code:

if( f16In>f16HystON) f16OUT=f16OUTON;

if( f16In<f16HystOFF) f16OUT=f16OUTOFF;

it is okay.

Hope it can help you

BR

Xiangjun Rong

pastedImage_1.png

0 Kudos