0-5V compass reference

Status
Not open for further replies.

DrWhoF

Advanced Member level 1
Joined
May 6, 2005
Messages
402
Helped
24
Reputation
48
Reaction score
11
Trophy points
1,298
Activity points
4,388
picaxe compass

I have to design a device which takes two 0-5V signals: one comes from 0-360° compass (reference) and one comes from an instrument from inside a tube.
Tube's heading is from the compass and instument's heading has to be calculated with reference to the compass and output as ASCII via serial port.
I need A/D conversion and then some maths to calculate true heading of the instrument.
Any help is highly appreciated.
DrWho
 

If you are happy with 10-bit conversion, you can do it with PICAXE-08M, which has three 10-bit A/D and serial port ..

Compass: 0-359deg <=> 0-5Vdc <=> 0-1023
Instrument: 0-359deg <=> 0-5Vdc <=> 0-1023

The absolute heading of the instrument can be calculated in the following way:

If [Compass] ≤ [Instrument] then [Result] = [Instrument] – [Compass]
If [Compass] > [Instrument] then [Result] = 1023 – ([Compass] – [Instrument])

To output [Resullt] in 0°-359° range you will have to multiply it by 360 and divide it by 1024, but in the PICAXE-BASIC this should not be a problem ..

Rgds,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Hi Ianp.
I don't have picaxe-08m but I have picaxe-18.
Can I use it and can you come up with some picaxe-basic code
Thanks
 

Try thie code:

Code:
' Micro: PICAXE-08M or PICAXE-18X
' input  1 [pin6] compass as reference [Ref]
' input  2 [pin5] encoder as instrument [Instr]

		setfreq m8					' serial speed 9600bps ..

start:
		readadc10 1, w0				' Compass as reference => Ref to w0
		readadc10 2, w1				' Encoder as instrument => Instr to w1

		if w0<=w1 then case1			' Res = Instr - Ref
		if w0>w1 then case2			' Res = 360 - (Ref - Instr)
		goto start

	case1:
		w2 = w1 - w0
		goto calc

	case2:
		w2 = 1023 - w0 + w1			' 0/359 => 0/1023 .. with 10-bit adc ..

	calc:
		w3 = w2 * 30				' 12 * 30 = 360
		w3 = w3 / 32				' 32 * 32 = 1024
		w3 = w3 * 12
		w4 = w3 / 32


		sertxd (#w4,$0D,$0A)			' send w4 as ASCII [#w4] 
								' string format: [w4 CR LF]
		pause 1000					' wait 1sec
	goto start

end

Should work with PICAXE-08M [8-pin] and, if you select the right inputs, with PICAXE-18X[18-pin] ..

Rgds,
IanP
 

    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
I will test it on Monday.
thx
:|
 

It is working fine but there is small problem when the instrument's potentiometer is between 5V and 0V (continous rotation): the reading can be anything between 0 and 359deg.
How can this be rectified?
DrWho
 


    DrWhoF

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…