Programming a Digital Current and Power Monitor on PIC18F26K80

Thread Starter

D1NG0

Joined Jul 28, 2021
7
Hi, I'm on a project where I would like to measure a battery voltage. For that, I have to use a Digital Current and Power Monitor, called INA260. I already have a board made and it's functional because I've already tested it with the arduino, but I'm not able to do the programming on the PIC18F26K80. Can anyone help me?
 

Attachments

click_here

Joined Sep 22, 2020
439
First step is to draw out a rough circuit with your pic and write down what I/O you want to use, which pins you need, ect... It will make coding easier with a hardware plan.

Don't forget voltage regulator and ICSP pins.

Did you want to use the internal osc, or an external?

Next step is to go to the PIC datasheet and decide what you want/need to use.

This is where you decide how fast you need the osc, find out how to implement the ultra low power mode, comms (ECAN, I2C, ...), ... I always try to have one USART for debugging

Once you have a hardware plan and software plan you build up your prototype and start with a development process (https://cboard.cprogramming.com/c-programming/88495-development-process.html)

Start with a blinking LED, this confirms that you can program the device and the osc settings are correct.

You might then set up a USART for debugging, with a "hello world".

And then try reading from the '260 and spitting out the value on the USART

Basically get each thing working one at a time. One of the great mistakes people do is start with the program archetecture before confirming each thing works.

"Slow is smooth, smooth is fast"
 

Thread Starter

D1NG0

Joined Jul 28, 2021
7
I've done this now I just need to make the code for the INA260 to work correctly.
I created the I2C library using the MPLAB® Code Configurator then I made the C code by hand but I still can't get the values properly
 

click_here

Joined Sep 22, 2020
439
So currently the values are correct from the Arduino, but not the PIC?

What values are you getting from one vs the other?

It might pay to get 10 values from each and compare
 

Ian Rogers

Joined Dec 12, 2012
935
Could do with seeing your code...
One difference between the two platforms... Arduino wants the 7bit address whereas Pic will use the full 8 bit address.

Also I don't the 10k pullups.. far too slow... Knock the I2C speed down to 100Khz to try it..
 

Ian Rogers

Joined Dec 12, 2012
935
Do you know of any projects that have been done using the INA260 and the PIC?
No not really, but its not much different to an eeprom..

When a device is not really used much, resources are few and far between... I personally would rewrite the arduino library..
 
Top