Discussion in "PIC Microcontroller Discussion" started by    Anup Teke    Jul 21, 2014.
Mon Jul 21 2014, 01:08 pm
#1
Dear All,

I'm working on a project where I want to read DC Battery charging discharging Current from a shunt. For that I'm using MCP3901(it has differential input plus 24 bit resolution) and PIC18F46K22. I'm using Hi-Tech compiler demo and its SPI library. Reading and writing in to all internal registers is going well but when i read ADC Data registers (applied voltage at inputs is 5V ref is 2.37V) it should give me 0x7FFFFF i.e. full scale reading. But its giving me 0x7F7F7F. What should be the problem.

Kindly help me out.
Tue Jul 22 2014, 01:36 am
#2
That MCP3901 is a very complicated chip.
I have no idea what some of its settings do !
I'd advise you to use a simpler device, or use the ADC built into the 18F46K22.

A 10 bit resolution may not seem much compared to 24,
but I believe it is good enough in practise.

The 18F46K22 has many channels, so you could scale inputs with external
amplifiers to get good results.


[ Edited Tue Jul 22 2014, 04:18 am ]
Tue Jul 22 2014, 11:24 am
#3
are you sure your read is working properly? I mean you're not getting first byte again and again.
Tue Jul 22 2014, 11:49 am
#4
Wed Jul 23 2014, 12:58 pm
#5
Sir,

I was doing like this

MCP3901_CS = 0;
WriteSPI1(0x01);
TempData = ReadSPI1( );
TempData <<= 8;
TempData |= ReadSPI1( );
TempData <<= 8;
TempData |= ReadSPI1( );
MCP3901_CS = 1;

and my problem solved by doing like this

MCP3901_CS = 0;

WriteSPI1(0x01);
TempData = ReadSPI1( );
TempData <<= 8;
MCP3901_CS = 1;

MCP3901_CS = 0;

WriteSPI1(0x03);
TempData |= ReadSPI1( );
TempData <<= 8;
MCP3901_CS = 1;

MCP3901_CS = 0;

WriteSPI1(0x05);
TempData |= ReadSPI1( );

MCP3901_CS = 1;
Thu Jul 24 2014, 10:27 am
#6
I really do not understand why are you reading register 1, 3 and 5 register 1 belongs to CH0 and 3,5 belongs to CH1. I think you should read chapter 6.7 of datasheet for reading in continuous mode.
Thu Jul 24 2014, 10:38 am
#7
Ajay Sir,

CHannel 0 Register is 24 Bit. it register address is from 0x00 to 0x02. To read any register we have to send command with first bit 1(Read Bit). so to read CH0 register address will be 0x01 (MSB)
0x03(Middle Byte)
0x05(LSB).
Sat Jul 26 2014, 03:02 am
#8
I get it now.. Did not read that part, sorry for misunderstanding.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am