So I've been waiting for 10 days for my new boards to arrive... they got here about 20 minutes ago.
I've set up a test for my application - what I got these things for - and am initially quite disappointed with the results, so am asking here for any tips, hints or suggestions.
I need to measure the frequency "fairly accurately" of a source. It's a TTL signal of variable duty cycle and variable frequency. I'm only interested in the frequency.
So I connected the board - no temperature sensors, no A/D inputs. The ONLY thing connected is my signal source.
I wrote a small piece of code, as follows:
The code is intended to do nothing apart from sit in a very tight loop waiting for a second transition. The moment it detects the transition it sets var1 to the current counter value and immediately clears the counter. There are no branches, decisions, calculations etc that may introduce timing variabilities here, intentionally to keep the loop times as near identical as possible.
Once it has the counter safely stored in var1, it checks to see if we've just transitioned to the first second of a new minute (if seconds WERE 59, we must NOW be 0) - and will reset the "minimum" (var2) and "maximum" (var3) counters to the current value. Each other pass, it simply compares and updates the minimum and maximum count.
The program them drops out the bottom and restarts - where it goes back into the loop to catch the second change again.
I'm feeding it a constant signal of around 120KHz at the moment, and here's the output:
32 Bit Signed Vars 121641 106485 128908 0 0 0 0
A variability from 106,485 to 128,908 is HUGE - unusably so.
How can I improve this, because quite honestly - it's useless like this!
I've set up a test for my application - what I got these things for - and am initially quite disappointed with the results, so am asking here for any tips, hints or suggestions.
I need to measure the frequency "fairly accurately" of a source. It's a TTL signal of variable duty cycle and variable frequency. I'm only interested in the frequency.
So I connected the board - no temperature sensors, no A/D inputs. The ONLY thing connected is my signal source.
I wrote a small piece of code, as follows:
Code:
start
set ram1 cs
secwait:
tsteq ram1 cs
goto secwait
set var1 counter
set counter 0
tsteq ram1 59
set var2 var1
tsteq ram1 59
set var3 var1
tstlt var1 var2
set var2 var1
tstgt var1 var3
set var3 var1
end
The code is intended to do nothing apart from sit in a very tight loop waiting for a second transition. The moment it detects the transition it sets var1 to the current counter value and immediately clears the counter. There are no branches, decisions, calculations etc that may introduce timing variabilities here, intentionally to keep the loop times as near identical as possible.
Once it has the counter safely stored in var1, it checks to see if we've just transitioned to the first second of a new minute (if seconds WERE 59, we must NOW be 0) - and will reset the "minimum" (var2) and "maximum" (var3) counters to the current value. Each other pass, it simply compares and updates the minimum and maximum count.
The program them drops out the bottom and restarts - where it goes back into the loop to catch the second change again.
I'm feeding it a constant signal of around 120KHz at the moment, and here's the output:
32 Bit Signed Vars 121641 106485 128908 0 0 0 0
A variability from 106,485 to 128,908 is HUGE - unusably so.
How can I improve this, because quite honestly - it's useless like this!