MCP3901 and PIC18F46K22
Discussion in "PIC Microcontroller Discussion" started by Anup Teke Jul 21, 2014.
Mon Jul 21 2014, 01:08 pm
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.
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
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.
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
are you sure your read is working properly? I mean you're not getting first byte again and again.
Wed Jul 23 2014, 12:58 pm
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;
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
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
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).
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).
Powered by e107 Forum System