示例#1
0
int main(void)
{
	int read;
	float input_voltage, temperature;
	
	UART_INIT();					// UART 통신 초기화
	ADC_INIT(1);					// AD 변환기 초기화
	
	while(1)
	{
		// 온도 센서의 출력 전압을 ADC를 거쳐 읽는다.
		read = read_ADC();
		
		// 0에서 1023 사이의 값을 0V에서 5V 사이 값으로 변환한다.
		input_voltage = read * 5.0 / 1023.0;
		
		// 10mV에 1℃이므로 100을 곱해서 현재 온도를 얻는다.
		temperature = input_voltage * 100.0;
		
		UART_print16bitNumber((int)temperature);	// 정수값으로 출력
		UART_transmit('\n');				// 줄바꿈

		_delay_ms(1000);				// 1초에 한 번 출력
	}
}
示例#2
0
文件: main.c 项目: adamselevan/dicio
void Task1()
{
uint16_t cnt;
int8_t fd,val,chan;
uint16_t sample;


   printf( "Task1 PID=%d\r\n",nrk_get_pid());

  nrk_gpio_direction(NRK_BUTTON, NRK_PIN_INPUT);
  nrk_gpio_direction(NRK_DEBUG_0, NRK_PIN_OUTPUT);

  nrk_led_set(RED_LED);
  do{} while(nrk_gpio_get(NRK_BUTTON)==1);
  nrk_led_clr(RED_LED);
  nrk_led_set(GREEN_LED);

   // Initialize values here
   ADC_INIT ();
   ADC_ENABLE ();
   ADC_SET_CHANNEL (2);

  while(1) {
	ADC_SAMPLE_SINGLE();
	ADC_GET_SAMPLE_10(sample);
  	// Send sync byte
  	putchar(0x55);
	putchar(sample>>8);
	putchar(sample&0xff);
  	}
}
示例#3
0
void power_init ()
{
  ADC_INIT ();
  ADC_ENABLE ();
  ADC_VREF_VCC();
  nrk_timer_int_configure( NRK_APP_TIMER_0, 1, 7373, calc_power);
  ticks=0;
  cycle_state=CYCLE_HIGH;
  //cycle_state_last=CYCLE_UNKNOWN;
  cycle_cnt=0;
  cycle_avg=0;
  cycle_started=0;
  c1_center=496;
  v_p2p_low=2000;
  v_p2p_high=0;
  c_p2p_low=2000;
  c_p2p_high=0;
  c_p2p_low2=2000;
  c_p2p_high2=0;
  rms_current=0;
  rms_current2=0;
  rms_voltage=0;
  energy_total2=0;
  energy_total=0;
  energy_cycle2=0;
  energy_cycle=0;
  cummulative_energy2=0;
  cummulative_energy=0;
  total_secs=0;
  v_last=VOLTAGE_LOW_THRESHOLD+10;
  triggered=0;

  nrk_gpio_direction(NRK_DEBUG_2, NRK_PIN_OUTPUT);

  //startup_sock_state=nrk_eeprom_read_byte(0x100);
  //if((startup_sock_state&0x01)==0x01)
  //      {
                nrk_timer_int_start(NRK_APP_TIMER_0);
                power_mon_enable();
                socket_0_enable();
                socket_0_active=1;
  //      }
  //else {
  //socket_0_active=0;
  //power_mon_disable();
  //              nrk_kprintf( PSTR("Socket inactive\r\n"));
  //}
  //if((startup_sock_state&0x02)==0x02)
  //      {
                socket_1_enable();
                socket_1_active=1;
  //      }
  // else {
  // socket_1_active=0;
  // }



}
示例#4
0
// ****************************************************************************
// Fumctions for init-start-stop-read
// ****************************************************************************
void BSP_adc_init (void) 
{
	// Init all pins, configure speed, reference etc.
	ADC_INIT();
                 
    adc_raw8 = 0;
    adc_raw_minor_bit = 0;
}
示例#5
0
void init_adc()
{
// Initialize values here
    DDRA = 0x80;
    ADC_INIT ();
    ADC_ENABLE ();
    ADC_SET_CHANNEL (0);
}
示例#6
0
double RTD::tempC() // main function to read the RTD temperature in degree Celsius
{
	MUX_SELECT(_nChannel);
	ADC_INIT();
	long adcRaw = ADC_READ();
	double rtdTempC = OHM2CELSIUS(ADC_2_mV(adcRaw));
	return rtdTempC;
}
//串口打印变阻器模拟信号数值
void W1_ADC(int *read_xpdata){
	ADC_INIT(); //初始化AD控制寄存器
    /*****串口打印ADC数据函数****/
    while(rADCCON & 0x1);                //因为成功启动A/D转换后,该位会
                                          //自动清零,因此在这里检查ADC是否真正启动
    while(!(rADCCON & (1<<15)));            //使用查询方式等待ADC转换结束
    *read_xpdata=(int)(rADCDAT0&0x3ff);   //读取ADCDAT0后十位
    Uart_Printf("\n HELLO ADC# W1值为: %04d ",*read_xpdata);//串口输出ADCDAT0后十位值
    Delay(500);
	}
示例#8
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{	
	unsigned short int analogval;
	unsigned char *analoghi, *analoglow;
	float VREF = 3; //Voltage reference
	float result; // ADC voltage result
	short int result_high = 0;
	short int result_low = 4095;
	char samples = 0;
	short int accum[16] = {0}; // Still compute the average
	char i;
	unsigned long int sum = 0;
	unsigned int avg;
	float result_dec1; // Need 2 variables to hold the decimal value to prevent overflow
	float result_dec2;
	analoglow = (char *) &analogval;
	analoghi = analoglow + 1;

	WDTCN = 0xDE; // Disable the watchdog timer
	WDTCN = 0xAD;
	
	PORT_INIT(); // Initialize the Crossbar and GPIO
	SYSCLK_INIT(); // Initialize the oscillator
	UART0_INIT(); // Initialize UART0
	ADC_INIT(); // Initialize ADC0
	INTERRUPT_INIT();
	DAC_INIT();

	
	
	while(1)
	{
		//dig_val = dig_val + 50; // Generate the sawtooth
		SFRPAGE = ADC0_PAGE;
		AD0INT = 0; // Clear the "conversion done" flag
		AD0BUSY = 1; // Start A/D Conversion
		while (AD0INT == 0); // Wait for the conversion to finish
		*analoglow = ADC0L; // Read the low byte
		*analoghi = ADC0H; // Read the high byte
		
		SFRPAGE = DAC0_PAGE; // Output the digital value through the DAC
		DAC0L = analogval << 0; //digval;
		DAC0H = analogval >> 8; //digval >> 8;
		
		SFRPAGE = UART0_PAGE;
		//result = analogval*2.4/(float)4095;
	
		// Compute the average
		
		//result_dec1 = (1000*result-1000*(int)result);
		//result_dec2 = (1000*(result_dec1-(int)result_dec1));
		// Erase screen and move cursor to home position
		//printf("Voltage reading: %d.%03d%03d\n\r", (int)result, (int)result_dec1, (int)result_dec2);
	}
}
示例#9
0
int main(void)
{
	int read;
	ADC_INIT(0); // AD 변환기 초기화
	INIT_TIMER1();
	while(1)
	{
		read = read_ADC(); // 가변저항 값 읽기
		OCR1A = PULSE_MIN + (int)(3.48 * read);
		_delay_ms(ROTATION_DELAY);
	}
}
示例#10
0
int main(void)
{
	int read, actualVCC;
	ADC_INIT(0x0E); // 15번 채널 선택
	UART_INIT(); // UART 통신 초기화
	while(1)
	{
		read = read_ADC(); // 15번 채널 값 읽기
		actualVCC = 1125300L / read; // mV 단위로 변환
		UART_print16bitNumber(actualVCC); // AVCC 값 출력
		UART_printString("\n"); // 줄 바꿈
		_delay_ms(1000); // 1초에 한 번 읽음
	}
}
示例#11
0
文件: audio.c 项目: ESE519/ISA100.11a
void
audio_init()
{
uint8_t i;
// Initialize values here
  DDRA = 0x80;
  ADC_INIT ();
  ADC_ENABLE ();
  ADC_SET_CHANNEL (MIC_PIN);
  audio_index=0;  // set index to 0
  for(i=0; i<AUDIO_BUFS; i++ )
  {
	audio_cnt[i]=0;  // clear buffer counts
  }
  printf( "Audio init\r" );
}
示例#12
0
int main(void)
{
	int value;
	uint8_t on_off;
	
	ADC_INIT(0);
	PORT_INIT();
	
	while(1)
	{
		value = read_ADC() >> 7;
		
		on_off = 0;
		for(int i = 0; i <= value; i++){
			on_off |= (0x01 << i);
		}
		PORTD = on_off;
	}
}
示例#13
0
/**
  * @brief  Main function. Executes all initialization and terminate its thread.
  * @param  None
  * @retval None
  */
int main(void)
{	
  ///////////////////////////////////////////////////////////////////////////////////////////
  /* Configure the MPU attributes as Write Through */
  MPU_Config();
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
	// initialize CMSIS-RTOS
  osKernelInitialize();
	///////////////////////////////////////////////////////////////////////////////////////////
	// Hardware initialize
  if( HAL_Init() != HAL_OK)
		Error_Handler();
	if( ConfigureDMA(&g_DmaHandle, &g_AdcHandle) != HAL_OK)
		Error_Handler();
	if( ADC_INIT(&g_AdcHandle) != HAL_OK)
		Error_Handler();
	
	BSP_SDRAM_Init();
	Touch_Initialize();
	///////////////////////////////////////////////////////////////////////////////////////////
  /* Configure the System clock to have a frequency of 216 MHz */
  SystemClock_Config();
	// Thread initialization
	Init_TH_GUI();
	Init_TH_Touch();
	// RTOS Start Kernel
  osKernelStart();                      // start thread execution 
	// Get Main Thread ID
	Main_thID = osThreadGetId();
	///////////////////////////////////////////////////////////////////////////////////////////
	// Start data acquire
	HAL_ADC_Start_DMA(&g_AdcHandle, values, ADC_BUFFER_LENGTH);
	///////////////////////////////////////////////////////////////////////////////////////////
	// Terminate main thread
	osThreadTerminate(Main_thID);
	/* Infinite loop */
  while (1) {  }
}
示例#14
0
//------------------------------------------------------------------------------------
// MAIN Routine
//------------------------------------------------------------------------------------
void main(void)
{
	unsigned char adcValH[3];
	unsigned char adcValL[3];
	unsigned int result;
	unsigned short int analogval;
	unsigned char analoghi, analoglow;
	float VREF = 3;

	WDTCN = 0xDE; // Disable the watchdog timer
	WDTCN = 0xAD;
	
	PORT_INIT(); // Initialize the Crossbar and GPIO
	SYSCLK_INIT(); // Initialize the oscillator
	ADC_INIT(); // Initialize ADC0
	DAC_INIT();
	MAC_INIT();

	adcValH[2] = adcValH[1] = adcValL[2] = adcValL[1] = 0;
	result = 0;
	
	while(1)
	{
		SFRPAGE = ADC0_PAGE;
		AD0INT = 0; // Clear the "conversion done" flag
		AD0BUSY = 1; // Start A/D Conversion
		while (AD0INT == 0); // Wait for the conversion to finish
		analoglow = ADC0L; // Read the low byte
		analoghi = ADC0H; // Read the high byte
		analogval = analoghi<<8 | analoglow;

		// Update the variables in the filter equation
		adcValH[2] = adcValH[1]; // x(k-2) high byte
		adcValH[1] = adcValH[0]; // x(k-1) high byte
		adcValL[2] = adcValL[1]; // x(k-2) low byte
		adcValL[1] = adcValL[0]; // x(k-1) low byte

		adcValH[0] = analoghi; // x(k) high and low bytes
		adcValL[0] = analoglow;

		SFRPAGE = MAC0_PAGE;
		MAC0CF |= 0x08; // Clear MAC

		// Load the MAC with the correct values and compute the filter equation
		MAC0AH = 0x28;
		MAC0AL = 0x00;
		MAC0BH = adcValH[0];
		MAC0BL = adcValL[0];

		MAC0BH = adcValH[2];
		MAC0BL = adcValL[2];

		MAC0AH = 0x1E;
		MAC0AL = 0xC4;
		MAC0BH = adcValH[1];
		MAC0BL = adcValL[1];

		MAC0AH = 0x26;
		MAC0AL = 0x00;

		SFRPAGE = MAC0_PAGE; // Delay with any dummy command

		result = (int)MAC0RNDH<<8 | MAC0RNDL; // Read the result from the rounding engine

		SFRPAGE = DAC0_PAGE; // Output the result through the DAC
		DAC0L = result;
		DAC0H = result>>8;
	}
}