SCT used to measure on-time

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SCT used to measure on-time

1,348 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jdurand on Tue Apr 01 14:48:54 MST 2014
I'm working on my first SCT project, but am experienced with LPC81x parts from other projects.

I have an input that will be pulsing and I need to measure the time it's high over a set period.  I also need to send the decisions to an output pin.

What I'm trying to simulate here is a normal UP timer that is gated by an input pin.

Here's what I'm thinking:

Counter_H and L are both clocked at 1 MHz after the prescalers.

Counter_L free runs.

Event 0 takes the device pin as an input and when the pin is high, it removes HALT from counter_H.  Sets the output pin.

Event 1 takes the same device pin as an input and when the pin is low, it sets HALT for counter_H. Clears the output pin.

Event 2 happens when Counter_L = 50,000.  STOP is set for both counters.

When the counters stop, my program reads Counter_H and has the total on-time for the device input pin.

Now to figure out how to configure this.
Labels (1)
0 Kudos
5 Replies

1,254 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jdurand on Wed Apr 02 16:22:41 MST 2014
Got it working.  I loaded the Blinky example and verified I had all my pins set right, then modified from there.  Here's what I would up with:

//LPC_SCT->CONFIG// default, split timer

// Event 0 is TP high, start CounterH
LPC_SCT->EVENT[0].STATE = 0x01;// event 0 only happens in state 0
LPC_SCT->EVENT[0].CTRL = 1<<4// HEVENT H, input
| 1<<6// select CTIN_1
| 3<<10// active high
| 2<<12// COMBMODE only IO
| 1<<14// STATELD = STATEV is loaded into state
| 0<<15// STATEV = 0 (new state is 0)
;// no match used
LPC_SCT->START_H = 1<<0;// event 0 starts timer H
LPC_SCT->OUT[0].SET = 1<<0;// event 0 will setSCT_OUT0

// Event 1 is TP low
LPC_SCT->EVENT[1].STATE = 0x01;// event 1 only happens in state 0
LPC_SCT->EVENT[1].CTRL = 1<<4 // HEVENT H, input
   | 1<<6// select CTIN_1
  | 0<<10// active LOW
   | 2<<12// COMBMODE only IO
                       | 1<<14// STATELD = STATEV is loaded into state
                      | 0<<15 // STATEV = 0 (new state is 0)
                       ;// no match used
LPC_SCT->STOP_H = 1<<1;// event 1 stops timer H
LPC_SCT->OUT[0].CLR = 1<<1; // event 1 will clear SCT_OUT0

// Event 2 is counter L = 50,000
LPC_SCT->MATCH_L[2] = 50000;// match 2 set to 50mS
LPC_SCT->EVENT[2].STATE = 0x01;// event 2 only happens in state 0
LPC_SCT->EVENT[2].CTRL = 2// use Match register 2
   | 0<<4 // HEVENT L
   | 1<<12// COMBMODE only MATCH
                      | 1<<14// STATELD = STATEV is loaded into state
                       | 0<<15// STATEV = 0 (new state is 0)
                       | 1<<20;// match when >=, direction independent
LPC_SCT->HALT_H = 1<<2;// event 2 halts counterH
LPC_SCT->HALT_L = 1<<2;// event 2 halts counterL

LPC_SCT->CTRL_U = 0// L is up counter, not STOPped or HALTed
| 1<<3// clear counter L, UP count only
| (SystemCoreClock / 1000000)<<5// 1 uS ticks
| 1<<17// counter H UP count, stopped, not halted
| 1<<19// clear counter H
| (SystemCoreClock / 1000000)<<21;// 1 uS ticks


0 Kudos

1,254 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Tue Apr 01 20:20:00 MST 2014
Hi Jdurand,
To make calculation simple you can also reset counter on an event if you are not using it for any other purpose. Rising and falling edge will generate two events.These events can be used to capture counter value
in two separate capture registers respectively. You can use one match register to set the limit(reset counter) for time out. You can also generate interrupt either on falling edge or rising edge.  If you want you can also generate interrupt when timeout event triggers.

So in your case if you just want to measure ontime you can do following
Falling edge will generate event1 which will capture counter value and also generate interrupt so that you can use this value
Rising edge will generate event2 which can be used to reset counter
You can have event0 for timeout it will also reset counter.
0 Kudos

1,254 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jdurand on Tue Apr 01 17:51:30 MST 2014
Wow, lot of information.  Thanks.

Will take a look at this tomorrow.  Got partway through the setup today.

I looked at the graphical Red State, but it seems too high level.  I rarely find those graphical things useful for the stuff I work on.
0 Kudos

1,254 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcwizz on Tue Apr 01 17:47:15 MST 2014
while i can not write the sct config file for your project i can supply you with information which i gathered during a couple of weeks getting used to the sct

1) there is an lpc800 sct cookbook with examples and other useful information at
http://www.lpcware.com/content/nxpfile/lpc80-sct-cookbook-and-tutorial-code-examples

2) there is also an lpc1500 sct cookbook with a slightly different approach to design the sct config files at
http://www.lpcware.com/content/nxpfile/lpc1500-sct-cookbook-and-tutorial
the lpc1500 sct is basically the same core, just larger, more events

3) you have the option to use the red state tool which come with lpcxpresso and documentation can be found at
http://support.code-red-tech.com/CodeRedWiki/NewInVersion4?action=AttachFile&do=get&target=Red_State...
there is a newer ver 5 also on the net, which contains basically the same information

while this tool provides a very high level design approach it can be sometimes a bit tricky and will not produce all necessary config data if the user doesn't provide enough or the wrong information like input, event, activities ... etc
the issue is to find a correlation of the high level state configuration and how it translates to the generated sct config data

the files sct_user.h and sct_fsm.c/h are state red generated

4) i have included an excel spreadsheet which i generated for one of my projects to keep all relevant information sort of grouped together ... it will take a while to follow this spreadsheet, but it might help ... note it's only a table to fill in and to look at it in a more organized fashion and no arithmetic or logic data is being produced ... also included is an lpc1500 excel document containing the same data (might not be completely updated, but it should help to see the difference)

the bit fields of the event regs are not numerically ordered, rather grouped together by functionality
not all registers have data filled in in both spreadsheets. hope this helps

5) i have also enclosed a study on how "C" style macros and enums can help with logically grouping the individual bits and bit fields of the regs together ... the data contained is all from the same project. There might be an app-note coming out soon explaining the particular app these docs came from
file sct_defs.h contains the all (or most) sct regs related bit and bitfield information.
file sct_ctouch.h has the app specific terms equated to some generic sct regs and bit filed names
file sct_ctouch.c holds the actual sct regs config data

6) i decided to also include the set of pdfs related to the sct example ... it might be not to easy to follow since i did not provide a lengthy explanation about the functionality, but it should help to make the connections from the state red tool to the generated sct config files

hope this helps ... it takes a bit to get used to the sct ( a couple weeks at least), but once you know it you won't want to miss it :)
0 Kudos

1,254 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jdurand on Tue Apr 01 14:57:54 MST 2014
I meant remove and set STOP/START based on events 0 & 1, event 2 sets HALT for everything
0 Kudos