Rev. 1.10
94
November 04, 2019
Rev. 1.10
95
November 04, 2019
HT45F5Q-3
Battery Charger Flash MCU
HT45F5Q-3
Battery Charger Flash MCU
The diagram shows the ideal transfer function between the analog input value and the digitised
output value for the A/D converter. Except for the digitised zero value, the subsequent digitised
values will change at a point 0.5 LSB below where they would change without the offset, and the
last full scale digitised value will change at a point 1.5 LSB below the V
REF
level.
Note that here the V
REF
voltage is the actual A/D converter reference voltage determined by the
SAVRS field.
FFFH
FFEH
FFDH
03H
02H
01H
0
1
2
3
4093 4094 4095 4096
V
REF
4096
Analog Input Voltage
A/D Conversion
Result
1.5 LSB
0.5 LSB
Ideal A/D Conversion Function
A/D Conversion Programming Examples
The following two programming examples illustrate how to setup and implement an A/D conversion.
In the first example, the method of polling the ADBZ bit in the SADC0 register is used to detect
when the conversion cycle is complete, whereas in the second example, the A/D interrupt is used to
determine when the conversion is complete.
Example: using an EOCB polling method to detect the end of conversion
clr ADE ; disable A/D converter interrupt
mov
a,03h ;
select
f
SYS
/8 as A/D clock and
mov SADC1,a ; select external channel input and external reference input
mov a,0Ah ; setup PBS0 to configure pin AN0 and pin VREF
mov PBS0,a
mov a,20h
mov SADC0,a ; enable A/D and connect AN0 channel to A/D converter
:
start_conversion:
clr START ; high pulse on start bit to initiate conversion
set START ; reset A/D
clr START ; start A/D
polling_EOC:
sz ADBZ ; poll the SADC0 register ADBZ bit to detect end of A/D conversion
jmp polling_EOC ; continue polling
mov a,SADOL ; read low byte conversion result value
mov SADOL_buffer,a ; save result to user defined register
mov a,SADOH ; read high byte conversion result value
mov SADOH_buffer,a ; save result to user defined register
:
:
jmp start_conversion ; start next A/D conversion