Software timer

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

Software timer

2,457件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bhallett on Thu Jun 03 02:03:43 MST 2010
Hello all,

I am looking to create a software timer that does not use any of the timers supplied in the LPC1342 microcontroller. I am thinking of reading a ram, rom, or flash location a number of times in order to make up a specific time period (i.e. using the access time of these devices). Has anyone achieved this under the ARM/Thumb2 environment programmed in C?

Regards

Barry
0 件の賞賛
返信
8 返答(返信)

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xinbadaz on Thu Aug 11 23:34:35 MST 2011
the delay function realy helps a lot.:)

but i found that after i build the program using [B][COLOR=Red]Realse Mode[/COLOR][/B], and the DelayuS() actually takes twice longer.:confused:

i wonder whether i can turn off the optimization, just for the DelayuS()???
0 件の賞賛
返信

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micrio on Thu Jun 03 16:32:52 MST 2010
The problem is with the "subs". The last "s" means update the CPU status flags. In M3 processors updating the status flags is optional, in M0 processors it is not. Thus "sub" works just fine.
0 件の賞賛
返信

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Jun 03 14:50:56 MST 2010

Quote: micrio
Do you have a high resolution delay routine for M0 Cortex?

subs r3, #1

This is not supported in Thumb16.



I haven't actually tried this out with the tools, but I suspect that you need to add [I].syntax unified / divided[/I] around the assembler code in order to get it to build. For more info, see:

http://knowledgebase.nxp.com/showthread.php?p=1779

in particular, http://knowledgebase.nxp.com/showpost.php?p=1766&postcount=2

Regards,
CodeRedSupport
0 件の賞賛
返信

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micrio on Thu Jun 03 14:34:06 MST 2010
Do you have a high resolution delay routine for M0 Cortex?

subs r3, #1

This is not supported in Thumb16.
0 件の賞賛
返信

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Thu Jun 03 13:40:22 MST 2010

Quote: bhallett
Hello all,

I am looking to create a software timer that does not use any of the timers supplied in the LPC1342 microcontroller. I am thinking of reading a ram, rom, or flash location a number of times in order to make up a specific time period (i.e. using the access time of these devices). Has anyone achieved this under the ARM/Thumb2 environment programmed in C?

Regards

Barry



It is nearly impossible to create an accurate delay loop in C that is stable over changing compiler versions and optimization settings.

This code may be helpful for shorter time delays. For longer time delays, maybe you could use the SysTick timer built into the Cortex M0/M3 core. It is independent from the CT16B0/1 and CT32B0/1 timers. Using the SysTick timer, if you set up a 10 mS interrupt and a counter, you could go into sleep mode and save power while waiting.


// Microsecond delay loop-
void DelayuS(uint32_t uS)
{
    uint32_t CyclestoLoops;

    CyclestoLoops = SystemCoreClock;
    if(CyclestoLoops >= 2000000)
    {
        CyclestoLoops /= 1000000;
        CyclestoLoops *= uS;
    } else
    {
        CyclestoLoops *= uS;
        CyclestoLoops /= 1000000;
    }

    if(CyclestoLoops <= 100)
        return;
    CyclestoLoops -= 100; // cycle count for entry/exit 100? should be measured
    CyclestoLoops /= 4; // cycle count per iteration- should be 4 on Cortex M0/M3

    if(!CyclestoLoops)
        return;

    // Delay loop for Cortex M3 thumb2
    asm volatile (
        // Load loop count to register
        "      mov  r3, %[loops]\n"

        // loop start- subtract 1 from r3
        "loop: subs r3, #1\n"
        // test for zero, loop if not
        "      bne loop\n\n"

        : // No output registers
        : [loops] "r" (CyclestoLoops) // Input registers
        : "r3" // clobbered registers
    );
}
0 件の賞賛
返信

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by domen on Thu Jun 03 10:10:09 MST 2010
Check out:

arm cortex-m3 technical reference manual

arm architecture v7m reference manual
0 件の賞賛
返信

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bhallett on Thu Jun 03 09:24:56 MST 2010
Thanks for the info micrio

If I where to loop a nop x number of times could I achieve a longer delay?

Also, does anyone know where I can find the assembly instruction execution cycle times ?

Regards

Barry
0 件の賞賛
返信

2,427件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micrio on Thu Jun 03 08:32:01 MST 2010
If you want a short delay you can use a NOP instruction. You can
code it this way in C:

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]asm[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"NOP"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][SIZE=2][COLOR=#3f7f5f][/LEFT]
[/COLOR][/SIZE]
0 件の賞賛
返信