Other Parts Discussed in Thread: ENERGYTRACE
Hi Everyone,
I am doing a project using CC1310 in which CC1310 sends RF Packet which contains the data of On-duration, count, battery voltage and a device ID. The on-duration is obtained from a HWI which is called when switch is turned on, once it is off it goes back to the task. So in my code I have one Task- Sending RF Packets and an Interrupt Button callback function - to calculate on duration. I have added the codes for task and button callback function below.
Task Function
/* TX task function. Executed in Task context by TI-RTOS when the scheduler starts. */ static void txTaskFunction(UArg arg0, UArg arg1) { /* Enabling the battery monitoring function to check the battery voltage*/ AONBatMonEnable(); /* Setup callback for button pins */ PIN_Status status = PIN_registerIntCb(buttonPinHandle, &buttonCallbackFunction); Assert_isTrue((status == PIN_SUCCESS), NULL); /* Initialize the radio */ RF_Params rfParams; RF_Params_init(&rfParams); /* Customize the CMD_PROP_TX command for this application */ RF_cmdPropTx.pktLen = PAYLOAD_LENGTH; RF_cmdPropTx.pPkt = packet; RF_cmdNop.startTrigger.triggerType = TRIG_NOW; RF_cmdNop.startTrigger.pastTrig = 1; /* Set up the next pointers for the command chain */ RF_cmdNop.pNextOp = (rfc_radioOp_t*)&RF_cmdPropCs; RF_cmdPropCs.pNextOp = (rfc_radioOp_t*)&RF_cmdCountBranch; RF_cmdCountBranch.pNextOp = (rfc_radioOp_t*)&RF_cmdPropTx; RF_cmdCountBranch.pNextOpIfOk = (rfc_radioOp_t*)&RF_cmdPropCs; /* Customize the API commands with application specific defines */ RF_cmdPropCs.rssiThr = RSSI_THRESHOLD_DBM; RF_cmdPropCs.csEndTime = (IDLE_TIME_US + 150) * 4; /* Add some margin */ RF_cmdCountBranch.counter = CS_RETRIES_WHEN_BUSY; /* Request access to the radio */ rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams); /* Set the frequency */ RF_runCmd(rfHandle, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, 0); /* Get current time */ times = RF_getCurrentTime(); RF_yield(rfHandle); /* Enter main TX loop */ /* Getting LSB of MAC Address for Device ID */ uint64_t macAddrLsb = HWREG(FCFG1_BASE + FCFG1_O_MAC_15_4_0); /*For Full MacAddress use following code * uint64_t macAddrMsb =HWREG(FCFG1_BASE + FCFG1_O_MAC_15_4_1); uint64_t macAddress = (uint64_t)(macAddrMsb << 32) + macAddrLsb; */ uint8_t j = 11; /* Reset values to avoid garbage values*/ packet[7] = 0; packet[8] = 0; packet[9] = 0; packet[10] = 0; packet[11] = 0; /*Storing LSB of MAC Address in Radio Packet */ while(macAddrLsb>0) { packet[j] = macAddrLsb%100; if(j!=0) {macAddrLsb /= 100;} else {macAddrLsb /= 10;} j--; } while(1) { /* Wait for a button press */ Semaphore_pend(txSemaphoreHandle, BIOS_WAIT_FOREVER); /* Reading the battery voltage */ batteryStatus = AONBatMonBatteryVoltageGet(); /* Convert in Milli volts*/ batteryStatus = (batteryStatus * 125) >> 5; batteryVoltage = (float) batteryStatus / 100; /* Create packet with incrementing sequence number */ packet[0] = (uint8_t) (seqNumber >> 8); packet[1] = (uint8_t) (seqNumber); packet[2] = batteryVoltage; //packet[3] = ; /* Set absolute TX time to utilize automatic power management */ times += (PACKET_INTERVAL_US * 4); RF_cmdNop.startTime = times; /* Send packet */ RF_runCmd(rfHandle, (RF_Op*)&RF_cmdNop, RF_PriorityNormal, &callback, 0); RF_cmdNop.status = IDLE; RF_cmdPropCs.status = IDLE; RF_cmdCountBranch.status = IDLE; RF_cmdPropTx.status = IDLE; RF_cmdCountBranch.counter = CS_RETRIES_WHEN_BUSY; RF_yield(rfHandle); } }
HWI
/***** Button Callback function *****/ static void buttonClockCb(UArg arg) { PIN_Handle buttonHandle = (PIN_State *) arg; /* Stop the button clock */ /* Re-enable interrupts to detect button release. */ Clock_stop(hButtonClock); /* Check that there is active button for debounce logic*/ if (activeButtonPinId != PIN_TERMINATE) { /* Checking whether the button is actively pressed*/ if(!PIN_getInputValue(activeButtonPinId)) { /* Wait here till the button is released */ while(!PIN_getInputValue(activeButtonPinId)) { usleep(50000); } /* Checking whether the button is released*/ if (PIN_getInputValue(activeButtonPinId)) { switch (activeButtonPinId) { case Board_DIO10: /* Getting time form the Timestamp function*/ time1 = Timestamp_get32(); /* Calculating the time between switch pressed and released*/ timePeriod = time1-time0; /* Converting the time to microseconds from clock ticks*/ microTime = timePeriod/0.065536; /* Converting the time from microseconds to centiseconds */ realTime = microTime/10000; /* Reset values to avoid garbage values*/ packet[3] = 0; packet[4] = 0; packet[5] = 0; packet[6] = 0; /* Encoding the time in different packets for radio transmission*/ i = 6; while(realTime>0) { packet[i] = realTime%100; realTime /= 100; i--; } /* Posting the semaphore for the radio functions*/ Semaphore_post(txSemaphoreHandle); break; default: /* Do nothing */ break; } } } } /* Re-Enabling the interrupt for detecting the button press*/ PIN_setConfig(buttonHandle, PIN_BM_IRQ, activeButtonPinId | PIN_IRQ_NEGEDGE); /* Set activeButtonPinId to none... */ activeButtonPinId = PIN_TERMINATE; }
My issue is the with power consumption, I am using Lithium CR2032 3V battery and it only last 2 or 3 days, however I ran a test where it sends data every 3 seconds by running only the task and keeping the switch in off position, it lasted for more than 2 weeks. Could anyone please let me know what I am doing wrong in the code or what can be done to improve the battery life? Also the all the variables are declared static.
Thanks in advance