Half Second Timer needed - read GPIO for every Half second

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

Half Second Timer needed - read GPIO for every Half second

Jump to solution
2,662 Views
TVNAIDU
Contributor III

Need to add smal pioece of code to read GPIO for every Half second code, any timer I can invoke from task to read fro every Half-second?.

 

appreciated.

Labels (1)
0 Kudos
Reply
1 Solution
1,601 Views
TVNAIDU
Contributor III
Thanks Yevgeni. appreciated.

View solution in original post

0 Kudos
Reply
7 Replies
1,601 Views
admin
Specialist II

For interval of half a second, 32-bit timer needs to be used.

 

Alternatively, you can count the OS ticks (the default is 50 ms).

 

0 Kudos
Reply
1,601 Views
TVNAIDU
Contributor III

Thanks, can I crwate a separate task for this, in main function in for loop, can I use tk_sleep for Half second, that way, task collects data for every Half second.

 

task_main_fn()

{

 

      for(;:smileywink: {

       collect GPIO data and do process....

      tk_sleep(half-second);

      }

 

}

0 Kudos
Reply
1,601 Views
admin
Specialist II
Yes, it is the simplest solution: the dedicated task, which reads and processes GPIO and then sleeps for half a second.
0 Kudos
Reply
1,602 Views
TVNAIDU
Contributor III
Thanks Yevgeni. appreciated.
0 Kudos
Reply
1,601 Views
TVNAIDU
Contributor III

Hi Yevgeni:

 

I have to take 840 samples per second, if I keep for loop for 840 then if I keep tk_sleep, not sure when it finishes, for example I have to measure 24 receptacles instantaneous current and voltage for 840 samples per second, is there any way I can measure makesure 840 samples can take within one second, can I use times to happen 840 samples per second exactly without putting task in sleep using tk_sleep?

0 Kudos
Reply
1,601 Views
admin
Specialist II

TVNAIDU,

let discuss sampling the analog values in the separate thread.

Coukd you, please, open the new thread with the descriptive name?

 

0 Kudos
Reply
1,601 Views
TVNAIDU
Contributor III

Yes yevgenit, I opened another thread "Sampling of Analog values". Please take a look.

 

thanks.

0 Kudos
Reply