Go Down

Topic: Energy Measurement (Read 2081 times) previous topic - next topic

noblevirk

Hello Everyone,

I am an Electrical Engineering student and an extreme newbie to Arduino who wants to implement it in my school project. So far I have atmega328p board and Atmega1280 (just for back up if I run out of space).

The project I want to implement is a remotely controllable power outlet capable of storing energy usage on a SD card. Basically there are four major blocks of this project

1) Energy measurement
2) Communication mechanism (This is RF based)
3) Energy Storage on storage device.
4) User interface (LCD and bunch of buttons)

1) Energy measurement is performed by CS5460A chip from cirrus logic and the Irms, Vrms and is available through SPI.

2) A RF remote which have a control switch and send the signal through a RF Transreceiver TI CC2520 to the micro, which in turn control relays to control the power. this transreceiver  also communicate wit micro through SPI

3) Energy data storage will have a simple CSV file with time and energy usage.

4) As the energy storage data needs to have some sort of time reference to create a simple energy usage map for example (1:00AM - 2:00AM = 12 Kwh). Thus there must be a mechanism for setting up the clock through simple switches (just like the digital clocks) to increment and decrement the digits. Thus setting year, month, day, hour, minutes.

I am not sure whether it is a good idea to implement this clock in software or to use a real-time-hardware clocks (I was unaware of these until past hr). As the micro will be in a loop of SPI communications pretty much all the time, I don't know how to run an accurate parallel clock that increments its variables as the time progress.

So please present any other ideas/ways-to-implement in order to provide an accurate clock to the project. I am going to research more on the Hardware-based clock and their usage until then.

Thank you all for making Arduino a readily available and super easy prototyping solution.

Regards,
noble

jluciani

I would use the RTC chip. I like the DS1337. Two interrupt outputs. Runs for a number
of years off a 1220 coin.

I make an Arduino compatible board that has a DS1337 on it. There is
a schematic in the datasheet. On the site is a software library and some examples.
See http://wiblocks.luciani.org/NB1/NB1A-index.html

Be careful when you select the crystal. Some of the chips want a crystal with a CL of
6pF  others want  a CL of 12pF.

(* jcl *)

------------------------------------
www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org


noblevirk

Hello Everyone,

I am back with some interesting problems and issues. I did not received the CL yet for the RTC, however thought to get my hands dirty with I2C until then. Thus I started with 24FC512 (I2C EEPROM by Microchip) as a starting project to understand the I2C. I have read datasheets of both Atmega1280 (Arduino Mega Board) & of 24FC512, I understand the logic behind the I2C well, and have traced back the code provided in Wire library.

To ensure proper communication, I can store a specific data at a specific location on EEPROM and if i successfully read it back then it should confirm that I have it working.

I used the following code to write to a specific memory location, however was not successful in multiple tries.

Code: [Select]

#include <Wire.h>

const int deviceaddress = 80;             // Default address for the device 0x50 = 10100000 (as A2, A1 & A0 are grounded)
                           // Random address for data transfer.
int memadd = 100;                      //  100 in Binary ->  1100 0100
int memadd1 = 125;                    //  125 in Binary ->  1111 1101
int memadd2 = 150;                    //  150 in Binary ->  1001 0110    
int memadd3 = 250;                    //  250 in Binary ->  1111 1010


void setup() {
 Serial.begin(9600);
 Wire.begin();
}

void loop() {
    i2c_eeprom_write_byte(deviceaddress,memadd,(byte)memadd);
    i2c_eeprom_write_byte(deviceaddress,memadd1,(byte)memadd1);
    i2c_eeprom_write_byte(deviceaddress,memadd2,(byte)memadd2);
    i2c_eeprom_write_byte(deviceaddress,memadd3,(byte)memadd3);
}



void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
 int rdata = data;
 
 Wire.beginTransmission(deviceaddress);
   Wire.send((int)(eeaddress >> 8));     // Send MSB of Address First
   Wire.send((int)(eeaddress & 0xFF));   // Then send LSB
   Wire.send(rdata);                     // Finally send Data (Binary equivlent of Address where it is stored)
   int retcode =  Wire.endTransmission();  // Get an insight what happened in the process.
   Serial.print("Return code -> \t");  
   Serial.print(retcode);                // Regurn code = 2; Error: Address Send, NACK received :'(
   Serial.print("\n");          
 }


Return Code I received is 2, which is generated when TWSR contains 0x20 and imples "error: address send, nack received"

It is equivalent to say that nothing is happening, in fact retcode didn't changed when i disconnected SDA and SCL completely.

Configuration is as follows:
On EEPROM chip I have pin 1,2,3,4 & 7 grounded.
pin 8 = Vcc (tried both 3.3 & 5V)
pin 5 = SDA (Pin 44 on Arduino Board)
pin 6 = SCL (Pin 43 on Arduino Board)

Wire library says it utilizes the internal pull up resistors for the TWI and the EEPROM says that it requires pull ups as well.

I tried without pullup resistors, 2k (for 400kHz) & 10k( <= 100kHz)

Please provide more suggestions on how to debug and proceed.

Regards,
Noble



noblevirk

Hoorayy !!!

I got it working, now I can read and write the data to EEPROM with flying colors.

My mistake was the pin mapping, I still can't believe how much time i spend debugging it while repeating same mistake over and over again. So here it is folks.

As Atmel Atmega1280 have pin assigned to SCL & SDA (which were 44 & 43 respectively), I was connecting the SCL  & SDA lines for communication from Arduino to EEPROM to Digital pins 44 & 43 rather than the pre-defined communication pins (SCL & SDA).

Oh well I learned hard way, by spending at least 8-10 hrs on this.


luxabdul

Hello, noblevirk

An excellent work! If possible let it compatible with the Pachube, so you can think me up a shield for Arduino MEGA. Please share your the circuits.

Mohammed

noblevirk

Thanks Everyone for their replies, I have the following covered now

RTC configured using I2C Bus
SDCard configured using SPI Bus
SPI Bus communication


The next issue I am stuck on is as follows

I have three slave devices on same SPI Bus with different Communication speeds lets name them Chip 1 (0-2Mhz) Chip 2 (0-20Mhz) and SDcard (0-8Mhz).

I will be accessing these slaves in a iterative manner one after another in my main loop using Arduino Mega. Now the questions I have:

  • Is it appropriate or recommended to change the SPI Bus speed for SDCard?
  • I am using Fat16lib (which allows 4Mhz and 8Mhz of operation along with various timeouts to ensure other functions and error generation) and not sure will Fat16lib will break for  < 4Mhz of operation?
  • I am also not quite sure how much time it will take to complete writing apporx 1 line / hour or somethings will mess up if I drop the SPI bus frequency to SD Card at say 1.5 Mhz speed"

[/b]
Please Advice, I will soon upload the final code along with its operation summary.

Regards,
noble

Go Up