2 input capture channels on SCT

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

2 input capture channels on SCT

1,231件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Wed Jul 23 10:45:43 MST 2014
I have 2 SCT0 capture inputs enabled to measure PWM period from external sensors (between falling edges). I created 2 events to generate an interrupt and read out capture values from CAP[0] and CAP[1]. The timer is running from the system's clock. Everything works perfectly fine until falling edges on both channels get really close to each other. In that case there is no flag set for one of the channels in the EVFLAG register and the channel simply misses its edge. INSYNC bits are set for both channels. Any thoughts?
ラベル(1)
0 件の賞賛
12 返答(返信)

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Fri Mar 18 13:14:02 MST 2016
LPCOpen 2.20 for LPC15xx is out but this bug reported more than a year ago hasn't still been fixed.  |(  |(  |(
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Wed Jul 30 06:22:48 MST 2014
Is there any bug tracker for the LPCOpen project? I have one more issue to post.
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Mon Jul 28 10:51:59 MST 2014
Yes, there are still a lot of 'little surprises' in LPCOpen  :) 

But a bunch of Beta testers are working hard to find them...

At least you are  :bigsmile:
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Mon Jul 28 09:39:53 MST 2014
By the way. I copied it from sct_15xx.h without paying much attention
/**
 * @briefClear the specified event flag in State Configurable Timer
 * @parampSCT: The base of SCT peripheral on the chip
 * @paramevt: Event value
 * @returnNothing
 */
STATIC INLINE void Chip_SCT_ClearEventFlag(LPC_SCT_T *pSCT, CHIP_SCT_EVENT_T evt)
{
pSCT->EVFLAG |= evt;
}


0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Mon Jul 28 09:25:32 MST 2014
You are absolutely right. My bad. Have overlooked such a basic stuff... Need to go for a vacation. Thank you very much for your help.
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Mon Jul 28 08:56:17 MST 2014
If you feed both capture inputs with the same signal (or your original signals trigger the inputs at the same time),
ISR is starting with:

[color=#f00]EVFLAG = 3[/color] 

So if you read EVFLAG and write it back you are clearing both events...

Correct sample:

void SCT0_IRQHandler(void)
{
 if (LPC_SCT0->EVFLAG & SCT_EVT_0)
 {
  Board_LED_Set(0,false);
  [color=#f00]LPC_SCT0->EVFLAG = SCT_EVT_0; //clear EVENT0 only[/color]
  Board_LED_Set(0,true);
 }
 if (LPC_SCT0->EVFLAG & SCT_EVT_1)
 {
  Board_LED_Set(1,false);
  [color=#f00]LPC_SCT0->EVFLAG = SCT_EVT_1; //clear EVENT1 only[/color]
  Board_LED_Set(1,true);
 }
}
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Mon Jul 28 08:22:53 MST 2014
What is a problem? For the first event I clear the first event's flag.
uint32_t ev = LPC_SCT->EVFLAG;
if (ev & SCT_EVT_0) {
// processing
...
LPC_SCT->EVFLAG |= SCT_EVT_0;
}


For the second event I clear the second event's flag.
uint32_t ev = LPC_SCT->EVFLAG;
if (ev & SCT_EVT_1) {
// processing
...
LPC_SCT->EVFLAG |= SCT_EVT_1;
}



Moreover I tried to clear all flags at the same time but with no improvement.
uint32_t ev = LPC_SCT->EVFLAG;
LPC_SCT->EVFLAG |= ev;


Will try to feed same signal to both channels once I am at the lab.
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Fri Jul 25 13:52:14 MST 2014

Quote: DF9DQ

Quote:
Doesn't look too wrong...
...
[color=#f00]What's happening if you feed both captures with the same signal?[/color]



Except for this minor detail: 
LPC_SCT->EVFLAG |= SCT_EVT_0;




And now we can forget the good old fish story   
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by DF9DQ on Fri Jul 25 13:06:52 MST 2014

Quote:
Doesn't look too wrong...



Except for this minor detail: 
LPC_SCT->EVFLAG |= SCT_EVT_0;


The read-modify-write kills the other event flag if it was set after reading the flags into "ev".
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Wed Jul 23 13:29:02 MST 2014
Doesn't look too wrong...

That's not LPCXpresso  :((

What's happening if you feed both captures with the same signal?
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Wed Jul 23 11:50:50 MST 2014
Lets put it simple. The task is to measure frequency of pulses on two input channels by measuring number of clock cycles between falling edges. The problem is when falling edges from both channels are close enough to each other then EVFLAG for one of the channels gets missed.

void LPC_SCT_IRQ_Handler() {

  uint32_t ev = LPC_SCT->EVFLAG;

  if (ev & SCT_EVT_0) {

    // channel 0 handler
    ...

    LPC_SCT->EVFLAG |= SCT_EVT_0;

  }

  if (ev & SCT_EVT_1) {

    // channel 1 handler
    ...

    LPC_SCT->EVFLAG |= SCT_EVT_1;

  }

}

void Init() {

  Chip_INMUX_SelectSCT0Src(0, SCT0_INMUX_PIO1_7);
  Chip_INMUX_SelectSCT0Src(1, SCT0_INMUX_PIO1_6);

  Chip_SCT_Init(LPC_SCT);
  Chip_SCT_Config(LPC_SCT, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_CLKMODE_BUSCLK | (3 << 9);

  LPC_SCT->REGMODE = 0x03;
  LPC_SCT->EVEN = 0x03;

  LPC_SCT->CAPCTRL[0].U = _BIT(0);              // event 0 is causing capture 0
  LPC_SCT->CAPCTRL[1].U = _BIT(1);              // event 1 is causing capture 1

  // setup channel 0 event
  LPC_SCT->EVENT[0].STATE = 0xFFFF;            // event happens in all states
  LPC_SCT->EVENT[0].CTRL = _SBF( 6, 0) |       // IN_0
                           _SBF(10, 2) |                              // falling edge
                           _SBF(12, 2);                               // IO condition only

  // setup channel 1 event
  LPC_SCT->EVENT[1].STATE = 0xFFFF;               // event happens in all states
  LPC_SCT->EVENT[1].CTRL = _SBF( 6, 1) |          // IN_1
                           _SBF(10, 2) |                                // falling edge
                           _SBF(12, 2);                                 // IO condition only

  NVIC_EnableIRQ(LPC_SCT_IRQn);

  Chip_SCTPWM_Start(LPC_SCT);

}
0 件の賞賛

1,139件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Wed Jul 23 11:06:16 MST 2014
I'm not sure what we are talking about in detail. If it's a 'conventional' SCT program it could be a good idea to post it...
0 件の賞賛