Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Input Edge Count Individual Up or Down mode not working in CC2538 using Timer?

$
0
0

Hello All,

Looking for a quick feedback.

I am giving a rising edge frequency to CC2538 at BSP_LED_1 pin of CC2538. I would like to measure a frequency from 500 Khz to 1 MHz. of 50% duty cycle.

I would like to use the CC2538 in Input Edge Count mode using Timer for detection of rising edges. Also followed the steps as mentioned in the data sheet .

I am going to post the steps and my code for the same.

Steps:

A timer is configured to Input Edge-Count mode by the following sequence:
1. Ensure the timer is disabled (the TAEN bit is cleared) before making any changes.
2. Write the GPTM Configuration (GPTIMER_CFG) register with a value of 0x0000.0004.
3. In the GPTM Timer Mode (GPTIMER_TnMR) register, write the TnCMR field to 0x0 and the TnMR
field to 0x3.
4. Configure the type of event(s) that the timer captures by writing the TnEVENT field of the GPTM
Control (GPTIMER_CTL) register.
5. If a prescaler is to be used, write the prescale value to the GPTM Timer n Prescale Register
(GPTIMER_TnPR).
6. Load the timer start value into the GPTM Timer n Interval Load (GPTIMER_TnILR) register.
7. Load the event count into the GPTM Timer n Match (GPTIMER_TnMATCHR) register.
8. If interrupts are required, set the CnMIM bit in the GPTM Interrupt Mask (GPTIMER_IMR) register.
9. Set the TnEN bit in the GPTIMER_CTL register to enable the timer and begin waiting for edge events.
10. Poll the CnMRIS bit in the GPTMRIS register or wait for the interrupt to be generated (if enabled). In
both cases, the status flags are cleared by writing a 1 to the CnMCINT bit of the GPTM Interrupt
Clear (GPTIMER_ICR) register.

My code without EVENT Interrupt

----------------------------------------------------------------------------------

SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);
   
SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);    
    
SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);    
        
InitConsole();

UARTprintf("\n FREQUENCY MEASUREMENT ");
   
IOCPinConfigPeriphInput(BSP_LED_BASE, BSP_LED_1, IOC_GPT0OCP1);
 
while(1)
{   
 
 TimerDisable(GPTIMER0_BASE,GPTIMER_BOTH);
 
 //!< GPTIMER_CFG ( Configure Timer for 16 bit Timer )
 TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR | GPTIMER_CFG_B_CAP_COUNT | GPTIMER_CFG_A_PERIODIC_UP );
   
//! Timer Control Event TimerControlEvent(uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Event)  
 TimerControlEvent(GPTIMER0_BASE,GPTIMER_B,GPTIMER_EVENT_POS_EDGE); //!< EDGES
 
  //!< Timer Enable
  TimerEnable(GPTIMER0_BASE,GPTIMER_BOTH);
 
  /*TimevalgetB= TimerValueGet(GPTIMER0_BASE, GPTIMER_B);
  UARTprintf("\n Time_B0 = %d \n" , TimevalgetB);
}

My code with Interrupt

--------------------------------------------------------------------------

SysCtrlClockSet(false, false, SYS_CTRL_SYSDIV_32MHZ);
   
SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);    
    
SysCtrlPeripheralEnable(SYS_CTRL_PERIPH_GPT0);    
        
InitConsole();

UARTprintf("\n FREQUENCY MEASUREMENT ");
   
IOCPinConfigPeriphInput(BSP_LED_BASE, BSP_LED_1, IOC_GPT0OCP1);

 TimerDisable(GPTIMER0_BASE,GPTIMER_BOTH);
 
 //!< GPTIMER_CFG ( Configure Timer for 16 bit Timer )
 TimerConfigure(GPTIMER0_BASE, GPTIMER_CFG_SPLIT_PAIR | GPTIMER_CFG_B_CAP_COUNT | GPTIMER_CFG_A_PERIODIC_UP );
   
//! Timer Control Event TimerControlEvent(uint32_t ui32Base, uint32_t ui32Timer, uint32_t ui32Event)  
 TimerControlEvent(GPTIMER0_BASE,GPTIMER_B,GPTIMER_EVENT_POS_EDGE); //!< EDGES

  //!< Enable Processor Interupt
  IntMasterEnable();
 
  //!< Register a handler else systick will be called
  TimerIntRegister(GPTIMER0_BASE,GPTIMER_B, FreqMeasure_handler);
 
  //!< Generate an interrupt
  TimerIntEnable(GPTIMER0_BASE,GPTIMER_CAPB_EVENT);  

 
  //!< Enable the Timer0A interrupt on the processor (NVIC)
  IntEnable(INT_TIMER0B);
 
  //!< Timer Enable
  TimerEnable(GPTIMER0_BASE,GPTIMER_BOTH);

}

Also I have a handler where I will capture the Timer count value as below.

void
FreqMeasure_handler(void)
{
  static uint32_t Handler_count,TimevalgetA;

  TimevalgetB= TimerValueGet(GPTIMER0_BASE, GPTIMER_B);
  UARTprintf("\n Time_B = %d \n" , TimevalgetB); 
}

I am not to see any count value for TimerB in Edge count mode, please let me know what could be wrong in above code or if any step I am missing.

Regards

Gaurav


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>