Other Parts Discussed in Thread: CC2650
Hello !
I'm actually working on the CC2650 with the TI-RTOS 2.20 on CCS 6.1.3.
I saw in datasheet the ADC can convert at 200kSamples/s, so 5microseconde/sample. Unfortantely I'm unable to get this time with the RTOS.
I have arround 22 microsecondes unless 5. Is the TI-RTOS slowing the ADC that much ?
Here is the code i used, I took the faster convert (2.7us) and have no other task. I thought this issue came from the clock but it seems we haevn't the choice about the clock.
#include "Board.h"
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <ti/drivers/power/PowerCC26XX.h>
#include <ti/sysbios/BIOS.h>
#include <ti/drivers/PIN/PINCC26XX.h>
#include <ti/drivers/UART.h>
#include <driverlib/aux_adc.h>
#include <driverlib/aux_wuc.h>
#include <inc/hw_aux_evctl.h>
#include <ti/mw/display/Display.h>
#include <xdc/runtime/System.h>
#define TASK_STACK_SIZE 512
#define TASK_PRI 1
char taskStack[TASK_STACK_SIZE];
Task_Struct taskStruct;
Semaphore_Struct sem;
Semaphore_Handle hSem;
Hwi_Struct hwi;
#define SAMPLECOUNT 100
#define SAMPLETYPE uint16_t
#define SAMPLESIZE sizeof(SAMPLETYPE)
#define ALS_POWER IOID_26
#define ALS_OUTPUT IOID_23
SAMPLETYPE adcSamples[SAMPLECOUNT];
SAMPLETYPE singleSample;
// Analog light sensor pins
const PIN_Config alsPins[] = {
ALS_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
ALS_OUTPUT | PIN_INPUT_DIS | PIN_GPIO_OUTPUT_DIS ,
PIN_TERMINATE
};
PIN_Handle pinHandle;
PIN_State pinState;
//CUSTOM
static PIN_Handle ledPinHandle;
static PIN_State ledPinState;
/*
* Application LED pin configuration table:
* - All LEDs board LEDs are off.
*/
PIN_Config ledPinTable[] = {
Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
UART_Handle uHandle;
void taskFxn(UArg a0, UArg a1);
void adcIsr(UArg a0);
int main(void) {
//Initialize pins, turn on GPIO module
PIN_init(BoardGpioInitTable);
//Initialize task
Task_Params params;
Task_Params_init(¶ms);
params.priority = TASK_PRI;
params.stackSize = TASK_STACK_SIZE;
params.stack = taskStack;
Task_construct(&taskStruct, taskFxn, ¶ms, NULL);
// Construct semaphore used for pending in task
Semaphore_Params sParams;
Semaphore_Params_init(&sParams);
sParams.mode = Semaphore_Mode_BINARY;
Semaphore_construct(&sem, 0, &sParams);
hSem = Semaphore_handle(&sem);
ledPinHandle = PIN_open(&ledPinState, ledPinTable);
System_printf("ADC INITIALIZED\n");
System_flush();
BIOS_start();
}
void taskFxn(UArg a0, UArg a1) {
Hwi_Params hwiParams;
Hwi_Params_init(&hwiParams);
hwiParams.enableInt = true;
Hwi_construct(&hwi, INT_AUX_ADC_IRQ, adcIsr, &hwiParams, NULL);
// Set up pins
pinHandle = PIN_open(&pinState, alsPins);
// Enable clock for ADC digital and analog interface (not currently enabled in driver)
AUXWUCClockEnable(AUX_WUC_MODCLKEN0_ANAIF_M|AUX_WUC_MODCLKEN0_AUX_ADI4_M);
// Set up ADC
AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);
// Disallow STANDBY mode while using the ADC.
Power_setConstraint(PowerCC26XX_SB_DISALLOW);
uint8_t currentSample = 0;
while(1)
{
for(currentSample = 0; currentSample < SAMPLECOUNT; currentSample++)
{
//Sleep 100ms in IDLE mode
//Task_sleep(4 / Clock_tickPeriod);
AUXADCSelectInput(ADC_COMPB_IN_AUXIO7);
// Trigger ADC sampling
AUXADCGenManualTrigger();
// Wait in IDLE until done
Semaphore_pend(hSem, BIOS_WAIT_FOREVER );
adcSamples[currentSample] = singleSample;
PIN_setOutputValue(ledPinHandle, Board_LED1, !PIN_getOutputValue(Board_LED1));
}
System_printf("Value AD1 : %d \t \n",adcSamples[currentSample-1]);
System_flush();
}
}
void adcIsr(UArg a0) {
// Pop sample from FIFO to allow clearing ADC_IRQ event
singleSample = AUXADCReadFifo();
// Clear ADC_IRQ flag. Note: Missing driver for this.
HWREGBITW(AUX_EVCTL_BASE + AUX_EVCTL_O_EVTOMCUFLAGSCLR, AUX_EVCTL_EVTOMCUFLAGSCLR_ADC_IRQ_BITN) = 1;
// Post semaphore to wakeup task
Semaphore_post(hSem);
}
Thank you by advance.
Bets regards,
John
