Tuesday, February 22, 2011

Andrew's Week 5 Progress Report

This week I connected the 110V circuit and enclosure to the breadboarded circuitry.  For now I am using the 5V breadboard power supply as the power source but plan on building my own in the near future.  Next I connected the MKII module so that the micro controller is ready for programming.  The circuit is now ready for operational testing and callibration once the programming is finished. 
After making these connections I decided to draw a schematic which displays the circuit thus far.  The schematic is shown below.  For the ethernet portion of the circuit I only put the W5100 ethernet chip because we are currently using the ethernet arduino as our hardware.  The following link shows a schematic of the ethernet arduino: http://arduino.cc/en/uploads/Main/arduino-ethernet-shield-05-schematic.pdf    I also plan to add the power supply schematic which will most likely involve a step down transformer, a bridge, fusing, and a linear voltage regulator.







Next week I plan on testing and callibrating the entire circuit with Ashley to resolve any conflicts in the programming and hardware.  I also plan on beginning to explore power supply options so that our circuit can become more standalone. 

Kevin's Week 5 Report

Right now I am working on getting the drop down buttons to display various options for the user.  The challenge in doing this, is that I must get the different drop downs to communicate with the database.  I am having trouble getting the buttons to access the data within the database.  The way it works is that the user will first have to select a year from the drop down.  To display the available years, the drop down button must access the database and determine which years are available and then display it in the drop down menu.  After the user selects a year, the month drop down button must access the database to see which months are available within that year.  It can then display those months to the user for them to pick.  This process continues until the user has entered in the desired time period information.  I will have to add in a "Submit" button as well, in case the user only wants to view monthly data, then they should leave the day and hour buttons blank.  I cannot get the radio button without the submit button to take them to the next viewing.  If I do it this way, then there is possibility for error as the user can click the day radio button before entering in the specified day, and no data will show up, so the submit button I believe will be a better setup.  I am also working on the same type of format to add and remove graphing lines of different sensors to the graph.
Once I have this step complete, then I can start making the website look more user friendly.  Then I can begin testing out how to take in data from the ethernet connection instead of getting it from a random value source.

Ashley's Week 5 Report

This week: I didn't get as far as expected.  I have the read, write and initialize subroutines for the SPI communication.  I have a subroutine for implementing the SPI communication to the ADE7763 called readADE.  The SPI subroutines should work for the ethernet chip as well, I will simply just need to implement them into a readEthernet subroutine.  I don't think that my readADE is completely correct so I will try to get some help on this within the next day or two to make sure that it is ready to go for testing.  Below are my modified main program as well as the read, write and SPI initialization subroutines.  Andrew and I met briefly this morning to discuss our progress as well as when we wanted to get together to test the reading of data from the ADE.  I also told him the connections I would need him to make between the micro and the ADE so that my test program will work.

Next week: I will have the test program completed by the end of the week so that I can come in on either Friday or Tuesday to test that the micro can read in the temperature from the ADE7763.  I'll connect to the computer via RS232 and print the value to the secureCRT terminal.  

------------------------------------------------------

int main(void){

setBitPortB(2); //ADE7763 SS line on PB2; Set to high.
InitSPI();
char temp;

usart_init();
sei();

while(1){
char str[25];
char temp_reg = 0x26;

while(!uart_buffer_empty()){
char c = usart_getc();

if(c == 'p'){
temp = readADE();

usart_prints("\r");
usart_prints("The temperature is: ");
sprintf(str, "%d\n",temp);
usart_prints(str);
}
}
}
}

char readADE(void){
clearBitPortB(2); //pull PB2 low to start communication mode with ADE7763
_delay_ms(10);

char temp;

WriteByteSPI(0x26);
temp = ReadByteSPI(0x26);

setBitPortB(2);  //pull PB2 high to end communication mode

return temp;

}

void InitSPI(void)
{
DDRB = (1<<PB4)|(1<<PB5) | (1<<PB7); // Set MOSI , SCK , and SS output
   /* Enable SPI, Master, set clock rate fck/8 */
   SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
   SPSR = (1<<SPI2X);
}

void WriteByteSPI(unsigned char byte)
{

SPDR = byte; //Load byte to Data register
while(!(SPSR & (1<<SPIF))); // Wait for transmission complete

}

char ReadByteSPI(char addr)
{
SPDR = addr; //Load byte to Data register
while(!(SPSR & (1<<SPIF))); // Wait for transmission complete
addr=SPDR;
return addr;
}

Tuesday, February 15, 2011

Ashley's Week 4 Report

This Week:  I have done a bit more research on SPI communication in general.  I realized that I had  misunderstood how it functioned and thought it to be more similar to I2C communication in that you have to address the specific slave that you want to communicate with.  In my situation, and in most, the microcontroller is defined as the master, and the ethernet chip and the power chip are the two slaves.  In SPI, there are 4 connections between the master and the slave device.  Three of these connections are shared by the two slaves: the MISO, MOSI and SCK pins.  The fourth pin is the SS and differs between the two slaves.  Any I/O pin can be used as an SS, so I will probably be using PB1 and PB2 as my two SS connections.  The way that you determine which slave device you are communication with is to trigger a change in voltage on that slaves SS line.  The case for both of my slave devices is that a falling edge will start communication mode.  For example, the ADE7763's SS line will be on PB1.  PB1 will be pulled high as the default.  When I want to communicate with the ADE7763, I will pull PB1 low, write to the communication register that I want to read a value, then read the actual value, and pull it back high when I am finished to exit communication mode.  Below is sample code that I've started for this.  For testing, I will read the RMS Voltage.

Next Week:  I will finish the getRMSV() routine and see if there are any other initialization steps to be taken in the main program.  I hope to get together with Andrew to test the program by the time we have our 5 week meeting.


----------------------------------------------------------

int main(void)
{

setBitPortB(1); //ADE7763 SS line on PB1; set to High
SPI_MasterInit();

uint8_t rmsV;

usart_init();
sei();

while(1)
{
char str[25];

while(!uart_buffer_empty()){
char c = usart_getc();

if(c == 'p'){

clearBitPortB(0); //pull PB1 low to start communication mode with ADE7763
_delay_ms(10);
rmsV = getRMSV();
                setBitPortB(1); //exit communication mode

//printing to terminal
usart_prints("\r");
usart_prints("The RMS Voltage is: ");
sprintf(str,"%d\n",rmsV);
usart_prints(str);
}


}
}


}

void setBitPortB(int bit)  //sets bit to 1
{
PORTB = PINB | (1<<bit);
}

void clearBitPortB(int bit)  //sets bit to 0
{
PORTB = PINB & (~(1<<bit));
}



//SPI STUFF
void SPI_MasterInit(void)
{
   /* Set MOSI and SCK output, all others input */
   DDRB = (1<<PB2)|(1<<PB1);

   /* Enable SPI, Master, set clock rate fck/8 */
   SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
   SPSR = (1<<SPI2X);
}

uint8_t getRMSV()
{
uint8_t rmsV = 1;
//send write to communication register
//read rms volage

return rmsV;


}

Kevin's Week 4 Report

This week I was able to get data from the database to show up on a graph that will be displayed to the user on the website.  The data is passed to the graph via query string as I described last week.  The radio buttons and the check boxes in the image below are not quite working yet, however, the general idea is that the user can use the buttons to display the data they would like to see.  They will be able to select values from the drop down menu, and the radio button selected will indicate how much of a time period the window will show.  Also, more checkboxes will be added so users can see multiple data sensors on one graph.  The Previous and Next buttons work right now, and that is how I navigated from 9PM to 10PM.  The URL through the local host right now looks like the following:
Where Type=hour indicates that it will show an hourly data window.  The information following that indicates the year, month, day, and hour to be viewed.  If Type=day, then there will be no hour in the URL.  I have provided the screenshots of the database to compare with the graph to show that numbers are being correctly recorded into the graph.  The database collected data from Sensor1 and Sensor2, but I only displayed Sensor1 data on the graph for now.
My next step is to get the buttons to display different time periods of data and multiple data sensors working.  Right now to change the time of the window, the user must manipulate the URL which is not very user friendly.








Monday, February 14, 2011

Andrew's Week Four Progress Report

This week i continued to breadboard and started by making an RS-232 connection from the micro controller to the pc.  We are doing this temporarily as a way to make check our data before we link the micro controller to the router. 
After finishing the breadboarding I performed several safety checks with a digital multimeter to ensure there were no direct shorts which required me to run several continuity tests between the line hot and line neutral, ground, and various points throughout the enclosure.
After testing these points I decided it was safe to connect the circuit to 110V wall outlet.  After plugging the device in I again performed several "hot" voltage measurements to make sure the voltage levels were appopriate at all the inputs and outputs of the line voltage circuit.
To answer the comments left on icon I would like to say that I appreciate your input and suggestions.  Wade showed me the soldering station and I was very impressed with the with the setup however I never have had any formal training soldering such small components as the SSOP.  With a little lesson from Wade I am hoping to venture out on my own next time.
Overall I had a light week working on this project but hope to have another productive week starting Thursday when we will be meeting again as a group to continue integrating our project into one. I am excited but know that much work lies ahead debugging and troubleshooting.

Tuesday, February 8, 2011

Ashley's Week 3 Report

This week:  I started putting together a test program to read from the power chip.  So far it is just a skeleton and I need to fill in the details on the SPI communication.  The test program will in essence transfer data from the ADE7763 to a computer terminal.  Because we already have experience with RS232 communication, I will use SecureCRT as my terminal.  When the user presses "p" on the computer, the microcontroller will contact the ADE7763, read the power and print it to the terminal.  This way we can make sure the microcontroller is able to read data and determine whether the values make sense.  I also began searching the internet for information regarding the Ethernet communication.  It also uses SPI bus so the basic concepts will be the same, just a difference in addresses and commands.  Because both devices use the same bus, they will share some communication lines.  Their individual addresses will let its device know that it is being communicated with.  Here is a basic wiring diagram of the microcontroller with two SPI devices.

**Click to Enlarge**

---------------------------------------------------------------------------------------------

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <string.h>
#include <stdio.h>
#include "uart.h"
#include "spi.h"

#define F_CPU 8000000UL        // This should match the processor speed
#define BAUD_RATE 9600        // Baud rate. The usart_int routine

// Variables and #define for rge RX ring buffer.
#define RX_BUFFER_SIZE 64
unsigned char rx_buffer[RX_BUFFER_SIZE];
volatile unsigned char rx_buffer_head;
volatile unsigned char rx_buffer_tail;

//USART Function Prototypes
unsigned char uart_buffer_empty(void);
void usart_prints(const char *ptr);
void usart_printf(const char *ptr);
void usart_init(void);
void usart_putc(const char c);
unsigned char usart_getc(void);


int getPower(int command);

void setRegister(int value, int command);

void startReading(int command);



int main(void)
{

//pull CS low?

int pow = 0;
int valP = 0;


usart_init();


//Initialize Power Chip settings
setRegister(valP, pow);
startReading(pow);



sei();

while(1)
{
char str[25];
uint8_t power = getPower(pow);

while(!uart_buffer_empty()){
char c = usart_getc();

if(c == 'p'){
usart_prints("\r");
usart_prints("The power is: ");

sprintf(str,"%d\n",power);

usart_prints(str);
}


}


_delay_ms(10000);
}


}



int getPower(int command)
{
int value = 1; //read power from chip
return value;
}

void setRegister(int value, int command)
{  
    //set bits of specified register
}

void startReading(int command)
{

}


//USART FUNCTIONS BELOW

ISR(USART_RX_vect)
{
   // UART receive interrupt handler.
   // To do: check and warn if buffer overflows.
  
   char c = UDR0;
   rx_buffer[rx_buffer_head] = c;
   if (rx_buffer_head == RX_BUFFER_SIZE - 1)
      rx_buffer_head = 0;
   else
      rx_buffer_head++;
}

void usart_init(void)
{
   // Configures the USART for serial 8N1 with
   // the Baud rate controlled by a #define.

   unsigned short s;
 
   // Set Baud rate, controlled with #define above.
 
   s = (double)F_CPU / (BAUD_RATE*16.0) - 1.0;
   UBRR0H = (s & 0xFF00);
   UBRR0L = (s & 0x00FF);

   // Receive complete interrupt enable: RXCIE0
   // Receiver & Transmitter enable: RXEN0,TXEN0

   UCSR0B = (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0);

   // Along with UCSZ02 bit in UCSR0B, set 8 bits
  
   UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);

   DDRD |= (1<< 1);         // PD0 is output (TX)
   DDRD &= ~(1<< 0);        // PD1 is input (Rx)
 
   // Empty buffers

   rx_buffer_head = 0;
   rx_buffer_tail = 0;
}


void usart_printf(const char *ptr){

   // Send NULL-terminated data from FLASH.
   // Uses polling (and it blocks).

   char c;

   while(pgm_read_byte_near(ptr)) {
      c = pgm_read_byte_near(ptr++);
      usart_putc(c);
   }
}

void usart_putc(const char c){

   // Send "c" via the USART.  Uses poling
   // (and it blocks). Wait for UDRE0 to become
   // set (=1), which indicates the UDR0 is empty
   // and can accept the next character.

   while (!(UCSR0A & (1<<UDRE0)))
      ;
   UDR0 = c;
}

void usart_prints(const char *ptr){
  
   // Send NULL-terminated data from SRAM.
   // Uses polling (and it blocks).

   while(*ptr) {
      while (!( UCSR0A & (1<<UDRE0)))
         ;
      UDR0 = *(ptr++);
  }
}

unsigned char usart_getc(void)
{

   // Get char from the receiver buffer.  This
   // function blocks until a character arrives.
  
   unsigned char c;
 
   // Wait for a character in the buffer.

   while (rx_buffer_tail == rx_buffer_head)
      ;
 
   c = rx_buffer[rx_buffer_tail];
   if (rx_buffer_tail == RX_BUFFER_SIZE-1)
      rx_buffer_tail = 0;
   else
      rx_buffer_tail++;
    return c;
}

unsigned char uart_buffer_empty(void)
{
   // Returns TRUE if receive buffer is empty.
  
   return (rx_buffer_tail == rx_buffer_head);
}
----------------------------------------------------------------------------------------

Next week:  I'll continue to work on my ADE7763 test program and Ethernet specific SPI programming.  I may also start my test program for the Ethernet communication to the computer.

Kevin's Week 3 Report

This week I worked on trying to get data from the database structure into a website in order to graph the display.  Designing the page using ASP.net, the webpage is able to access the database.  On the webpage, the user will select what time period they wish to view (minute, hour, day, week, etc..).  This will then give the user options to enter in what specific hour, day, week, etc. they wish to view.  When the user enters this information, the respective numbers of the hour, day, week, etc. will be put into a querystring.  The program that accesses the database will take this querystring and take the numbers it needs and put it into a string.  This string will only go down to the minute as the most specific data point.  If the user wants to view data on a specific minute, then the datatemp table will be accessed, since it contains information down to second accuracy, and all the data that match that minute information will be sent to the webpage.  Similarly, if the user wants to view data for a certain hour, then the dataminute table is accessed, since it contains information down to minute accuracy, and all the entries that have the same hour value as the user input will be selected, so 60 data entries.  This process applies to all data selections.  There will have to be a checker so that if the user requested minute data from the whole of year 2010, an error message will appear.  The database cannot keep data that specific for that long of a time period, and the user will have to select monthly data instead.
Right now the values are being passed into the querystring and they are being read.  However, they are not plotting on the graphs, using MS chart control.  I will need to find out why data is being passed into program, but no data shows up.  Once this is working though, I plan to hook up the program to our old digital thermometer circuit to test actual data coming in.  Once this is complete then I can begin working on taking in data through ethernet connection instead of serial.

Andrew's Week 3 Progress Report

This week I worked on the physical installation of the power metering hardware and breadboarding.  I began by soldering signal wires onto the shunt resistor.  Next after soldering the wires I attached it to the load and line side neutrals on the terminal block using crimp on fork and round terminals.  Shown below is a picture which displays the shunt resistor in the upper left corner.







After installing the shunt resistor I next mounted fuse blocks so that all the signal wires can be fused at a much lower amperage to prevent fire or overheating.  This required three fuse blocks which will provide the signal for the current and voltage measurements as well as the electronic power supply.  Shown below is a picture of the fuse blocks and the signal wires.  Currently there are 7A fuses installed but I plan to step these fuse sizes down to 1A after bread boarding is complete.

  
Finally the last task I worked on this week was breadboarding the power monitoring circuitry connected to an Atmega328P through SPI communication bus.  During this breadboarding process I needed to convert the power monitoring chip (ADE7763) from SSOP to DIP for compatible.  Classmate Wade Hansen soldered this part for me because it required high precision.  Shown below is the nearly complete breadboarded power monitoring circuit.




Next week I plan to completely finish the prototyping of the power measuring circuit and work out any communication/ micro controller hardware issues.  If I complete this task by the end of the week I will move onto working with the microcontroller ethernet circuitry.

Tuesday, February 1, 2011

Kevin's Week 2 Report

Kevin’s Week 2 Report:  This week I continued testing the database.  The database now continues to take in data every second and this data is stored into a datatemp table in the database.   It averages the second data every minute and stores this into the dataminute table.  This data will be used to display information for the hourly and daily data.
Once the second data is averaged, the datatemp table is cleared to preven the table from growing too large.  This same concept will be applied to clearing the minute data every day.  It will also clear daily data every month.  A bit more simulating needs to be done to make sure that this clearing is sufficient and that the database won’t get too full.  This won’t be an initial problem when the user is first using the system.  Once the system has been plugged in for a year or so, if no clearing is done there may be too much data in the database.


I also set up the initial interface the user will see when they first use the system.  The user needs to just enter in their information in the text boxes, hit “Start Logging Data” and then the system begins to store information.  Below is a screenshot of the initial window.  The debug button is used solely as testing right now.

I also decided to use the MS chart control for graphing the data and displaying it on the webpage.  It is compatible with the .NET framework and seems to be a good tool.  I also decided to use the MS chart control for graphing the data and displaying it on the webpage.  It is compatible with the .NET framework and seems to be a good tool.  http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx

Next Week:  Start working with MS chart control and make some basic graphs of the data collected so far.

Ashley's Week 2 Report

This Week: I learned about the serial interface communication with the ADE7763.  I read about it on the datasheet itself as well as found a handful of examples and a partial library online.  First you have to place the ADE7763 in communication mode.  This occurs when you power on or toggling the RESET pin low and having a falling edge on the CS pin.  Regardless of whether you want to read or write to the ADE7763, you have to first send it a "write" to its communication register. The communication register is 8-bits.  The MSB determines whether the next data transfer is a read or write.  Bit 7 should be left alone (0).  The LSBs will contain the address of the register to be accessed.  There's a table with all of the addresses of the registers.  For example, the address for the RMS voltage is 0x17.  Therefore the entire binary string sent to the ADE7763 would be: 00010111.  The data transfer is complete when the LSB of the ADE7763 register being addressed is transfered to the ADE7763, and it once again enters communication mode.

Next week: I will continue working on test code for the ADE7763 communication as well as starting to research the communication with the ethernet connection.

Andrew's Progress Report February 1st, 2011

This week I continued to purchase parts for both the electronic circuitry and the enclosure itself.  I decided to build the enclosure earlier in the process because it will allow us to safely prototype with a 110V fused energy source.  After purchasing these parts I built the enclosure, a 110v fused disconnect and a 110v 15 amp GFCI receptacle connected to the load side so various devices can be tested by our device easily in the future.  Inside the enclosure is a terminal strip which insulates the 110v voltage and other connections from the rest of the enclosure.  Also located at the bottom is a ground bar which allows for easy connection of any devices requiring a ground.  Shown below is the enclosure as constructed thus far.

On the electronic hardware end of my responsiblities I purchased the components needed to breadboard our initial current and voltage measurement circuits.  This includes capacitors, resistors, a board which allows us to connect 20 pin SSOP to 20 pin DIP package for prototyping and the shunt resistor.  Shown below are the receipts for these parts.

Receipt from Engineering Electronics Shop




Receipt from Digikey for Shunt resistor


Next week I plan to have the voltage and current measurement circuits bread boarded and connected to the ADE7763 power monitoring chip.  After making these connections I next plan to connect the ADE7763 to the Atmega328P using SPI communication.  I then plan to work with Ashley to troubleshoot and test our power monitoring circuits.