Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:32 29 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : synchronized frequency measurements

Author Message
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2289
Posted: 02:56am 17 Jul 2015
Copy link to clipboard 
Print this post

hi,
this question is mainly for geoff, though with all the porting of mmbasic that has been going on it is quite possible someone else may also know the answer.

i need to measure the frequency outputs from TWO attached fluxgate magnetometers, where the frequencies can vary from around 30kHz up to about 140kHz. it is important that each pair of measurements are unique (no 'doubling up' where one or both are duplicated from the previous pair), are made over the exact same period, and that as much resolution as possible is retained.

to achieve this, i configure the two input pins, wait for 1.5 measurement periods (1500mS) to elapse, then print the frequencies returned from the pins every subsequent period (1000mS). see the below code.

my question is - will this work and keep in sync with the internal frequency count updates made by the mmbasic interpreter? if not, is there any other solution?

a while back i recall suggesting some sort of 'completed' flag be implement on these types of events. in the case of pins configured as FIN, this could be achieved with the syntax
f% = Pin(15, BLOCK)
to indicate that a value should not be returned until updated since the last read was made.


period% = 1000
SetPin 15, FIN, period%
SetPin 18, FIN, period%
Timer = period% / 2
Pause period%

Do
Do: Loop Until (Timer Mod period%) < (period% / 2)
Do: Loop Until (Timer Mod period%) > (period% / 2)

f1% = Pin(15)
f2% = Pin(18)
print f1%, f2%
Loop


cheers,
rob :-)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 03:20am 17 Jul 2015
Copy link to clipboard 
Print this post

Yes, it will stay in sync because all timing is done using the one timing base (a 1mS tick). This includes Timer and the frequency measurement.

A simpler program would be this:

period% = 1000
SetPin 15, FIN, period%
SetPin 18, FIN, period%
Pause period% * 1.5
SetTick period%, TickInt

Do : Loop

Sub TickInt
f1% = Pin(15)
f2% = Pin(18)
print f1%, f2%
End Sub

Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2289
Posted: 03:29am 17 Jul 2015
Copy link to clipboard 
Print this post

excellent! thanks geoff

cheers,
rob :-)
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8583
Posted: 03:31am 17 Jul 2015
Copy link to clipboard 
Print this post

Robert

Based on my reading of the code there is a high probability that the readings will be in synch. The measurement periods are controlled in the 1msec clock interrupt and given that the two setpin commands are next to each other and probably only take say 1/20000 seconds to execute then it is highly likely (19 in 20 = 95%)that the measurement periods for each will end on the same clock tick.

To be certain of this here are a couple of trivial Cfunctions to stop the clock and start the clock. The demo demonstrates that the clock is stopped while the first loop is run and then is working again when the second is run.

Remember not to use the very first pair of readings but after that they should be perfectly in synch

option explicit
option default none
cpu 100
dim integer i,j, k
timer=0
i=stopclock()
for j=0 to 10000: k=j*j :next j
print timer
i=startclock()
for j=0 to 10000: k=j*j :next j
print timer
end
CFunction stopclock
00000000
3c030008 3c02bf88 ac431064 3c02bf88 ac401068 03e00008 00000000
End CFunction 'MIPS32 M4K
CFunction startclock
00000000
3c020008 3c03bf88 ac621064 3c03bf88 ac621068 03e00008 00000000
End CFunction 'MIPS32 M4K
'
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 03:36am 17 Jul 2015
Copy link to clipboard 
Print this post

I had to look up a fluxgate magnetometer to see what it was. At first I thought that it was related to a flux capacitor.

Geoff
Geoff Graham - http://geoffg.net
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2289
Posted: 03:58am 17 Jul 2015
Copy link to clipboard 
Print this post

thanks peter. in my application, the odd millisecond won't matter, but i shall file away those custom functions for later application!

the term "fluxgate magnetometer" is indeed quite impressive, and a mouthful to use frequently in conversation without laughing. the devices i've been working with (FGM-3) are made by a little company in wales:
http://www.speakesensors.com/products.htm

the trick is to mount two of them about 1/2 a metre apart to a pole, aligned as exactly as possible so that the earth's magnetic field affects them both identically. you then measure the frequency difference between them, which becomes your 'reference point'. if you then bring the end of the pole near to a (buried) metal object, the closest sensor will be affected far more than the other - you will see the frequency difference change.

this gives you a type of (ferrous) metal detector that is of use in archaeology. you create a grid over your site, and take measurements over the grid (with the pole vertical to the ground), plot the results, which will (all going well) give you a map showing what lies beneath the ground. this is useful for things like finding the slate floor of a long-gone dwelling - or so i am led to believe.

cheers,
rob :-)
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024