ADC Configuration in mplab MCC

Thread Starter

Владимир Чижиумов

Joined Aug 31, 2019
8
Hi. I'm trying to use ADC in PIC MC. The problem is in all examples I've seen there's just left and right alignment of result. But in my MpLab I see totally different things (added pic.) . And how i understand...sing magnitude means left alignment since it set bit ADFM 0...But I'm not sure, and can't find ane other similar configs. Can someone help me with that?
 

Attachments

nsaspook

Joined Aug 27, 2009
6,504
http://ww1.microchip.com/downloads/en/DeviceDoc/40001675C.pdf

Read the datasheet.
17.1.6 page 173-174
17.1.6 RESULT FORMATTING The 10-bit and 12-bit ADC conversion results can be supplied in two formats: 2’s complement or sign-magnitude. The ADFM bit of the ADCON1 register controls the output format. Sign magnitude is left justified with the sign bit in the LSB position. Negative numbers are indicated when the sign bit is ‘1’. Two’s complement is right justified with the sign extended into the Most Significant bits. Figure 17-3 shows the two output formats. Table 17-2 shows conversion examples.
Look at the 'registers' menu on the MCC window for the ADC configuration.
 

Papabravo

Joined Feb 24, 2006
12,548
This may be difficult to convey with a written explanation, but I'll try with some examples. Sign magnitude is always left justified. Twos complement is always right justified.


Code:
Sign Magnitude
#      10 bit          Left Justified 16 bit
-2      10 0000 0010    1000 0000 1000 0000
-1      10 0000 0001    1000 0000 0100 0000
0       00 0000 0000    0000 0000 0000 0000
1       00 0000 0001    0000 0000 0100 0000

Twos complement
#       10 bit          Right Justified, sign extended to 16 bit
-2      11 1111 1110     1111 1111 1111 1110
-1      11 1111 1111     1111 1111 1111 1111
0       00 0000 0000     0000 0000 0000 0000
1       00 0000 0001     0000 0000 0000 0001

понимаешь?
 
Last edited:

Thread Starter

Владимир Чижиумов

Joined Aug 31, 2019
8
This may be difficult to convey with a written explanation, but I'll try with some examples. Sign magnitude is always left justified. Twos complement is always right justified.


Code:
Sign Magnitude
#      10 bit          Left Justified 16 bit
-2      10 0000 0010    1000 0000 1000 0000
-1      10 0000 0001    1000 0000 0100 0000
0       00 0000 0000    0000 0000 0000 0000
1       00 0000 0001    0000 0000 0100 0000

Twos complement
#       10 bit          Right Justified, sign extended to 16 bit
-2      11 1111 1110     1111 1111 1111 1110
-1      11 1111 1111     1111 1111 1111 1111
0       00 0000 0000     0000 0000 0000 0000
1       00 0000 0001     0000 0000 0000 0001

понимаешь?
Understood :)
 
Top