HVI (ADC) measure

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HVI (ADC) measure

Jump to solution
1,553 Views
aaronlee
Contributor V

Hi,

I use HVI0 to measure 0~30VDC. But I can not measure 22.2~30V.

The ADC result:

8bit ADC

5V ==> 43

10V ==> 86

15V ==> 129

20V ==> 172

22.1V ==> 190

25V ==> 190 (I got wrong value, It should be around 215)

30V ==> 190 (I got wrong value, It should be around 255)

10bit ADC

5V ==> 172

10V ==> 343

15V ==> 515

20V ==> 687

22.2V ==> 762

25V ==> 762 (I got wrong value, It should be around 859)

30V ==> 762 (I got wrong value, It should be around 1023)

 

What problem in my code?

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "ADC.h"

#define HVI0 0x0D //Internal_5 - High voltage input port L0

unsigned int ADC_Vin_VALUE=0;

void main(void) {
   unsigned int result=0;
   unsigned char digit[4];

   DIENL_DIENL0= 0; // PL0: DISABLE Digital Input
   PTAENL_PTAENL0=1; // PL0: ENABLE ADC
   PTADIRL_PTADIRL0= 0; // PL0: DISABLE Direct-Mode
   PIRL_PIRL0=0; // PL0: H_HVI (Ratio 6:1)

   ADC_init();

   for(;;){
      ADC_Vin_VALUE = ADC_read(HVI0);
      result = ADC_Vin_VALUE;

      digit[0] = result % 10;
      digit[1] = ((result - digit[0]) / 10) % 10;
      digit[2] = ((result - digit[1]*10 - digit[0]) /100) % 10;
      digit[3] = ((result - digit[2]*100 - digit[1]*10 - digit[0]) /1000) % 10;

   }
}

/*
* ADC.c
*
* Created on: Dec 1, 2015
* Author: B55840
*/

#include "derivative.h"
#include "ADC.h"
#include "GPIO.h"

/* ADC list directions value*/

volatile unsigned char adc0_cmdlist[1][4] = {0xC0,0xD0,0xA0,0x00};
volatile unsigned int adc0_results[1];

void ADC_init(void){
   ADC0CTL_0 = 0x0D; /*Dual Access mode and trigger mode selected */
   ADC0CTL_1 = 0x00; /* Single command and result value list */
   ADC0TIM = 0x0F; /*No prescale selected */
   ADC0FMT = 0x80; /* Left justified and 8 bit resolution */
// ADC0FMT = 0x82; /* Left justified and 10 bit resolution */
// ADC0FMT = 0x84; /* Left justified and 12 bit resolution */

/* ADC0 Command & Result Base Pointers */
   ADC0CBP_0 = (unsigned char)(((long)adc0_cmdlist) >> 16);
   ADC0CBP_1 = (unsigned char)(((long)adc0_cmdlist) >> 8);
   ADC0CBP_2 = (unsigned char)((long)adc0_cmdlist);

// ADC0 Result Base Pointer
   ADC0RBP_0 = (unsigned char)(((long)adc0_results) >> 16);
   ADC0RBP_1 = (unsigned char)(((long)adc0_results) >> 8);
   ADC0RBP_2 = (unsigned char)((long)adc0_results);

   ADC0CTL_0_ADC_EN= 1; /*Enables the ADC */
}


unsigned int ADC_read(unsigned int channel){
   adc0_cmdlist[0][1] = 0xC0|channel;
   ADC0FLWCTL_RSTA = 1; // Restart Event
   while(0x00 == ADC0CONIF){} //wait until conversion is complete
   ADC0CONIF = ADC0CONIF;//clear flag
   return adc0_results[0];
}

Labels (1)
Tags (3)
1 Solution
885 Views
aaronlee
Contributor V

Dear Daniel,

The HVI circuit has a standoff voltage. So, the HVI cannot reach the full scale of the ADC.

This answer is important for me. I get a deeper understanding of the HVI. Thank you.

I will use ratio H_HVI=6 to measure my signal (0~10V). And use 12-bit to increase resolution.

Now, I understand the Num.26 of Table G-1

pastedImage_6.png

Best Regards,

Aaron

View solution in original post

0 Kudos
4 Replies
885 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

 

Regarding code, there is an example on the community:

High Voltage Input (HVI) SW examples for MagniV devices.

So, you can try the code and see if you get same result.

 

I have noticed that your cmdlist and result list is not aligned __attribute__ ((aligned (4))) which should be. And you comment that the result is “left justified” but 0x8x stands for “right justified”.

 

Make sure you use a 10k serial resistor on HVI pin.

Regards,

Daniel

0 Kudos
885 Views
aaronlee
Contributor V

Hi,

Thanks a lot.

I make sure 10k serial resistor on HVI pin.

I modify some code as follow. The result of ADC is the same.

volatile unsigned char adc0_cmdlist[1][4] __attribute__ ((aligned (4))) = {0xC0,0xD0,0xA0,0x00};
volatile unsigned int adc0_results[1] __attribute__ ((aligned (4)));

ADC0FMT = 0x80; /* Right justified and 8 bit resolution */

I use the High Voltage Input (HVI) SW examples for MagniV devices. The result of ADC is the same, too.

I think the voltage above 22V has been clipped. Why?

I try to change ratio=2.

PIRL_PIRL0=1; // PL0: L_HVI (Ratio 2:1)

The voltage above 7.8V has been clipped, too.

How can I do?

Best Regards,

Aaron

0 Kudos
885 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Aaron,

 

I was wrong in my previous answer. Sorry for that. Your measurement is correct.

The HVI circuit has a standoff voltage. So, the HVI cannot reach the full scale of the ADC.

 

Regards,

Daniel

886 Views
aaronlee
Contributor V

Dear Daniel,

The HVI circuit has a standoff voltage. So, the HVI cannot reach the full scale of the ADC.

This answer is important for me. I get a deeper understanding of the HVI. Thank you.

I will use ratio H_HVI=6 to measure my signal (0~10V). And use 12-bit to increase resolution.

Now, I understand the Num.26 of Table G-1

pastedImage_6.png

Best Regards,

Aaron

0 Kudos