haripriyasnr
Newbie level 2
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
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: