SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By jasonharper
#42660
Tilt the unit on all axes, making a note of the extreme largest and smallest values you can achieve on each axis.

If the min & max on any one axis do not have the same magnitude, that's one problem.

If each axis is balanced, but their max magnitudes are different, that's another problem.

If all axes are balanced and have close to the same magnitude, yet your sum-of-squares still isn't constant, that's a third problem.

Which is it?
By e5kjetil
#42677
Analyzing the numbers at /128 divisor,

z axis seems to have a bottom at -150 but the top seems to be at 130.
y axis seems to stay in the 45 to 65 range in all orientations (must be totally garbage).
x axis seems to have a bottom of -95, a top of 95. The kind of reading I was hoping to get from the other axes..

All axes respond to a small magnet being moved along the axis.

EDIT: the same trend seems to apply with other divisors. Y axis measurement doesn't make *any* sense..
By e5kjetil
#42684
A strange observation on the y axis; when a magnet is moved along the axis (/256 divisor), the reading increases unntil the magnet is about 3cm from the sensor. This is a peak in the reading (around 3000) and when the magnet has moved even closer, the reading has dropped to around 500. Can anyone interprent anything from this strangeness?
By mistral
#42739
I've seen that you are using C30 compiler and hardware SPI.
Could you show how you send and receive data throuth SPI, becouse the hardware SPI clocks in the data just after the "command" is send (or in the middle). Also the command is 8 bit length and the answer from micromag is 16 bit length. I don't know how to do that.

If you could help me I'll apreciate this
Last edited by mistral on Thu Feb 14, 2008 4:57 am, edited 1 time in total.
By e5kjetil
#42747
mistral wrote:I've seen that you are using C30 compiler and hardware SPI.
Could you show how you send and receive data throuth SPI, becouse the hardware SPI clocks in the data just after the "command" is send (or in the middle). Also the command is 8 bit length and the answear from micromag is 16 bit length. I don't know how to do that.

If you could help me I'll apreciate this
OK, you've seen the setup.. 8-bit non-sync.. I use a SPI readwrite function writing a byte and returning the response:
Code: Select all
unsigned char WriteSPI(unsigned char WriteByte) {

	unsigned char RecvByte;

	SPI1BUF=WriteByte & 0xFF;

  	while(SPI1STATbits.SPITBF);	// Ensure that SPITBF buffer clears before we proceed,
	while(!SPI1STATbits.SPIRBF);	//make sure recieve buffer is full..	
	IFS0bits.SPI1IF = 0;		// clear interrupt flag

	SPI1STATbits.SPIROV = 0;	// clear overflow flag if set

	RecvByte = SPI1BUF;			// read recieved data, hardware clears SPIRBF bit

	return RecvByte;

}
I reset the MicroMag,
I send a command to the MicroMag by

Code: Select all
unsigned char cmd = (sensitivity << 4) | axis;
unsigned char dummyretval = WriteSPI(cmd);
Then, when the DRDY interrupt triggers, I read two bytes, putting them together to the 16-bit signed form:
Code: Select all
unsigned char Hbyte = WriteSPI(0x00);
unsigned char Lbyte = WriteSPI(0x00);
Mag[axis] = (int)(0x100 * Hbyte) | (int)Lbyte
In my case, I'm starting to lean towards a hardware error. The Y axis does not seem to respond unless a very high magnetic field is applied, it simply outputs "noise" when rotated around, the numbers bear no or little resemblence to the orientation. I've had it with this module.. I've spent money and time on it, and it turns out it doesn't even work. Like the USB bit whacker I ordered with it that came with a blank chip. :evil:
By mistral
#42748
First of all thanks for your answer:)

I've got one question.

After receiving the DRDY singal you are sending two zero commands.
And here are my doubts, becouse sending command in 8 bit mode, need 8 clock cycles to be send and immediately after this there are clocked next 8 cycles to get data from slave (micromag).

Am I right?

So if you send such a command after receiving DRDY singal you may lost your data?

As you said your code is working, so be so kind and say where is a mistake in my concept.
Last edited by mistral on Thu Feb 14, 2008 4:58 am, edited 1 time in total.
By e5kjetil
#42758
mistral wrote:After receiving the DRDY singal you are sending two zero commands.
Yes. The value of these bytes doesn't matter, they hold no information used by the micromag. Micromag will throw them away just like we do with the response we get when writing the command byte.
mistral wrote:And here are my doubts, becouse sending command in 8 bit mode, need 8 clock cycles to be send and immediately after this there are clocked next 8 cycles to get data from slave (micromag).

Am I right?
No.

SPI is a full duplex transfer, so each SPI clock cycle one bit is shifted out on the <data out> line, while another bit is shifted in on the <data in> line. Since 1 bit is sent and 1 bit recieved per SPI clock cycle, then 8 cycles would be required to exchange a byte over the SPI bus. Read up on SPI (Serial Peripheral Interface) on Wikipedia or some other source.

The micromag communicates the measurement with a 2-byte response, so two reads (and writes) are required. You see, that is why we write two dummy bytes to get the measurement bytes, because to read from the SPI bus you also have to write.
By mistral
#42768
Thanks
I read the wikipedia and there is everything as you said.

So concluding when you are in 8 bit mode writing byte to the SPIBUF
causes 8 clock cylces (in non Frame suported mode on dspic) and in this
8 cycles you send a command and receive a byte of data.(So sending command and answer reception takes only 8 clock cycles) That would by clear for me, but what for is the SMP bit in SPIxCON register
bit 9 SMP: SPI Data Input Sample Phase bit
Master mode:
1 = Input data sampled at end of data output time
0 = Input data sampled at middle of data output time
I understand this in other way. As I wrote befor

SMP=1 -> 8 clock cycles to send + 8 clock cycles to receive
SMP=0 -> 8 clock cycles to send + 4 clock cycles to receive the secound half of the answer byte


Sorry for my not understanding, but I realy want that to be clear for me
By e5kjetil
#42769
No, regardless of the SMP configuration, the transfer is over in 8 cycles. The SMP bit merely determines where in a cycle the input line is sampled. The input line cannot be sampled at the exact moment the slave device writes to it - you will get into timing trouble (master reads line before data is written to the line reading erroneous data). Sample it half a cycle after it has been set by the slave and you will get the correct reading. SMP is for adjusting this.

Please refer to the SPI section of the dsPIC30F Family Reference Manual for details on the SPI configuration registers.
By mistral
#42770
All my doubts are becouse of this ds 30f family and the SMP bit I mentioned befor.

So the whole transfer take 8 clock cycles and that is all.

Thank you for everything
By e5kjetil
#42896
No further tips except OT oddities? Well, I guess that spells the end of my MicroMag3. Perhaps I'll use it in a 2-axis compass one day...

I better get a real magnetic sensor..
By rkrishnan7
#65952
It's been a year - I wonder if you tossed off the MicroMag 3 or smehow found a solution ?
If you picked another sensor, which one ? Honeywell ?

Thanks for posting the results of your work - very helpful, especially the weird SPI16 vs. SPI8 part...