# ADC Configuration in mplab MCC

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

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

• 4.9 KB Views: 13

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

Joined Aug 31, 2019
8
sign magnitude*

#### nsaspook

Joined Aug 27, 2009
7,585
Exactly which PIC are you trying to configure.

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

Joined Aug 31, 2019
8
Exactly which PIC are you trying to configure.
- MPLab X IDE v5.25;
- XC 8 v2.10
- PIC16F1788;
- PICkit v3.

#### nsaspook

Joined Aug 27, 2009
7,585

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
14,378
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:

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

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

#### Papabravo

Joined Feb 24, 2006
14,378