cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

NeDh_4602711
Contributor II

Hello,

I am a beginner in Cypress PSoC creator. I have 1 question. I am using the CY8CKIT-042-BLE pioneer kit with the CYBLE-022001-00 module and wondering to display time duration since CYBLE-022001-00 was started. 

Currently, I am doing this same with a different approach. I am using a counter variable and incrementing it by 1 after every CyDelay(100). If the counter reaches 10, then I considered as 1 second which is not a good way to do the same.
I don't want to connect any external device like RTC. Kindly help me to get milliseconds.
Thanks in advance.
0 Likes
1 Solution
MotooTanaka
Esteemed Contributor

Hi,

I think that SysTick would be handy for your purpose.

I posted a sample of using SysTick

Measuring time interval using SysTick (CY8CKIT-059/CY8CKIT-044)

I hope that this can be some hint for you.

moto

View solution in original post

7 Replies
MotooTanaka
Esteemed Contributor

Hi,

I think that SysTick would be handy for your purpose.

I posted a sample of using SysTick

Measuring time interval using SysTick (CY8CKIT-059/CY8CKIT-044)

I hope that this can be some hint for you.

moto

View solution in original post

NeDh_4602711
Contributor II

Hello Motoo Tanaka,

SysTick worked for me.

Thank you so much.

NeDh_4602711
Contributor II

My milliseconds doesn't match with the actual clock. What setting I should make in Clock in "Design Wide Resource"?Untitled.png

I noticed that due to the below function clock doesn't stay synch with the actual clock.

void LowPower(void)

{

    CYBLE_LP_MODE_T pwrState;

    CYBLE_BLESS_STATE_T blessState;

    uint8 intStatus = 0;

    if((CyBle_GetState() == CYBLE_STATE_ADVERTISING) ||

       (CyBle_GetState() == CYBLE_STATE_CONNECTED))

    {

        pwrState  = CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); /* Configure BLESS in Deep-Sleep mode */

        intStatus = CyEnterCriticalSection(); /* No interrupts allowed while entering system low power modes */

            blessState = CyBle_GetBleSsState();

            if(pwrState == CYBLE_BLESS_DEEPSLEEP) /* Make sure BLESS is in Deep-Sleep before configuring system in Deep-Sleep */

            {

                if(blessState == CYBLE_BLESS_STATE_ECO_ON || blessState == CYBLE_BLESS_STATE_DEEPSLEEP)

                {

                    CySysPmDeepSleep(); /* System Deep-Sleep. 1.3uA mode */

                }

            }

            else if (blessState != CYBLE_BLESS_STATE_EVENT_CLOSE)

            {

                 /* Change HF clock source from IMO to ECO, as IMO can be stopped to save power */

                CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_ECO);

                /* Stop IMO for reducing power consumption */

                CySysClkImoStop();

                /* Put the CPU to Sleep. 1.1mA mode */

                CySysPmSleep();

                /* Starts execution after waking up, start IMO */

                CySysClkImoStart();

                /* Change HF clock source back to IMO */

                CySysClkWriteHfclkDirect(CY_SYS_CLK_HFCLK_IMO);

            }

        CyExitCriticalSection(intStatus);

    }

}

13:05:51.526 ->Val : 1182

13:05:51.526 ->Val : 1196

13:05:51.526 ->Val : 1210

13:05:51.561 ->Val : 1223

13:05:51.561 ->Val : 1237

13:05:51.596 ->Val : 1251

13:05:51.596 ->Val : 1264

13:05:51.596 ->Val : 1278

13:05:51.630 ->Val : 1292

13:05:51.630 ->Val : 1305

13:05:51.664 ->Val : 1319

13:05:51.664 ->Val : 1333

13:05:51.664 ->Val : 1346

13:05:51.698 ->Val : 1360

13:05:51.698 ->Val : 1374

13:05:51.733 ->Val : 1387

13:05:51.733 ->Val : 1401

13:05:51.733 ->Val : 1415

13:05:51.767 ->Val : 1428

13:05:51.767 ->Val : 1442

13:05:51.801 ->Val : 1455

13:05:51.801 ->Val : 1469

13:05:51.801 ->Val : 1483

13:05:51.835 ->Val : 1496

13:05:51.835 ->Val : 1510

13:05:51.870 ->Val : 1524

13:05:51.870 ->Val : 1537

13:05:51.870 ->Val : 1551

13:05:51.905 ->Val : 1565

13:05:51.905 ->Val : 1578

13:05:51.939 ->Val : 1592

13:05:51.939 ->Val : 1606

13:05:51.939 ->Val : 1619

13:05:51.973 ->Val : 1633

13:05:51.973 ->Val : 1647

13:05:52.008 ->Val : 1660

13:05:52.008 ->Val : 1674

13:05:52.008 ->Val : 1688

13:05:52.041 ->Val : 1701

13:05:52.041 ->Val : 1715

13:05:52.075 ->Val : 1729

13:05:52.075 ->Val : 1742

13:05:52.075 ->Val : 1756

13:05:52.109 ->Val : 1770

13:05:52.109 ->Val : 1783

13:05:52.143 ->Val : 1797

13:05:52.143 ->Val : 1810

13:05:52.143 ->Val : 1824

13:05:52.177 ->Val : 1838

13:05:52.177 ->Val : 1851

13:05:52.212 ->Val : 1865

13:05:52.212 ->Val : 1879

13:05:52.212 ->Val : 1892

13:05:52.247 ->Val : 1906

13:05:52.247 ->Val : 1920

13:05:52.281 ->Val : 1933

13:05:52.281 ->Val : 1947

13:05:52.281 ->Val : 1961

13:05:52.314 ->Val : 1974

13:05:52.314 ->Val : 1988

13:05:52.349 ->Val : 2002

13:05:52.349 ->Val : 2015

13:05:52.349 ->Val : 2029

13:05:52.382 ->Val : 2043

13:05:52.382 ->Val : 2056

13:05:52.417 ->Val : 2070

13:05:52.417 ->Val : 2084

13:05:52.417 ->Val : 2097

13:05:52.450 ->Val : 2111

13:05:52.450 ->Val : 2125

13:05:52.483 ->Val : 2138

13:05:52.483 ->Val : 2152

13:05:52.483 ->Val : 2166

13:05:52.518 ->Val : 2179

13:05:52.518 ->Val : 2193

13:05:52.552 ->Val : 2206

13:05:52.552 ->Val : 2220

13:05:52.552 ->Val : 2234

13:05:52.586 ->Val : 2247

13:05:52.586 ->Val : 2261

13:05:52.621 ->Val : 2275

13:05:52.621 ->Val : 2288

13:05:52.621 ->Val : 2302

13:05:52.655 ->Val : 2316

13:05:52.655 ->Val : 2329

13:05:52.690 ->Val : 2343

13:05:52.690 ->Val : 2357

13:05:52.690 ->Val : 2370

13:05:52.725 ->Val : 2384

13:05:52.725 ->Val : 2398

13:05:52.759 ->Val : 2411

13:05:52.759 ->Val : 2425

13:05:52.759 ->Val : 2439

13:05:52.794 ->Val : 2452

13:05:52.794 ->Val : 2466

13:05:52.828 ->Val : 2480

13:05:52.828 ->Val : 2493

13:05:52.828 ->Val : 2507

13:05:52.861 ->Val : 2521

13:05:52.861 ->Val : 2534

13:05:52.896 ->Val : 2548

13:05:52.896 ->Val : 2562

13:05:52.896 ->Val : 2575

13:05:52.930 ->Val : 2589

13:05:52.930 ->Val : 2602

13:05:52.964 ->Val : 2616

13:05:52.964 ->Val : 2630

13:05:52.964 ->Val : 2643

13:05:52.998 ->Val : 2657

13:05:52.998 ->Val : 2671

13:05:53.031 ->Val : 2684

13:05:53.031 ->Val : 2698

13:05:53.031 ->Val : 2712

13:05:53.066 ->Val : 2725

13:05:53.066 ->Val : 2739

13:05:53.099 ->Val : 2753

13:05:53.099 ->Val : 2766

13:05:53.099 ->Val : 2780

13:05:53.134 ->Val : 2794

13:05:53.134 ->Val : 2807

13:05:53.168 ->Val : 2821

13:05:53.168 ->Val : 2835

13:05:53.168 ->Val : 2848

13:05:53.202 ->Val : 2862

13:05:53.202 ->Val : 2876

13:05:53.236 ->Val : 2889

13:05:53.236 ->Val : 2903

13:05:53.236 ->Val : 2917

13:05:53.270 ->Val : 2930

13:05:53.270 ->Val : 2944

13:05:53.305 ->Val : 2958

13:05:53.305 ->Val : 2971

13:05:53.305 ->Val : 2985

13:05:53.338 ->Val : 2999

13:05:53.338 ->Val : 3012

13:05:53.373 ->Val : 3026

13:05:53.373 ->Val : 3041

13:05:53.406 ->Val : 3055

13:05:53.406 ->Val : 3069

13:05:53.440 ->Val : 3083

13:05:53.474 ->Val : 3097

13:05:53.508 ->Val : 3111

13:05:53.543 ->Val : 3125

13:05:53.576 ->Val : 3139

13:05:53.610 ->Val : 3153

13:05:53.643 ->Val : 3167

13:05:53.677 ->Val : 3181

13:05:53.677 ->Val : 3194

13:05:53.711 ->Val : 3208

13:05:53.745 ->Val : 3222

13:05:53.778 ->Val : 3236

13:05:53.813 ->Val : 3250

13:05:53.847 ->Val : 3264

13:05:53.882 ->Val : 3278

13:05:53.915 ->Val : 3292

13:05:53.949 ->Val : 3306

13:05:53.982 ->Val : 3320

13:05:54.017 ->Val : 3334

13:05:54.017 ->Val : 3348

13:05:54.051 ->Val : 3362

13:05:54.085 ->Val : 3376

13:05:54.120 ->Val : 3390

13:05:54.154 ->Val : 3404

13:05:54.188 ->Val : 3418

13:05:54.221 ->Val : 3432

13:05:54.221 ->Val : 3445

13:05:54.255 ->Val : 3459

13:05:54.289 ->Val : 3473

13:05:54.323 ->Val : 3487

13:05:54.356 ->Val : 3501

13:05:54.390 ->Val : 3515

13:05:54.425 ->Val : 3529

13:05:54.459 ->Val : 3543

13:05:54.493 ->Val : 3557

13:05:54.527 ->Val : 3571

13:05:54.527 ->Val : 3585

13:05:54.562 ->Val : 3599

13:05:54.596 ->Val : 3613

13:05:54.630 ->Val : 3627

13:05:54.664 ->Val : 3641

13:05:54.699 ->Val : 3655

13:05:54.733 ->Val : 3669

13:05:54.768 ->Val : 3682

13:05:54.768 ->Val : 3696

13:05:54.802 ->Val : 3710

13:05:54.837 ->Val : 3724

13:05:54.872 ->Val : 3738

13:05:54.905 ->Val : 3752

13:05:54.940 ->Val : 3766

13:05:54.975 ->Val : 3780

13:05:55.009 ->Val : 3794

13:05:55.009 ->Val : 3808

13:05:55.042 ->Val : 3822

13:05:55.076 ->Val : 3836

13:05:55.111 ->Val : 3850

13:05:55.146 ->Val : 3864

13:05:55.180 ->Val : 3878

13:05:55.215 ->Val : 3892

13:05:55.249 ->Val : 3906

13:05:55.284 ->Val : 3920

13:05:55.318 ->Val : 3933

13:05:55.353 ->Val : 3947

13:05:55.353 ->Val : 3961

13:05:55.386 ->Val : 3975

13:05:55.421 ->Val : 3989

13:05:55.455 ->Val : 4003

13:05:55.489 ->Val : 4017

13:05:55.489 ->Val : 4031

13:05:55.523 ->Val : 4045

13:05:55.557 ->Val : 4059

13:05:55.592 ->Val : 4073

13:05:55.625 ->Val : 4087

13:05:55.660 ->Val : 4101

13:05:55.694 ->Val : 4115

13:05:55.728 ->Val : 4129

13:05:55.762 ->Val : 4143

13:05:55.795 ->Val : 4157

13:05:55.829 ->Val : 4171

13:05:55.864 ->Val : 4184

13:05:55.864 ->Val : 4198

13:05:55.898 ->Val : 4212

13:05:55.932 ->Val : 4226

13:05:55.966 ->Val : 4240

13:05:56.000 ->Val : 4254

13:05:56.033 ->Val : 4268

13:05:56.067 ->Val : 4282

13:05:56.067 ->Val : 4296

13:05:56.101 ->Val : 4310

13:05:56.135 ->Val : 4324

13:05:56.170 ->Val : 4338

13:05:56.205 ->Val : 4352

13:05:56.238 ->Val : 4366

13:05:56.273 ->Val : 4380

13:05:56.307 ->Val : 4394

13:05:56.342 ->Val : 4408

13:05:56.342 ->Val : 4422

13:05:56.375 ->Val : 4435

13:05:56.409 ->Val : 4449

13:05:56.442 ->Val : 4463

13:05:56.477 ->Val : 4477

13:05:56.512 ->Val : 4491

13:05:56.546 ->Val : 4505

13:05:56.580 ->Val : 4519

13:05:56.615 ->Val : 4533

13:05:56.650 ->Val : 4547

13:05:56.650 ->Val : 4561

13:05:56.685 ->Val : 4575

13:05:56.719 ->Val : 4589

13:05:56.753 ->Val : 4603

13:05:56.787 ->Val : 4617

13:05:56.821 ->Val : 4631

13:05:56.856 ->Val : 4645

13:05:56.856 ->Val : 4659

13:05:56.890 ->Val : 4673

13:05:56.924 ->Val : 4687

13:05:56.959 ->Val : 4701

13:05:56.992 ->Val : 4714

13:05:57.026 ->Val : 4728

13:05:57.060 ->Val : 4742

13:05:57.094 ->Val : 4756

13:05:57.129 ->Val : 4770

13:05:57.163 ->Val : 4784

13:05:57.198 ->Val : 4798

13:05:57.198 ->Val : 4812

13:05:57.233 ->Val : 4826

13:05:57.267 ->Val : 4840

13:05:57.301 ->Val : 4854

13:05:57.335 ->Val : 4868

13:05:57.335 ->Val : 4882

13:05:57.370 ->Val : 4896

13:05:57.405 ->Val : 4910

13:05:57.439 ->Val : 4924

13:05:57.474 ->Val : 4938

13:05:57.509 ->Val : 4952

13:05:57.544 ->Val : 4966

13:05:57.577 ->Val : 4980

13:05:57.610 ->Val : 4994

13:05:57.644 ->Val : 5008

13:05:57.678 ->Val : 5022

13:05:57.678 ->Val : 5035

13:05:57.712 ->Val : 5049

13:05:57.747 ->Val : 5063

13:05:57.781 ->Val : 5077

13:05:57.814 ->Val : 5091

13:05:57.848 ->Val : 5105

13:05:57.883 ->Val : 5119

13:05:57.883 ->Val : 5133

13:05:57.917 ->Val : 5147

13:05:57.952 ->Val : 5161

13:05:57.986 ->Val : 5175

13:05:58.021 ->Val : 5189

13:05:58.055 ->Val : 5203

13:05:58.090 ->Val : 5217

13:05:58.124 ->Val : 5231

13:05:58.157 ->Val : 5245

13:05:58.157 ->Val : 5259

13:05:58.192 ->Val : 5273

13:05:58.226 ->Val : 5287

13:05:58.260 ->Val : 5300

13:05:58.294 ->Val : 5314

13:05:58.329 ->Val : 5328

13:05:58.363 ->Val : 5342

13:05:58.397 ->Val : 5356

13:05:58.431 ->Val : 5370

13:05:58.466 ->Val : 5385

13:05:58.466 ->Val : 5399

13:05:58.500 ->Val : 5413

13:05:58.534 ->Val : 5427

13:05:58.568 ->Val : 5441

13:05:58.568 ->Val : 5455

13:05:58.602 ->Val : 5469

13:05:58.636 ->Val : 5483

13:05:58.670 ->Val : 5497

13:05:58.704 ->Val : 5511

13:05:58.738 ->Val : 5525

13:05:58.771 ->Val : 5539

13:05:58.771 ->Val : 5553

13:05:58.805 ->Val : 5567

13:05:58.839 ->Val : 5581

13:05:58.873 ->Val : 5595

13:05:58.908 ->Val : 5609

13:05:58.943 ->Val : 5623

13:05:58.977 ->Val : 5636

13:05:59.011 ->Val : 5650

13:05:59.046 ->Val : 5664

13:05:59.046 ->Val : 5678

13:05:59.080 ->Val : 5692

13:05:59.115 ->Val : 5706

13:05:59.150 ->Val : 5720

13:05:59.185 ->Val : 5734

13:05:59.218 ->Val : 5748

13:05:59.251 ->Val : 5762

13:05:59.285 ->Val : 5776

13:05:59.319 ->Val : 5790

13:05:59.353 ->Val : 5804

13:05:59.388 ->Val : 5818

13:05:59.423 ->Val : 5832

13:05:59.423 ->Val : 5846

13:05:59.457 ->Val : 5860

13:05:59.492 ->Val : 5874

13:05:59.526 ->Val : 5888

13:05:59.560 ->Val : 5901

13:05:59.560 ->Val : 5915

13:05:59.594 ->Val : 5929

13:05:59.628 ->Val : 5943

13:05:59.663 ->Val : 5957

13:05:59.697 ->Val : 5971

13:05:59.731 ->Val : 5985

13:05:59.765 ->Val : 5999

13:05:59.798 ->Val : 6013

13:05:59.833 ->Val : 6027

13:05:59.867 ->Val : 6041

13:05:59.902 ->Val : 6055

13:05:59.902 ->Val : 6069

13:05:59.936 ->Val : 6083

13:05:59.971 ->Val : 6097

13:06:00.005 ->Val : 6111

13:06:00.040 ->Val : 6125

13:06:00.074 ->Val : 6139

13:06:00.074 ->Val : 6153

13:06:00.109 ->Val : 6167

13:06:00.144 ->Val : 6181

13:06:00.179 ->Val : 6194

13:06:00.179 ->Val : 6208

13:06:00.213 ->Val : 6222

13:06:00.247 ->Val : 6236

13:06:00.282 ->Val : 6250

13:06:00.315 ->Val : 6264

13:06:00.350 ->Val : 6278

13:06:00.383 ->Val : 6292

13:06:00.383 ->Val : 6306

13:06:00.417 ->Val : 6320

13:06:00.451 ->Val : 6334

13:06:00.485 ->Val : 6348

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

If you are using DeepSleep, keeping time may be difficult.

The IMO will be stopped and ILO or WDT will keep working

but as you can see, their accuracy is not very good unless you connect external WCO (32K).

FYI, In the CyLib.c I found void CySysTickInit(void).

In that function, if you set CY_SYSTICK_LFCLK_SOURCE,

        CySysTickSetClockSource(CY_SYS_SYST_CSR_CLK_SRC_SYSCLK);

will be called.

So SysTick may keep counting, but the accuracy won't be as good as with the IMO or external RTC.

moto

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

I've been thinking about this last night.

As I wrote, I'm afraid that I don't have much knowledge about this specific question.

And since you marked my response as "Correct Answer" (Thank you for that though).

not many will be reading this topic.

So I would suggest you to post a new question, with a tile which has words something like below

DeepSleep, milliseconds, keep track of,

moto

NeDh_4602711
Contributor II

Thanks for your response.

As you mentioned I have added new question with subject "Deepsleep causes SysTick milliseconds to lag? ".

Shall I delete the above post? or let it be?

Thank you so much.

MotooTanaka
Esteemed Contributor

Dear NeDh-san,

Thank you very much for taking my suggestion.

The new question with a new title should get more attention from other members of the community.

So I hope that you will get response from people with more knowledge about this topic.

Meantime, for the previous discussion(s), I think it's OK to leave it as is.

(It may be helpful when others want to know the path to the new question, too).

Best Regards,

1-Jun-2020

Motoo Tanaka