ECE 477 Digital Systems Senior Design Project Spring 2006

Homework 10: Software Design Considerations

Due: Friday, March 31, at NOON

Team Code Name: ______Group No. ______

Team Member Completing This Homework: ______

E-mail Address of Report Author: ______@ purdue.edu

Evaluation:

Component/Criterion / Score / Multiplier / Points
Introduction & Summary / 0 1 2 3 4 5 6 7 8 9 10 / X 1
Software Design Considerations / 0 1 2 3 4 5 6 7 8 9 10 / X 3
Software Design Narrative / 0 1 2 3 4 5 6 7 8 9 10 / X 3
List of References / 0 1 2 3 4 5 6 7 8 9 10 / X 1
Appendices / 0 1 2 3 4 5 6 7 8 9 10 / X 1
Technical Writing Style / 0 1 2 3 4 5 6 7 8 9 10 / X 1
TOTAL

Comments:

______

______

______

______

______

1.0  Introduction

The goal of this project is to re-design the logic board of the Maximum Power Point Tracker (MPPT), which is currently in development by Purdue Solar Racing. A maximum power point tracker is a DC to DC converter which takes an input voltage from a solar cell array and converts it to the output voltage of a battery pack. For any solar cell array, there exists a point on its current versus voltage curve that produces the maximum power. The re-designed logic board will incorporate feedback control of the converter to obtain this maximum power point. Another feature of the logic board will be the CANbus interface that will allow for remote access of the data and diagnostics of the MPPT.

Several software design considerations were taken into account while designing the software for the MPPT. This report will discuss these considerations in detail. The report will also focus on memory mappings and provide the reasons behind the decisions of these mappings. Utilization of the integrated peripherals and organization of the application code will be discussed in the report. Finally, the report will also focus on explaining, in detail, each code module and the purpose it serves to the overall functionality of the software.

2.0  Software Design Considerations

The general idea behind the software is to be able to correctly calculate a maximum power point for a solar cell array and store that point along with input voltage, input current, output voltage, output current, temperature and duty cycle of the PWM in designated registers. There are several software design considerations for this logic board. The algorithm that calculates the maximum power point has to run below 30 Hz to maintain system stability. This is because the filters do not operate at a faster frequency than 30 Hz. Hence if the algorithm ran faster than 30 Hz, the system response would not be observed. Another design consideration is that a CAN request must be serviced as soon as it is detected, hence all CAN requests will be interrupt-driven. Finally, software must also report any errors it detects, immediately, through CAN.

Given the aforementioned constraints, our software starts with basic initialization routines of the UART, SPI, A/D, CAN and PWM. These initialization routines setup the USART, MSSP, A/D converter, ECAN and CCP1 modules to desired settings. Details of these settings will be discussed in Software Design Narrative section. After these initialization routines, the software does an initial calculation of the maximum power point. Finally, the software enters an infinite loop, and executes various processes within this loop. Please refer to the Software Design Narrative for more details on the Main module.

2.1 Mappings of memory

The PIC18F2680 microcontroller has 64Kbytes of on-chip program memory. The software program will be stored on the on-chip memory. The CAN module, without the CAN receive routine implemented, takes up 279 bytes of program memory and 270 bytes of data memory. The SPI module requires 440 bytes of program memory and 268 bytes of data memory. The PWM module requires 370 bytes of program memory and 270 bytes of data memory. The A/D module requires 140 bytes of program memory. 480 bytes of program memory is used by the UART. A total of 800 bytes of program memory and 270 bytes of data memory is used by the maximum power point algorithm.

The above mentioned program memory and data memory are within the default space that the microcontroller allocates for every software program. The entire software uses a total of 2309 bytes of program memory and 1620 bytes of data memory. Hence the default program memory and data memory allocations of the microcontroller are sufficient. As for the size of the stack, the software does not have large number of function calls nor any sort of recursive function calls. So there was no need to remap the stack.

2.2 Mapping of external interfaces

External interfaces of this project are CAN, RS232 (UART) and SPI. The PIC18F2680 microcontroller has all of these interfaces on-chip and due to the large on-chip program memory and data memory, the project does not require any additional external communication or memory devices.

2.3 Utilization of integrated peripherals

As mentioned earlier, the peripherals for this project are CAN, RS232 (UART), SPI, PWM and A/D converter. Communication between the MPPT and the rest of the solar car is via CAN. CAN is based on the “broadcast communication mechanism”, where message contents are defined instead of station and station addresses. Every message has a unique message identifier because the message identifier defines the content and also the priority of the message. A high degree of system and configuration flexibility is achieved due to the content-oriented addressing scheme. Stations can be easily added to an existing CAN network without any hardware and software modifications to the existing stations. The CAN protocol supports two message frame formats, CAN base frame and CAN extended frame. CAN base frame feature an eleven bit identifier and CAN extended frame features a 29 bit identifier [2]. This project is using the CAN base frame format because the 11 bit identifier can sufficiently support all the CAN devices that will be part of solar car network. The microcontroller provides 3 different modes of operation for CAN: Legacy, Enhanced Legacy and FIFO. FIFO mode is being used for the project mainly because CAN performs fastest under this mode. The CAN baud rate is set at 125 KHz and the clock frequency of the processor is 40MHz. The baud rate is set through Baud Rate Control Registers, BRGCON1, BRGCON2 and BRGCON3.

RS232 peripheral will be used as a trigger to enter DEBUG mode. Any character appearing on the RS232 will force the software to enter the DEBUG mode and a specified exit character will allow the software to exit the DEBUG mode. The operation of the UART is controlled through the TXSTA, RCSTA and BAUDCON registers. The SPI peripheral is used to transfer data to the microcontroller, most likely the CAN address of the device. The PIC18F2680 is equipped with a master synchronous serial port module (MSSP) which can operate in two modes and one of them is the SPI mode. Three registers, SSPSTAT, SSPCON1 and SSPCON2, control the MSSP module. The PWM peripheral will be used to control the duty cycle, which will allow the software to sweep the I-V curve and obtain the power points to the left and the right of the maximum power point along I-V curve. The CCP1 module of the microcontroller allows the configuration of the PWM. The period of the PWM is set through the PR2 register of the microcontroller and the duty cycle is controlled through the CCPR1L register. Finally the A/D converter, which will be used to monitor the voltage of the Maximum Power Point Trackers, will be controlled through 10-bit Analog to Digital Converter Module of the microcontroller. The module has five registers, ADRESH, ADRESL, ADCON0, ADCON1 and ADCON2. The A/D operation is controlled through ADCON0 register [1].

2.4 Application Code Organization

The organization of the application code for this project is a combination of state machine, polling loops and interrupt driven. The maximum power point algorithm will be implemented using a state machine. The two different states will be a “Sweep State,” where per every minute the software sweeps I-V curve and sets the maximum power point, and a “Check & Reset MPP” state, where every 60 ms the power points to the right and left of the maximum power point will be checked to ensure that the current maximum power point is the “best available” maximum power point. As mentioned earlier, all CAN messages will be interrupt-driven, hence the necessity for the interrupt-driven implementation in the application code. The polling-loop part of the code is due to the UART messages, which will be polled every run through “Main Loop” (discussed in detail in the Software Design Narrative) to decide whether or not to enter the DEBUG mode.

3.0  Software Design Narrative

The following section describes each software module that is being used in the Maximum Power Point Tracker and the status of each software module.

3.1 Main module

In this module, all the global variables required by the software of the MPPT are declared and initialized. This module consists of just one function, the main() function. This function controls the entire software of the MPPT. First this function calls the initialization functions for UART, SPI, PWM and A/D. Then the function obtains the CAN identifier through the SPI and uses this identifier to initialize CAN. Next the function sweeps the I-V curve to obtain the initial duty cycle. Following this the function enters an infinite while loop, where first it checks to see if there is any data on the UART. If there is data on the UART, the software enters the DEBUG mode. If there no data is present on the UART, the software measures input voltage, output voltage, input current, output current and temperature. After obtaining the voltages and currents, the software checks if overvoltage or overcurrent condition exists. If it does, then it sets the appropriate bit in “flags” variable, disconnects the relay output and turns on the “error” LED. The function also checks to see if any CAN cable is disconnected, if it is the software sets appropriate flag bit and turns on the “disconnect” LED. However, if the cables are connected then the flag bit is cleared and the “disconnect” LED is turned off. Finally, the function reaches to the point where it checks and sets the maximum power point. The function will call mpp_alg() function every 60 ms. The mpp_alg() function obtains the power points to the left and right of the existing maximum power point and compares them with the existing maximum power point and reassigns the maximum power point based on this comparison. Also every one minute, the function also calls the sweep_curve(), where the entire I-V curve is swept and a new maximum power point is set.

3.2 Communications module

This module controls all the communication functions for the MPPT. It initializes both the CAN and the UART. The module also includes several functions that are implemented to receive and transmit data from and to the RCSTA and TXSTA registers respectively. The functionality of all the functions that are part of this module are described below.

·  initial_Can(int id)

This function initializes the ECAN module of the microcontroller to have a baud rate of 125Kbps at 40MHz. The function first sets the CANCON to 0x80 so that it can enter configuration mode, then it sets BRGCON1, BRGCON2 and BRGCON3 to the appropriate values so that a baud rate of 125Kbps at 40 MHz can be achieved. The ECANCON register is set to run in the FIFO mode because CAN performs fastest in this mode. The function configures all the receive buffers to be in FIFO mode and all programmable buffers to receive buffers. Finally the function sets the CANCON register to 0x00 to exit the configuration mode and enter the normal mode of operation. Following this the function enables RX buffer interrupts through the PIE3 register and sets these interrupts to high priority. These interrupts are set to high priority because CAN requests must be serviced as soon as they are received.

·  initial_uart()

This function initializes the EUSART module of the microcontroller to the same baud rate as CAN and it uses the BAUDCON register to set the value. The function enables transmit and receive interrupts through the PIE1 register and sets these interrupts to a low priority through the IPR1 register. Then the function initializes transmit and receive buffers which will hold characters before being transferred into the TXSTA and RCSTA registers.

·  uart_putc(char data)

This function is responsible for loading data into the circular buffer. First the function checks to make sure that the data being passed in is valid ASCII data. If the data is valid, then the function waits for space in the buffer and then loads the data into the transmit circular buffer. The data is eventually loaded from the circular buffer to the TXSTA register and finally transmitted from this register.

·  uart_puts(static const rom char *data)

This function takes the passed string and loads it into the transmit circular buffer character by character using the uart_putc(char ) function. The main purpose of this function is to transmit any error messages to the screen during the DEBUG mode.