I would like to measure the time of command

Hi there, Hope you all are well.

I am building a PTZ Camera through Pelco D for which I need to do speed variation with respest to zoom.

The only way, I am thinking of is to measure the time, the serial data for zoom command is coming.

When ever I click for zoom, this command "FF 01 00 20 00 00 21" for 3.5 sec ( 1x to 26x zoom) followed by stop command "FF 01 00 00 00 00 01" when I release the zoom button.

How can I measure the time of my zoom command.

The reference code is as under.

BOB-TMC-5041 - Zoom.zip (3.0 KB)

Make a note of the time (millis) when you get the zoom command and also when you get the stop command. The difference is your duration in ms

In addition to "software" method, introduced by @J-M-L , I can suggest a "hardwire" one.
Choose any free pin, in the first command apply a high level to it, in the second low - and see the pulse on an oscilloscope or logic analyzer. This method is good because it does not require a monitor and can measure durations in fractions of a microsecond.

It requires an oscilloscope which is less frequent in the tinkerer kits :slight_smile:

that's why I say that my method is only addition to yours :slight_smile:

I have implemented something similar to it. It is working now. Thanks alot

Thanks alot. Let me check into it. I have implemented the method mentioned by @J-M-L ... It is working for my application. Thanks alot

If you use a modern AVR (post2016 revolution, 4808/9, tinyAVR 0/1/2 and DA/DB/DC) just use a timerB - or two in cascade mode (tiny2 and Dx only] and measure uip to 234 * system clocks (divide low clock by 2, then use the ovf bit for high bit

I don't need the cascade for my testing, I was trying to figure out how fast a piece of code ran in the tens or hundreds of clock cycles to run so it'd kick off a timer immediately before starting the test in pulse width measurement mode.

[AVR-Guidance/AVR_Math_speed.md at master · SpenceKonde/AVR-Guidance · GitHub](AVR math speed measured that way)
[AVR-Guidance/Fast_Math_Tricks.md at master · SpenceKonde/AVR-Guidance · GitHub](advise on seeding mathematics)

It may look like a toy, but an instrument you shoukd ask Santa Claus for one day is this

https://www.jameco.com/z/LA-USB-Hiletgo-24MHz-8-Channel-USB-Logic-Analyzer_2319143.html

You can pay more or less, google

 24 MHz 8 bit logic analyzer

and look around.

Works with free software for your desktop or laptop machine.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.