o proximo passo é a implementação de um canal AD. Este eu consegui fazer sem qualquer tipo de ajuda externa. apenas lendo os User guides e exemplos da Freescale.
Realmente o jeitão dele se repete.
Isso não garante que as rotinas estejam perfeitas e otimizadas. Mas ja é a ponta do Iceberg.
Arquivo IO.C
- Código: Selecionar todos
// -- Variaveis Globais
static FILE_PTR adc = NULL;
static FILE_PTR adc_channel = NULL;
// -- definições Globais
const ADC_INIT_STRUCT adc_init =
{
ADC_RESOLUTION_8BIT, /* resolution */
};
/* Logical channel #1 init struct */
const ADC_INIT_CHANNEL_STRUCT adc_channel_parameters =
{
POT_1, /* physical ADC channel */
ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_NOW,
10, /* number of samples in one run sequence */
0, /* time offset from trigger point in us */
50000, /* period in us (= 0.6 sec) */
0x10000, /* scale range of result (not used now) */
1, /* circular buffer size (sample count) */
ADC_TRIGGER_1, /* logical trigger ID that starts this ADC channel */
};
// -- Função para inicializar ADC
boolean InicializaIO(void)
{
// -- Configuração do ADC
ADC_INIT_CHANNEL_STRUCT adc_chl = adc_channel_parameters;
adc = fopen("adc:", (const char*)&adc_init);
if (NULL == adc) {
printf("ADC device open failed\n");
_task_block();
}
adc_channel = fopen("adc:3",(const char*)&adc_chl);
if (NULL == adc_channel) {
printf("adc:POT channel open failed\n");
_task_block();
}
}
// -- Função para retornar Valor do ADC
/*
* Read in ADC value on the channel given
*/
int_32 ReadADC(void) {
ADC_RESULT_STRUCT data;
int_32 val;
read(adc_channel, &data, sizeof(data) ) ;
val = data.result;
return val;
}
Arquivo TASK.C
- Código: Selecionar todos
void Adc_task(uint_32 initial_data)
{
int_32 ValorADC = 0;
printf("\n Adc task \n");
while (TRUE)
{
ValorADC = ReadADC();
if(ValorADC > 240)
{
SetOutput(3,1);
}
else
{
SetOutput(3,0);
}
_time_delay(100);
}
}
Tudo funciona Direitinho.