我想持续记录analog input 的值,每次记录相隔8ms,然后加上时间,透过蓝牙传出去。但
1.我不知道怎么加上时间
2.在另外一个电池电压管理的例子中,如果我想alarm在电压低于2.5的时候提醒我,应该怎么改
3.如果用蓝牙的话,是不是要有TASK-UART Emulator
我写了以下的代码:
持续记录
//Create variable int U16 int; //Enable the input of INT gpioEnableInputBuf(AUXIO_I_INT); //Input the INT's value into int gpioGetInputValue(AUXIO_I_INT; int); if (int == 1){ //Set DSET to be high gpioSetOutput(AUXIO_XD_DSET); // Select ADC input adcSelectGpioInput(AUXIO_A_DOUT); // Enable the ADC;reference voltage is 4.7V and the sampling time is 2.7us; Timer trigger adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_AUX_TIMER0); // Start ADC trigger timer at 12.5Hz (8ms) timer0Start(TIMER0_MODE_PERIODICAL, 24000,3); // Loop until the application sets the exit flag while (state.exit == 0) { // Wait for the next ADC sample and store it U16 n = state.head; adcReadFifo(output.pSamples[n]); // Update the head index utilIncrAndWrap(n, BUFFER_SIZE; state.head); // If ALERT interrupt generation is enabled if (state.alertEnabled == 1){ // Calculate the number of samples currently stored S16 count = state.head - state.tail; if (count < 0) { count += BUFFER_SIZE; } // If above the configured threshold ... if (count >= cfg.alertThr){ // Generate ALERT interrupt fwGenQuickAlertInterrupt(); // Disable further generation to avoid unnecessary interrupts. It will be reenabled // by the application after handling the ALERT interrupt. state.alertEnabled = 0; } if (int==0){ //clear the output on Dset gpioClearOutput(AUXIO_XD_DSET); // Generate ALERT interrupt fwGenQuickAlertInterrupt(); // Disable further generation to avoid unnecessary interrupts. It will be reenabled // by the application after handling the ALERT interrupt. state.alertEnabled = 0; } } } // Stop the ADC trigger and flush the ADC FIFO timer0Stop(); adcFlushFifo(); // Disable the ADC adcDisable(); }
电池电压
// Select VDDS as input adcSelectIntInput(ADC_INPUT_VDDS); // Enable the ADC adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL); // Measure and store the result adcGenManualTrigger(); U16 adcValue; adcReadFifo(adcValue); output.adcValue = adcValue; // Disable the ADC adcDisable(); // Check whether to notify the application (every time when below, once when returning above) if (cfg.alarmEnable == 1) { if (adcValue < cfg.alarmThr) { output.alarm = 1; fwGenAlertInterrupt(); } else { if (output.alarm == 1) { output.alarm = 0; fwGenAlertInterrupt(); } } } // Schedule the next execution fwScheduleTask(5);