[SOLVED] ADC reading on RENESAS microcontroller

Status
Not open for further replies.

haripriyasnr

Newbie level 2
Joined
Jun 3, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
13
Hi,
I'm using renesas rl78/g14 microcontroller. Not getting correct values when im reading dc values through ADC. Floating values are coming. I just wrote simple program for reading ADC. ADC reading in continuous scan mode

MAIN PROGRAM
Code:
#include "r_cg_macrodriver.h"
#include "r_cg_cgc.h"
#include "r_cg_adc.h"
#include "r_cg_userdefine.h"

void R_MAIN_UserInit(void);

void main(void)
{
    R_MAIN_UserInit();  
    R_ADC_Start();     

    while (1U)
    {        
	;    	
     }
  }

void R_MAIN_UserInit(void)
{
       EI();    
} 

[B][U]ADC PROGRAM[/U][/B]
#include "r_cg_macrodriver.h"
#include "r_cg_adc.h"
#include "r_cg_userdefine.h"

unsigned char channel=0;
unsigned int adc_arr[4],ADC_data0,ADC_data1,ADC_data2,ADC_data3;

__interrupt static void r_adc_interrupt(void)
{
    ADCS 		= 0U;  	//disable AD conversion 
    ADMK 		= 1U;  	//disable INTAD interrupt 
    ADIF 		= 0U;  	//clear INTAD interrupt flag
    
	if (channel == 0)
	{
		ADC_data0	= ADCR >> 6;
		channel		= 1;
		ADS 		= channel;
		ADMK 		= 0U;  	//enable INTAD interrupt 
	    	ADCS 		= 1U;  	//enable AD conversion 
		
	}
	else if (channel == 1)
	{
		ADC_data1	= ADCR >> 6;
		channel		= 2;
		ADS 		= channel;
		ADMK 		= 0U;  	//enable INTAD interrupt 
	    	ADCS 		= 1U;  	//enable AD conversion
	}
	else if (channel == 2)
	{
		ADC_data2	= ADCR >> 6;
		channel		= 3;
		ADS 		= channel;
		ADMK 		= 0U;  	//enable INTAD interrupt 
	    	ADCS 		= 1U;  	//enable AD conversion
	}
	else if (channel == 3)
	{
		ADC_data3	= ADCR >> 6;
		channel		= 0;
		ADS 		= channel;
		ADMK 		= 0U;  	//enable INTAD interrupt 
	    	ADCS 		= 1U;  	//enable AD conversion
	}
}
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…