How can I keep track of milliseconds passed since processor has been running? (akin to millis() for Arduino)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am using the PSoC Creator 4.2 and am implementing a PID control block that requires the number of milliseconds passed since the processor has been on/program has been running.  Originally, I was using this PID library for Arduino Mega 2560 that required that information but I do not have the knowledge to write it up for PSoC. 

How would I be able to do this (or mimic the "millis()" function in Arduino)?

Thank you very much,

Anthony

0 Likes
1 Solution
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

I'm with BoTa, there shouldn't be any need to know the time since start. However, if you still need to have this information, you can hook up to the SysTick timer, which is configured to 1ms by default.

The boot component provides the mechanics to do this. You can hook up up to five callbacks. So, you can write a callback and increment a variable each time it is called. Keep in mind that the variable must be defined volatile. I don't know how it's implemented in Arduino, but going the mentioned way would mean that the mechanism begins to work after the call to the callback configuration. So it's still not the time from (power) on or reset.

You can find the information about the relevant functions in system reference guide for your device.

Regards

View solution in original post

0 Likes
2 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Anthony,

I believe that PID algorithm doesn't need knowledge of time since start. Oftenwise, PID code is time-invariant, and might not need timescale at all. For example, timing comes from ADC sampling which runs on its own clock.

I recommend to post your project here for review. File->Create Workspace bundle->minimal.

/odissey1

0 Likes
RaAl_264636
Level 6
Level 6
50 sign-ins 25 sign-ins 10 solutions authored

I'm with BoTa, there shouldn't be any need to know the time since start. However, if you still need to have this information, you can hook up to the SysTick timer, which is configured to 1ms by default.

The boot component provides the mechanics to do this. You can hook up up to five callbacks. So, you can write a callback and increment a variable each time it is called. Keep in mind that the variable must be defined volatile. I don't know how it's implemented in Arduino, but going the mentioned way would mean that the mechanism begins to work after the call to the callback configuration. So it's still not the time from (power) on or reset.

You can find the information about the relevant functions in system reference guide for your device.

Regards

0 Likes