TouchScreen Resistive

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

gabrielcuellar
Posts: 12
Joined: Tue Apr 28, 2015 4:55 pm

TouchScreen Resistive

Tue May 03, 2016 7:57 pm

Hi guys, I try to read through AFEC0 CH0 a value converted of my touchscreen in the axis X and the axis Y in the AFEC0 CH1, this is the program, the steps to setting the conversor is wrong?
the values of my convertion is saves in the vars X_TouchScreen and Y_TouchScreen

Code: Select all

#include <asf.h>


#define VOLT_REF        (3300)
/** The maximal digital value */
#define MAX_DIGITAL_12_BIT     (4095UL)

/** AFEC sample data */
float g_afec0_sample_data, g_afec1_sample_data, X_TouchScreen, Y_TouchScreen;

/** The maximal digital value */
static uint32_t g_max_digital;

/** The delay counter value */
static uint32_t g_delay_cnt;

enum afec_channel_num ch_list[] =
{
	AFEC_CHANNEL_1,
	AFEC_CHANNEL_0,
};

/***/

struct afec_config afec_cfg;
struct afec_ch_config afec_ch_cfg;


char Secuencer_TouchScreen;
bool YConvert, XConvert;

/*********************************************************************************************************/
void Convertir_X(void)
{
	afec_channel_disable(AFEC0,AFEC_CHANNEL_1);
	afec_enable(AFEC0);
	afec_get_config_defaults(&afec_cfg);
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_enable(AFEC0);
	afec_init(AFEC0, &afec_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_0, &afec_ch_cfg);
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_0, 0x800);
	afec_set_trigger(AFEC0, AFEC_TRIG_SW);	
	afec_channel_enable(AFEC0, AFEC_CHANNEL_0);
	afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, Leer_X, 1);//La conversion se realiza mas alla del programa y por interrupcion manejo su valor convertido
	afec_start_calibration(AFEC0);
	while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
	afec_start_software_conversion(AFEC0);
}
/*********************************************************************************************************/
void Convertir_Y(void)
{
	afec_channel_disable(AFEC0,AFEC_CHANNEL_0);
	afec_enable(AFEC0);
	afec_get_config_defaults(&afec_cfg);
	afec_ch_get_config_defaults(&afec_ch_cfg);
	afec_enable(AFEC0);
	afec_init(AFEC0, &afec_cfg);
	afec_ch_set_config(AFEC0, AFEC_CHANNEL_1, &afec_ch_cfg);
	afec_channel_set_analog_offset(AFEC0, AFEC_CHANNEL_1, 0x800);
	afec_set_trigger(AFEC0, AFEC_TRIG_SW);
	
	afec_channel_enable(AFEC0, AFEC_CHANNEL_1);
	afec_set_callback(AFEC0, AFEC_INTERRUPT_DATA_READY, Leer_Y, 1);//La conversion se realiza mas alla del programa y por interrupcion manejo su valor convertido
	afec_start_calibration(AFEC0);
	while((afec_get_interrupt_status(AFEC0) & AFEC_ISR_EOCAL) != AFEC_ISR_EOCAL);
	afec_start_software_conversion(AFEC0);
}
static void Set_X(void)
{
	ioport_set_pin_mode(PIO_PD30_IDX, IOPORT_MODE_PULLDOWN);ioport_set_pin_dir(PIO_PD30_IDX, IOPORT_DIR_INPUT);
	ioport_set_pin_mode(PIO_PD31_IDX, IOPORT_MODE_PULLDOWN);ioport_set_pin_dir(PIO_PD31_IDX, IOPORT_DIR_INPUT); //ioport_set_pin_level(PIO_PD28_IDX,false);
		
	ioport_set_pin_dir(PIO_PD29_IDX, IOPORT_DIR_OUTPUT); ioport_set_pin_mode(PIO_PD29_IDX, IOPORT_MODE_PULLDOWN); ioport_set_pin_level(PIO_PD29_IDX,false);
	ioport_set_pin_dir(PIO_PD27_IDX, IOPORT_DIR_OUTPUT);ioport_set_pin_level(PIO_PD27_IDX,true);
}

/********************************************************************************************************************************************************/
static void Set_Y(void)
{
	ioport_set_pin_mode(PIO_PD29_IDX, IOPORT_MODE_PULLDOWN);ioport_set_pin_dir(PIO_PD29_IDX, IOPORT_DIR_INPUT);
	ioport_set_pin_mode(PIO_PD27_IDX, IOPORT_MODE_PULLDOWN);ioport_set_pin_dir(PIO_PD27_IDX, IOPORT_DIR_INPUT); //ioport_set_pin_level(PIO_PD28_IDX,false);	
	
	ioport_set_pin_dir(PIO_PD31_IDX, IOPORT_DIR_OUTPUT); ioport_set_pin_mode(PIO_PD31_IDX, IOPORT_MODE_PULLDOWN); ioport_set_pin_level(PIO_PD31_IDX,false);
	ioport_set_pin_dir(PIO_PD30_IDX, IOPORT_DIR_OUTPUT);ioport_set_pin_level(PIO_PD30_IDX,true);
}

/********************************************************************************************************************************************************/
static void Leer_X(void)
{
	X_TouchScreen = afec_channel_get_value(AFEC0, AFEC_CHANNEL_0); //g_afec0_sample_data
	afec_disable_interrupt(AFEC0, AFEC_INTERRUPT_ALL);
	XConvert = true;
}

/********************************************************************************************************************************************************/
static void Leer_Y(void)
{
	Y_TouchScreen = afec_channel_get_value(AFEC0, AFEC_CHANNEL_1); //g_afec1_sample_data
	afec_disable_interrupt(AFEC0, AFEC_INTERRUPT_ALL);
	YConvert = true;
}

/********************************************************************************************************************************************************/
void LeerTouch(void)
{
	switch(Secuencer_TouchScreen)
	{
		case 0: Set_X();
				Convertir_X();
				Secuencer_TouchScreen++;
		break;
		case 1:	if(XConvert)
				{
					//afec_disable_interrupt(AFEC0, AFEC_INTERRUPT_ALL);
					//afec_get_config_defaults(&afec_cfg);
					//afec_ch_get_config_defaults(&afec_ch_cfg);
					Secuencer_TouchScreen++;
				}
		break;
		case 2: Set_Y();
				Convertir_Y();
				Secuencer_TouchScreen++;
		break;
		case 3: if(YConvert)
				{
					//afec_disable_interrupt(AFEC0, AFEC_INTERRUPT_ALL);
					//afec_get_config_defaults(&afec_cfg);
					//afec_ch_get_config_defaults(&afec_ch_cfg);
					Secuencer_TouchScreen++;
				}
		break;
		case 4: Procesar_Touch();
				Secuencer_TouchScreen = 0;
		break;
	}
}

/********************************************************************************************************************************************************/

int main(void)
{
	sysclk_init();
	board_init();


	while(1)
	{
		LeerTouch();
	}
}
gabrielcuellar
Posts: 12
Joined: Tue Apr 28, 2015 4:55 pm

Re: TouchScreen Resistive

Mon May 09, 2016 4:07 pm

I could solve this some one have the same problem?

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest