dhruv_electro
Advanced Member level 4
here I am posting discussion with a friend about cs5460 so other can find it useful
Yes you have done the right way of start of conversion command in your main function.
But before start you have to do following step:
1. read a byte or a flag stored in your eeprom after power up, which indicate that calibration is done on your device or not?
2. If that flag says yes then you skip 3 to 6 step and goto step 7.
3. If that flag says no then you have to do calibration.
4. For calibration process please read an application note given by cirrus logic "Calibrating the cs5460a".
5. after calibration is done please read the calibration values for the DC/AC offset reg & Gain Reg.
6. Store this value in your eeprom or your flash.
7. Now after each power up you have to write this values in thier respective reg.
8. Now give start of conv command.
9. Start reading :wink:
I think now you can find answer to your que no 1.
yes for this kind of configuration the pin SDO,SDI,SCK and CS is enough. You can give pulled up high on Reset pin. (ans for que. 2)
Ans for que 3.: Your hardware must have lots of memory space (external memmory)for this and you must have used some "RTC" for this. You scan your reading in real time and you can store its vaue in your memory. You can use this reading leater for your Energy Vs Time graph. (Or you can use a PC interface with your MCU, which receive reading and your GUI will make direct real time graph).
Ans for que 4: Yes we have transmitted data over Zigbee module (microchip MRF24J40A) to remote PC. There we have maintained a real time System. But we dont use power or energy data. We just used current data. (our application was limited to some machine.)
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
Yes you have done the right way of start of conversion command in your main function.
But before start you have to do following step:
1. read a byte or a flag stored in your eeprom after power up, which indicate that calibration is done on your device or not?
2. If that flag says yes then you skip 3 to 6 step and goto step 7.
3. If that flag says no then you have to do calibration.
4. For calibration process please read an application note given by cirrus logic "Calibrating the cs5460a".
5. after calibration is done please read the calibration values for the DC/AC offset reg & Gain Reg.
6. Store this value in your eeprom or your flash.
7. Now after each power up you have to write this values in thier respective reg.
8. Now give start of conv command.
9. Start reading :wink:
I think now you can find answer to your que no 1.
yes for this kind of configuration the pin SDO,SDI,SCK and CS is enough. You can give pulled up high on Reset pin. (ans for que. 2)
Ans for que 3.: Your hardware must have lots of memory space (external memmory)for this and you must have used some "RTC" for this. You scan your reading in real time and you can store its vaue in your memory. You can use this reading leater for your Energy Vs Time graph. (Or you can use a PC interface with your MCU, which receive reading and your GUI will make direct real time graph).
Ans for que 4: Yes we have transmitted data over Zigbee module (microchip MRF24J40A) to remote PC. There we have maintained a real time System. But we dont use power or energy data. We just used current data. (our application was limited to some machine.)