Exact timestamp on AD measurements ?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
PicoPuls
Posts: 111
Joined: Wed Mar 02, 2016 11:26 am
Has thanked: 43 times
Been thanked: 22 times

Exact timestamp on AD measurements ?

Post by PicoPuls »

I need to make 16 AD measurements rapidly and to give this array of measurments a timestamp.

This package of 16 measurements is then repeated 300 times
and the time in ms or us is needed between the present and the very first package.

Can that be done in a smart way in Flowcode
with simplicity and speed
perhaps based on the internal processor clock ?


Best regards
BO

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Exact timestamp on AD measurements ?

Post by Benj »

Hello,

If I were doing it I would probably do something like this.

Create a 16/32-bit count variable and initialise it to 0.
Enable a timer interrupt based off the internal clock, preferably a 16-bit timer such as Timer1 on an 8-bit PIC.
Inside the timer interrupt macro increment the count variable.

When taking ADC samples first take a copy of the count variable and the timer count register, this then makes up your time stamp.

Say the timer interrupt was interrupting at 1Hz (probably pretty unlikely unless you can provide the exact crystal frequency required).
The timer count register would represent 1:65536th of a second (16-bit timer)
The count variable would be the number of seconds.

A 16-bit count variable would give you a max time period of 18.2 hours with a 1s interrupt rate.
A 32-bit count variable would give you a max time period of 139 years with a 1s interrupt rate.

stefan.erni
Valued Contributor
Valued Contributor
Posts: 654
Joined: Fri Aug 19, 2016 2:09 pm
Location: switzerland
Has thanked: 182 times
Been thanked: 179 times

Re: Exact timestamp on AD measurements ?

Post by stefan.erni »

What about the RTCC (Real-Time Clock/Calendar )? Some PIC have one included. If the timestamp is in seconds or minutes .... it's nice to use.
Is there a samplecode to use microchips rtcc?

Post Reply