Author Topic: Padauk Micro ADC  (Read 1059 times)

0 Members and 1 Guest are viewing this topic.

Offline epicodeTopic starter

  • Newbie
  • Posts: 6
  • Country: il
Padauk Micro ADC
« on: February 01, 2020, 02:50:54 pm »
Hello, I am trying to use a padauk PMS134 microcontroller to sample a voltage using the ADC and display it on a 7 segment display which I was able to control without any problem but I followed the instructions in the datasheet  on using the ADC (http://www.padauk.com.tw/upload/doc/PMS133,%20PMS134_datasheet_v103_EN_20181113.pdf - page 64-67) and it seems you get two bytes result and I could not find a way to convert that into a number so I can multiply it when using a voltage divider or get the individual digits to control the 7 segment display.
I am using padauk mini-c and the official framework and I've checked the documentation and could not find anything so if anyone has any experience with the framework and has any idea how to use those to bytes to control a 7 segment display your help will be very appreciated  :)
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6349
  • Country: fi
    • My home page and email address
Re: Padauk Micro ADC
« Reply #1 on: February 02, 2020, 02:37:51 pm »
I don't have a Padauk, but let me try to help anyway.

At 12 bit resolution, ADCRH will contain the four high bits of the result (value 0..15). ADCRL will contain the low 8 bits of the result (value 0..255).  So, logically, the 12-bit ADC sample value (0..4095) is ADCRH<<4 + ADCRL.

The way the Padauk example does it,
Code: [Select]
WORD sample;  // 16-bit result variable

AD_START = 1;  // Start ADC conversion
while (!AD_DONE) NULL; // Wait for conversion to complete
sample$1 = ADCRH; // High byte of conversion result
sample$0 = ADCRL;  // Low byte of conversion result
is that it stores the high byte of the conversion result to the high byte of the sample word; then the low byte. (The $n suffix selects the byte in a multibyte variable.)

Let's say you want to convert this 12-bit value to four individual digits, 0..9.  The simplest option is to use a subtraction loop:
Code: [Select]
byte thousands, hundreds, tens, ones;
word value;

value = sample;
thousands = 0;
hundreds = 0;
tens = 0;
ones = 0;
while (value >= 1000) {
    thousands++;
    value -= 1000;
}
while (value >= 100) {
    hundreds++;
    value -= 100;
}
while (value >= 10) {
    tens++;
    value -= 10;
}
ones = value;
This, however, produces leading zeroes.  To take care of those, you use something like this:
Code: [Select]
if (sample >= 1000) {
    // Display 'thousands' digit
} else {
    // Clear 'thousands' digit
}
if (sample >= 100) {
    // Display 'hundreds' digit
} else {
    // Clear 'hundreds' digit
}
if (sample >= 10) {
    // Display 'tens' digit
} else {
    // Clear 'tens' digit
}
// Display 'ones' digit
or, if you control the display from least significant digit upwards,
Code: [Select]
// Display 'ones' digit
if (sample >= 10) {
    // Display 'tens' digit
    if (sample >= 100) {
        // Display 'hundreds' digit
        if (sample >= 1000) {
            // Display 'thousands' digit
        } else {
            // Clear one digit (thousands)
        }
    } else {
        // Clear two digits (hundreds and thousands)
    }
} else {
    // Clear three digits (tens, hundreds, and thousands)
}
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf