Problem with SCT for a simple timer

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

Problem with SCT for a simple timer

511 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Wed Jan 08 00:11:28 MST 2014
Problem with SCT for a simple timer
Hi
back again with another problem :-D
I’m trying to run a 128 khz period cycle on pin0_7 whit SCT and my processor is LPC812M101JD16 and using the internal crystal
I’m writhe the program below but it’s not work
     SCT_delay=1000000;
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); //enable the clock for sct 92.1.18
    LPC_SYSCON->PRESETCTRL |= ( 1<< 8); // clear the sct resset pins  92.1.18
    LPC_SWM->PINASSIGN6 |= (111<<24) ; // set the pin0_7 to output
    LPC_SCT->CONFIG = (LPC_SCT->CONFIG & ~0x00060001);
    LPC_SCT->REGMODE_L = 0x00000000;
    LPC_SCT->MATCH[0].U = SCT_delay;
    LPC_SCT->MATCHREL[0].U = SCT_delay;
    LPC_SCT->OUT[0].SET = 0x00000001;
    LPC_SCT->OUT[0].CLR = 0x00000002;
    /* Initial state of CTOUT_0 is 0 */
    LPC_SCT->OUTPUT = (LPC_SCT->OUTPUT & ~0x00000001) | 0x00000000;
    LPC_SCT->EVENT[0].CTRL = 0x0000D000; /* match[0] causes transition to State 1 */
    LPC_SCT->EVENT[0].STATE = 0x00000001; /* Event[0] occurs in State 0 */
    LPC_SCT->EVENT[1].CTRL = 0x00005000; /* Event 0 on Match[0]. Load State 0 */
    LPC_SCT->EVENT[1].STATE = 0x00000002; /* Event[1] occurs in State 1 */
    LPC_SCT->STATE_L = 0;
    LPC_SCT->LIMIT_L = 0x00000003; /* EVENTS 0 and 1 cause a timer limit */




Labels (1)
0 Kudos
6 Replies

451 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Sun Jan 12 06:31:35 MST 2014
Thx for your answers I’m trying the clkout and also study more for understanding of SCT
lpcware are the coolest forum i ever sine for ARMs controllers
Thx guys  :D
0 Kudos

451 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Wed Jan 08 14:46:32 MST 2014

Quote: salamlora1

I’m trying to run a 128 khz period cycle on pin0_7


Much easier done with CLKOUT:
CLKOUT divider set to 94, use switch matrix to put moveable function to PIO0_7 (PINASSIGN8).
0 Kudos

451 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Wed Jan 08 12:58:52 MST 2014
How can you verify the output? Oscilloscope??

Just as a coarse roadmap:

You cannot divide 12MHz by an integral divider to get 128kHz, so let's assume 127.66 kHz is fine (divide by 94). We can generate the
wanted frequency by toggling with double frequency, divider=47

So set up a match at value 47-1 (match0) disable reload.
Configure AUTOLIMIT (CONFIG).
Configure event0 as match 0, no state condition. Use state 0 only.
Configure event0 to set CTOUT_0 (OUT0SET) and event0 to clear CTOUT_0 (OUT0CLR) and resolve
by setting RES to 'toggle' in case of conflict.
Configure switch matrix. Distinguish binary numbers/decimal numbers/hexadecimal numbers properly.

If you don't understand SCT, then re-read until you do. SCT is scaring at first, after some time it turns out to be cool and easy to
understand. You cannot learn by copy-and-paste-and-askTheForum-and-paste-again. Print the SCT chapter on paper. Read.
Read again. Understand what events, states, matches, captures, outputs, intputs can be used for. Don't start programming before
you understand that.
If you prefer hope to knowledge they you had better prefer preaching to programming  ;-)
0 Kudos

451 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Wed Jan 08 11:46:48 MST 2014
thx for your answer I’m new in arm m0 and i don’t understand sct very well its a peas of lpcxpresso samples i hope its work but its seams not :D
can you explain me how to create a timer whith 128khz 
0 Kudos

451 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by salamlora1 on Wed Jan 08 11:46:47 MST 2014
thx for your answer I’m new in arm m0 and i don’t understand sct very well its a peas of lpcxpresso samples i hope its work but its seams not :D
can you explain me how to create a timer whith 128khz 
0 Kudos

451 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MarcVonWindscooting on Wed Jan 08 08:28:31 MST 2014

Quote: salamlora1

    LPC_SWM->PINASSIGN6 |= (111<<24) ; // set the pin0_7 to output


That seems totally off to me. First the value 111, second the operation |= .
But also, you don't turn on the AHB clock of SWM befor using that.

And of course, you can implement your 120kHz toggle with one single state, one event, that both sets and clears CTOUT_0 and is resolved as toggle at this conflict.

You should explain a bit more, why you do it in that way.
0 Kudos