I was trying to trigger ADC with GPT1A on CC2650 (SmartRF06EB+CC2650EM-7ID) but failed to get any ADC output data. The following is my Main_tirtos.c source code. The whole project is modified from ADC Data Logger demo project removing "RTC-based execution scheduling" and all those initialization code / Execution code . After running, the program was hanging on the red line:
while (1) {
adcDac = AUXADCReadFifo();
...
}
Is there anything wrong? Or anyone could show me the right way to trigger ADC with the general purpose timer-out event (not by the AUX-timer). Appreciate for your help!
//*****************************************************************************
// SENSOR CONTROLLER STUDIO EXAMPLE: ADC DATA LOGGER
// Operating system: TI-RTOS
//
// The Sensor Controller is used to sample and buffer a single ADC channel.
// The ADC samples are stored in a ring-buffer, and the Sensor Controller
// maintains a head index indicating where the next sample will be written.
// The sampling interval is specified in the call to scifStartRtcTicksNow().
// The application wakes up at a fixed asynchronous interval, and transfers
// the ADC samples over UART (57600 baud, 8-N-1).
//
// Use a terminal window to connect to the SmartRF06EB's USB Serial Port.
//
// The DISABLE_LOW_POWER definition can be set to 1 to allow debugging.
//
//
// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//****************************************************************************/
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <ti/sysbios/family/arm/cc26xx/Power.h>
#include <ti/sysbios/family/arm/cc26xx/PowerCC2650.h>
#include <ti/drivers/UART.h>
#include <ti/drivers/uart/UARTCC26XX.h>
#include <Board.h>
#include "scif.h"
#include "string.h"
#include "stdio.h"
#include "aux_adc.h"
#include "prcm.h"
#include "timer.h"
#include "event.h"
#include "aux_wuc.h"
#define BV(n) (1 << (n))
#define DISABLE_LOW_POWER 0
// Display error message if the SCIF driver has been generated with incorrect operating system setting
#ifndef SCIF_OSAL_TIRTOS_H
#error "Generated SCIF driver supports incorrect operating system. Please change to 'TI-RTOS' in the Sensor Controller Studio project panel and re-generate the driver."
#endif
// Task data
Task_Struct myTask;
Char myTaskStack[1024];
// UART driver objects
UART_Handle uHandle;
UART_Params uParams;
void scTaskAlertCallback(void) {
} // taskAlertCallback
void scCtrlReadyCallback(void) {
} // ctrlReadyCallback
static void adcInit(void)
{
//intialisation of ADC
// Enable clock for ADC digital and analog interface (not currently enabled in driver)
AUXWUCClockEnable(AUX_WUC_ADI_CLOCK|AUX_WUC_SOC_CLOCK); // was : AUX_WUC_MODCLKEN0_SOC_M|AUX_WUC_MODCLKEN0_AUX_ADI4_M);
// Connect AUX IO7 (DIO23, but also DP2 on XDS110) as analog input.
AUXADCSelectInput(ADC_COMPB_IN_AUXIO7);
AUXADCEnableAsync(AUXADC_REF_FIXED, AUXADC_TRIGGER_GPT1A);
}
void taskFxn(UArg a0, UArg a1) {
// Initialize UART parameters
UART_Params_init(&uParams);
uParams.baudRate = 115200;
uParams.writeDataMode = UART_DATA_BINARY;//UART_DATA_TEXT;
uParams.dataLength = UART_LEN_8;
uParams.stopBits = UART_STOP_ONE;
// Open UART
uHandle = UART_open(Board_UART, &uParams);
// Initialize the Sensor Controller
scifOsalInit();
scifOsalRegisterCtrlReadyCallback(scCtrlReadyCallback);
scifOsalRegisterTaskAlertCallback(scTaskAlertCallback);
scifInit(&scifDriverSetup);
//scifStartRtcTicksNow(0x00010000 / 128);
//scifTaskData.adcTimerTrig.output.adcStartFlag = 0;
// Configure and start the ADC Data Logger task. The task does not signalize data exchange, but
// has buffering capacity for 256 samples = 2 seconds
scifStartTasksNbl(BV(SCIF_ADC_TIMER_TRIG_TASK_ID));
// Maintain the sample buffer tail index here. The Sensor Controller increments the head index (also
// starting at 0) each time a sample is stored in the buffer.
char pLine[120];
uint32_t adcDac = 0;
//Initialization and Configuration GPT1A
/* To use a GPT module, enable the peripheral domain and the appropriate GPT module in the PRCM by
* writing to the PRCM:GPTCLKGR, the PRCM:GPTCLKGS, and the PRCM:GPTCLKGDS registers, or
* by using the following driver library functions:
* PRCMPeripheralRunEnable(uint32_t, ui32Peripheral)
* PRCMPeripheralSleepEnable(uint32_t, ui32Peripheral)
* PRCMPeripheralDeepSLeepEnable(uint32_t, ui32Peripheral)
*/
PRCMPeripheralRunEnable(PRCM_PERIPH_TIMER1);
PRCMPeripheralSleepEnable(PRCM_PERIPH_TIMER1);
PRCMPeripheralDeepSleepEnable(PRCM_PERIPH_TIMER1);
/* 2. Next, load the setting to the clock controller by writing to the PRCM:CLKLOADCTL register */
//Ensure the timer is disabled (clear the GPT:CTL TnEN register bit) before making any changes.
Power_setDependency(PERIPH_GPT1);
TimerDisable(GPT1_BASE, TIMER_A);
//Write the GPTM Configuration Register (GPT:CFG) with a value of 0x0000 0000
HWREG(GPT1_BASE + GPT_O_CFG) = 0;
//Configure the GPTM Timer n Mode Register (GPT:TnMR) TnMR field:
//(a) Write a value of 0x1 for one-shot mode.
//(b) Write a value of 0x2 for periodic mode.
TimerConfigure(GPT1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_ONE_SHOT);
//Optionally, configure the GPT:TnMR TnSNAPS, TnWOT, TnMTE, and TnCDIR register bits to select
//whether to capture the value of the free-running timer at time-out, use an external trigger to start
//counting, configure an additional trigger or interrupt, and count up or down.
//Load the start value into the GPTM Timer n Interval Load Register (GPT:TnILR).
TimerLoadSet(GPT1_BASE, TIMER_A, 3750);
//If interrupts are required, set the appropriate bits in the GPTM Interrupt Mask Register (GPT:IMR).
// Enable timer trigger output for ADC
TimerTriggerControl(GPT1_BASE, TIMER_A, true);
// Configure the event fabric to select the appropiate timer.
EventRegister(EVENT_AUX_PROG, EVENT_TIMER1_A);
/* 3. Configure the IOC module to route the output from the GPT module to the IOs. */
/* The IOC module must then be configured to output the timer signal on the wanted I/O pin. For this,
* IOCFGn.PORTID must be written to the correct PORTIDs (see Chapter 11, I/O Control, for more
* details).
*/
/* init adc */
adcInit();
//AUXADCFlushFifo();
//Set the GPT:CTL TnEN register bit to enable the timer and start counting.
Power_setConstraint(Power_SB_DISALLOW);
TimerEnable(GPT1_BASE, TIMER_A);
sprintf(pLine, "sample: \r\n");
UART_write(uHandle, pLine, strlen(pLine));
// Main loop
while (1) {
adcDac = AUXADCReadFifo();
sprintf(pLine, "ADC %d\r\n", adcDac);
UART_write(uHandle, pLine, strlen(pLine));
}
} // taskFxn
int main(void) {
Task_Params taskParams;
// Optional: Prevent the system from entering standby to allow debugging
#if DISABLE_LOW_POWER
Power_setConstraint(Power_SB_DISALLOW);
Power_setConstraint(Power_IDLE_PD_DISALLOW);
#endif
// Initialize the PIN driver
PIN_init(BoardGpioInitTable);
// Configure the OS task
Task_Params_init(&taskParams);
taskParams.stack = myTaskStack;
taskParams.stackSize = sizeof(myTaskStack);
taskParams.priority = 3;
Task_construct(&myTask, taskFxn, &taskParams, NULL);
// Start TI-RTOS
BIOS_start();
return 0;
} // main