donnib said:dhruv_electro said:donnib said:Hi,
I read that you have implemented an simple energy meter using CS5460. I am trying to do the same but will be using an ATmega328 and i need some code to Configuration, Start measurement and Calibration. Could you send the final code to me ? I saw an example in this thread https://www.edaboard.com/threads/197704/
thx
donnib
Hi donnib.
The code i have given there is the final code and yes it is for ATmega8515. You can convert it acording to your mcu. I have code for:
you can copy detail code from that thred.Code:void SPI_MasterInit(void); //for initialisation the spi void SPI_MasterTransmit(unsigned char cData); // spi transmition unsigned char SPI_MasterReceive(void); // for spi reception void spi_reinitilise(void); // for reinitilise the cs5460 (read datasheet and see code) unsigned long int SPI_Read_data(char cData); //read data from address given from cs5460 void spi_data_write(char command,unsigned long int x); //write data at given address (24bit data)
now if you wanted to read Voltage channel rms value than type this
where 0x18 is address for reading data from voltage channel rms reg.Code:EN_CS1(); //enable cs5460 x=SPI_Read_data(0x18); DS_CS1(); //disable cs5460
for calibration you can give calibration command like this
where 0xDA is calibration command for gain reg. see datasheet for other calibration. I have done ac offset and dc offset calibration.Code:EN_CS2(); SPI_MasterTransmit(0xDA); DS_CS2();
for start of conversion you can do this:
Hope you will find this useful.Code:EN_CS2(); SPI_MasterTransmit(0xE8;); DS_CS2();
Yes this is indeed pretty helpful. thank you VERY much for replyiing back. I just need to figure out how to convert this to an ATmega328 or TI MSP430. At the moment i only have the MSP430 because my Arduino Uno with the ATMega328 has just been ordered. I guess i need to initialize the SPI properly and set the clock correct, yes ?
Let pressume i have set up correct SPI. How do i start ?
Code:int main(void) { //initialize SPI SPI_MasterInit(); //start conversion EN_CS2(); SPI_MasterTransmit(0xE8;); DS_CS2(); //read V_RMS EN_CS1(); //enable cs5460 x=SPI_Read_data(0x18); DS_CS1(); //disable cs5460 }
Would the above do it ?
Couple of more questions :
1. Calibration : How does that work in practice ? You just read the "Last voltage value" without load and if it gives let's say 210V then you know the offset is 220V-210V 10V ? What about the current because you do not know the value without load ? Sorry for asking such simple quesitons
2. What pins do i need to use ? Is SDO, SDI, CS, SCLK enough or i need the RESET pin as well ?
3. I would like to get all the enrgy used P during the use for some load so i can show it in a nice graph vs. time. Would one poll the "Last power value" and accumulate that or ? Any ideas are welcome ?
4. Did you do some wireless transmission from your microcontroller of the data or what did you do with your data delivered by the CS5460 ? My intention is to build some home monitoring meters for each wallet so i can monitor the power ussage in our house.
Thanks again for your very useful message.
br.
donnib
EN_CS2();
SPI_MasterTransmit(0xD9); //11011001
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x06);
spi_data_write(0x06,x);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x02);
spi_data_write(0x02,x);
DS_CS2();
EN_CS2();
SPI_MasterTransmit(0xDD);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x22);
spi_data_write(0x22,x);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x20);
spi_data_write(0x20,x);
DS_CS2();
EN_CS2();
SPI_MasterTransmit(0xDA);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x08;);
spi_data_write(0x08,x);
DS_CS2();
EN_CS2();
x=SPI_Read_data(0x04);
spi_data_write(0x04,x);
DS_CS2();
Dear dhruv please attach the schemetic for interfacing cs5460A with avr microcontroller.Hi mihir,
I have used CS5460A (may be u r also using that instead of CS5460). We had faced same kind of problem using this IC. But as for that much resolution with such cheap rates, may still use it. Now I just wanted to ask the sequence of your calibration. Link for your ref is here:
https://www.cirrus.com/en/pubs/appNote/an227rev1.pdf
This may be help.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?