- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I'm trying to use the gettimeofday function. My project compiles and builds without error. In the code, I initialize the members of the struct timeval tv (tv.tv_sec and tv.tv_usec) to 0 and then call gettimeofday. After calling gettimeofday, I examine tv.tv_sec and tv.tv_usec and they are still 0. Is function gettimeofday not supported?
A little more information... I am trying to create a delay function that will delay on the order of microseconds. Here is a code snippet:
gettimeofday(&tvStart, NULL);
usecStart = tvStart.tv_sec * 1000000 + tvStart.tv_usec;
do
{
gettimeofday(&tvNow, NULL);
usecDiff = tvNow.tv_sec * 1000000 + tvNow.tv_usec - usecStart;
}
while (usecDiff < DelayInMicroSeconds);
Thanks,
BB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, BB.
Since you do not have an OS on a PSoC the gettimeofday() will not work as you expect. Think about using the RTC component.
On the other hand, there is already a CyDelayUs() API. Check the "System Reference Guide" (from Creator -> Help).
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the quick reply. Makes sense. I didn't know if the PSoC maybe did some tricks to make functions like that work. And thanks for the tip on the CyDelayUs(). I'm still kicking the tires on this thing and getting an idea of how it behaves.
BB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just in a few sentences: PSoCs consist of an ARM processor with moderate speed, flash and sram and real routable internal hardware.
With that hardware a handful (PSoC5: more than 100) of components are built that can be put onto a schematic and routed as required.
When using PSoCs with internal UDBs (Universal Digital Block) you even might use a hardware definition language (Verilog) to build your own hardware components. There are analog components as opamps, ADCs, DACs, comparators, S&Hs, analog MUXes. There are digital ORs, ANDs, NOTs and whatever you need. Use them, think PSoC. There are a couple of video tutorials that will help you starting off. Get hands on one (or two) of the prototyping kits for PSoC4 or even better the PSoC5.
Happy coding
Bob