主题中讨论的其他器件:CC1350、 ENERGYTRACE、
您好!
我正在进行一个项目、每8小时通过射频发送一次 ADC 测量。 为此,在数据未发送的情况下,我使用 Task_sleep()在8小时内使电路板进入待机状态。 简单地说、"main_tirtos.c"(附加的第一个代码)创建了一个线程、用于获取 ADC 测量值并发送它。 该线程位于"rfPacketTx.c"(附加的第二个代码)中、其中我在 while (1)的文件末尾使用了 Task_sleep()。
/* * ======== main_tirtos.c ======== */ #include <stdint.h> /* POSIX Header files */ #include <pthread.h> /* RTOS header files */ #include <ti/sysbios/BIOS.h> /* Example/Board Header files */ #include "Board.h" extern void *mainThread(void *arg0); /* Stack size in bytes */ #define THREADSTACKSIZE 1024 /* * ======== main ======== */ int main(void) { pthread_t thread; pthread_attr_t attrs; struct sched_param priParam; int retc; int detachState; /* Call driver init functions */ Board_initGeneral(); /* Set priority and stack size attributes */ pthread_attr_init(&attrs); priParam.sched_priority = 1; detachState = PTHREAD_CREATE_DETACHED; retc = pthread_attr_setdetachstate(&attrs, detachState); if (retc != 0) { /* pthread_attr_setdetachstate() failed */ while (1); } pthread_attr_setschedparam(&attrs, &priParam); retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE); if (retc != 0) { /* pthread_attr_setstacksize() failed */ while (1); } retc = pthread_create(&thread, &attrs, mainThread, NULL); if (retc != 0) { /* pthread_create() failed */ while (1); } BIOS_start(); return (0); }
/***** Includes *****/ /* Standard C Libraries */ #include <stdlib.h> #include <unistd.h> /* TI Drivers */ #include <ti/drivers/rf/RF.h> #include <ti/drivers/PIN.h> #include <ti/drivers/pin/PINCC26XX.h> #include <math.h> #include <smartrf_settings/smartrf_settings.h> #include <time.h> #include <ti/sysbios/hal/Seconds.h> #include <ti/drivers/ADCBuf.h> #include <ti/drivers/ADC.h> //#include <ti/devices/cc13x0/driverlib/aon_ioc.h> //#include <ti/sysbios/family/arm/cc26xx/Timer.h> #include <ti/dpl/PowerCC26XX_tirtos.c> #include <ti/drivers/Power.h> #include <ti/drivers/power/PowerCC26XX.h> #include <ti/devices/cc13x0/driverlib/aon_batmon.h> /* Driverlib Header files */ #include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h) /* Board Header files */ #include "Board.h" #include <ti/drivers/GPIO.h> /***** Defines *****/ #define ADCBUFFERSIZE (28) #define ADC_SAMPLE_COUNT (10) #define THREADSTACKSIZE (768) #define ID0 0 #define ID1 1 /* Do power measurement */ //#define POWER_MEASUREMENT /* Packet TX Configuration */ #define PAYLOAD_LENGTH 9 #define NORM_VALUES 10 #ifdef POWER_MEASUREMENT #define PACKET_INTERVAL 5 /* For power measurement set packet interval to 5s */ #else #define PACKET_INTERVAL 300 /* Set packet interval to 500000us or 500ms */ #endif /***** Prototypes *****/ /***** Variable declarations *****/ static RF_Object rfObject; static RF_Handle rfHandle; //Timer_Object *TimerObj; //Timer_Handle TimerHandle; /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; static uint8_t packet[PAYLOAD_LENGTH]; static uint16_t seqNumber; /* ADC conversion result variables */ uint16_t adcValue0; uint32_t adcValue0MicroVolt; uint16_t adcValue1[ADC_SAMPLE_COUNT]; uint32_t adcValue1MicroVolt[ADC_SAMPLE_COUNT]; uint16_t sampleBufferOne[ADCBUFFERSIZE]; uint16_t sampleBufferTwo[ADCBUFFERSIZE]; float microVoltBuffer[ADCBUFFERSIZE]; float valor_temperatura=0; float media[ADCBUFFERSIZE]; int_fast16_t val; /* * Application LED pin configuration table: * - All LEDs board LEDs are off. */ PIN_Config pinTable[] = { Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, #ifdef POWER_MEASUREMENT #if defined(Board_CC1350_LAUNCHXL) Board_DIO30_SWPWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, #endif #endif PIN_TERMINATE }; /***** Function definitions *****/ float conversionTemp(uint16_t value){ float NTC; float Temp; // NTC = ((2.27*100000)/value)-100000; // NTC = NTC/1000; NTC = 100000*4096/value - 100000; NTC = NTC/1000; Temp = 66.266*exp((-0.01*NTC)); // Temp = exp((NTC-421.37)/-96.7); return(Temp); } void conversionFloat(float temp, float battery, uint8_t * packet) { float aux=roundf(temp * 100); int n=(int)aux; uint8_t i; for(i=5;i>1;i--) { packet[i]=n%10; n=n/10; } aux=roundf(battery * 100); n=(int)aux; for(i=8;i>5;i--) { packet[i]=n%10; n=n/10; } } uint16_t readADC(){ ADC_Handle adc; ADC_Params params; int_fast16_t res; float floatValue; uint16_t normValue = 0; uint8_t i; ADC_init(); ADC_Params_init(¶ms); adc = ADC_open(2, ¶ms); if (adc != NULL) { for (i=0; i < NORM_VALUES; i++){ /* Blocking mode conversion */ res = ADC_convert(adc, &adcValue0); if (res == ADC_STATUS_SUCCESS) { adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0); // floatValue = adcValue0MicroVolt*1.00/1000000.00; normValue += adcValue0; adcValue0 = 0; }else{ i--; } } normValue = normValue/NORM_VALUES; ADC_close(adc); } return (normValue); } float getBatteryValue(){ // uint32_t battery, BATstatus; // float BATvoltage; // // battery = AONBatMonBatteryVoltageGet(); // // // convert in Milli volts // BATstatus = (BATstatus * 125) >> 5; // // //convert in floating point value // BATvoltage = (float)BATstatus / 1000; float MeasuredVoltage = (float)(((uint32_t)HWREG(AON_BATMON_BASE + AON_BATMON_O_BAT)*125) >> 5)/1000; // Convert to milivolts, then convert to float return (MeasuredVoltage); } void *mainThread(void *arg0) { RF_Params rfParams; RF_Params_init(&rfParams); struct tm next_time; struct tm current_time; time_t next_seconds; time_t current_seconds; uint32_t sleep_interval; // float batteryValue; memset(&next_time, 0, sizeof(struct tm)); // memset(¤t_time, 0, sizeof(struct tm)); // float microVoltValue; uint16_t ADCvalue; float Temperature; RF_cmdPropTx.pktLen = PAYLOAD_LENGTH; RF_cmdPropTx.pPkt = packet; RF_cmdPropTx.startTrigger.triggerType = TRIG_NOW; /* Request access to the radio */ rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); /* Set the frequency */ RF_postCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); // Set the struct date / time to 2016 / 5 / 21 18:00:00 current_time.tm_year = 2016 - 1970; current_time.tm_mon = 5 - 1; current_time.tm_mday = 21; current_time.tm_hour = 18; current_time.tm_min = 0; current_time.tm_sec = 0; // Set the struct date / time to 2016 / 5 / 21 18:00:00 next_time.tm_year = 2016 - 1970; next_time.tm_mon = 5 - 1; next_time.tm_mday = 21; next_time.tm_hour = 18; next_time.tm_min = 0; next_time.tm_sec = 0; AONBatMonEnable(); /* Create packet with incrementing sequence number and random payload */ packet[0] = (uint8_t)ID0; packet[1] = (uint8_t)ID1; while(1) { // Get Battery level float MeasuredVoltage = (float)(((uint32_t)HWREG(AON_BATMON_BASE + AON_BATMON_O_BAT)*125) >> 5)/1000; // Convert to milivolts, then convert to float ADCvalue = readADC(); Temperature = conversionTemp(ADCvalue); conversionFloat(Temperature, MeasuredVoltage, packet); /* Send packet */ RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, NULL, 0); RF_yield(rfHandle); // Radio powered off Task_sleep(2880000000); // 8 hours } }
我 μA 到的问题是、睡眠模式下的电流消耗为1.7mA、但电流消耗应低得多(几 μ A)。 我将测量3V3跳线中的电流、如图所示。 我查看了用于测量电流消耗的应用手册、但我没有移除任何跳线、因为它是通过 USB 编程的。
为什么电流消耗如此高?
提前感谢、
Alberto