Microcontroller based ADC

Job ID: 33798568

Budget: $10 – $30 USD

In a microcontroller-based system, analogue to digital converter (ADC) is sensing analogue voltage coming on one of the analogue channels. This analogue voltage needs to be converted into a discrete level (0-4) depending upon the value of input voltage in such a way that some hysteresis is added to reject sudden voltage variations due to noise. Following graph shows the relationship between analogue voltage read (%age) from the channel to the discrete level that need to be encoded by the software. Write code that will perform this job. Use this prototype so the code can be tested: unsigned int hysteresis(unsigned int input_percent)
Hint: If analogue voltage increases from 9% to 15% encoded step shall be 1 and if it decreases back to 11% from 15%, the encoded level shall remain 1 unless voltage drops to 10%.

Embedded C problem