This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ADC Continuous read

hi,I have to question about ADC,please help me ,thank you very much!

I joined on the ADC input pin an adjustable resistance, to change the voltage value.Why change the voltage value of the ADC to read out the value of the without change

The code is as follows, please help me to find out the problem


main(){

	timer1_init();
	ppi_init();
	peripheral_configure();		
	nrf_adc_init(ADC_RES_8bit,ADC_INPUT_AIN0_P10,ADC_INT_DISABLED);						  
                     
                            vbat = nrf_adc_read1();
							NRF_TIMER1->TASKS_START = 1;
							while(1)
								{
								 NRF_TIMER1->TASKS_COUNT         = 1;
						  		NRF_TIMER1->TASKS_CAPTURE[0]    = 1;
									
								if(( x = nrf_adc_read()) > 1.2*vbat)
							{		
									nrf_gpio_pin_clear(dynamo_power);
									Invert();							
									nrf_delay_ms(1000);
									nrf_gpio_pin_clear(dynamo_power);
									break;

				
						}
					

}
}

#include "nrf_adc.h" #define AIN0 1


void nrf_adc_init(ADC_Res_t ADC_res, ADC_input_selection_t ADC_input_selection, ADC_interrupt_enabled_t ADC_interrupt_enabled) { if(ADC_input_selection <= 7) { NRF_ADC->CONFIG = ADC_res << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos | (1 << ADC_input_selection) << ADC_CONFIG_PSEL_Pos; NRF_ADC->ENABLE = 1;
if(ADC_interrupt_enabled) { NRF_ADC->INTENSET = ADC_INTENSET_END_Msk; NVIC_SetPriority(ADC_IRQn, 1); NVIC_EnableIRQ(ADC_IRQn); } } }

void nrf_adc_init_vbat(void) { NRF_ADC->CONFIG = ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos | ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos | ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos | ADC_CONFIG_PSEL_Disabled << ADC_CONFIG_PSEL_Pos;
NRF_ADC->ENABLE = 1; }

extern uint32_t nrf_adc_read(void) { uint32_t adc_data; // NRF_ADC->TASKS_START = 1; while(NRF_ADC->EVENTS_END == 0); NRF_ADC->EVENTS_END = 0; adc_data = NRF_ADC->RESULT;

return adc_data; }

float nrf_adc_read_vbat_f(void) { return (float)nrf_adc_read() * 3.0f * 1.2f / 1024.0f; }

uint32_t nrf_adc_read_vbat_mv(void) { // The non-optimized math is: (ADC / 1024) * 3 * 1.2 * 1000 return nrf_adc_read() * (3 * 6 * 1000 / 5) / 1024; }

extern uint32_t nrf_adc_read1(void) { uint32_t adc_data; NRF_ADC->TASKS_START = 1; while(NRF_ADC->EVENTS_END == 0); NRF_ADC->EVENTS_END = 0; adc_data = NRF_ADC->RESULT;

return adc_data; } void ppi_init(void){ NRF_PPI->CH[0].EEP = (uint32_t)(&NRF_TIMER1->EVENTS_COMPARE[0]); NRF_PPI->CH[0].TEP = (uint32_t)(&NRF_ADC->TASKS_START);

	NRF_PPI->CHEN = PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos;

}

void timer1_init(void) { // Configure Timer 1 to overflow every 2 seconds. // SysClk = 16 Mhz // BITMODE = 16 bit // PRESCALER = 9 // The overflow occurs every 0xFFFF/(SysClk/2^PRESCALER). // = 65535/31250 = 2.097 sec NRF_TIMER1->BITMODE = (TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos); NRF_TIMER1->PRESCALER = 9; NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);

// Trigger interrupt for compare[0] event.
NRF_TIMER1->MODE        = TIMER_MODE_MODE_Timer;
NRF_TIMER1->CC[0]       = 1;  // Match at even number of seconds

}

I'm sorry, because of the format problem, let you look very pain!

Parents Reply Children
Related