Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #33

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
.vscode/

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/cmake-microchip"]
path = external/cmake-microchip
url = git://github.com/Elemecca/cmake-microchip.git
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.3)

# set up the Microchip cross toolchain
set(CMAKE_TOOLCHAIN_FILE external/cmake-microchip/toolchain.cmake)

# set the default MCU model
set(MICROCHIP_MCU PIC18F26K22)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

project(xc8-cmake C)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic")
set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_C_FLAGS_RELEASE "-O3")

#add_subdirectory(src/)
add_subdirectory(version2/)
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Register | Access | Description | Unit | Values
0xA6 | R/W | Charging current | 0.1 A | 6 - 80
0xA7 | R/W | Access bit | | 0:No Access / 1:Access
0xA8 | R/W | EVSE mode (without saving) | | 0:Normal / 1:Smart / 2:Solar
0xA9 | R | Internal Temperature in C°

## Register 0xC*: Configuration

Expand All @@ -118,6 +119,12 @@ Register | Access | Description | Unit | Values
0xC7 | R/W | External Switch on IO2 | | 0:Disable / 1:Access Push-Button / 2:Access Switch / 3:Smart-Solar Push-Button / 4:Smart-Solar Switch
0xC8 | R/W | Residual Current Monitor on IO3 | | 0:Disable / 1:Enable

## Register 0xD*: Extended Configuration

Register | Access | Description | Unit | Values
--- | --- | --- | --- | ---
0xD0 | R/W | Disable Menu | | 0: Menu Enabled / 1: Menu Disable

## Register 0xE*: Load balancing configuration (same on all SmartEVSE)

Register | Access | Description | Unit | Values
Expand Down
1 change: 1 addition & 0 deletions external/cmake-microchip
Submodule cmake-microchip added at c7462a
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(SOURCES
CurrentTX.c
EVSE.c
LCD.c
)

add_executable(version1 ${SOURCES})
target_include_directories(version1 PRIVATE ./)

target_link_libraries(version1)
11 changes: 11 additions & 0 deletions version2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(SOURCES
SmartEVSE2.X/bootloader.c
SmartEVSE2.X/EVSE.c
SmartEVSE2.X/GLCD.c
SmartEVSE2.X/utils.c
)

add_executable(version2 ${SOURCES})
target_include_directories(version2 PRIVATE SmartEVSE2.X/)

target_link_libraries(version2)
189 changes: 137 additions & 52 deletions version2/SmartEVSE2.X/EVSE.c

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions version2/SmartEVSE2.X/EVSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,17 @@
#define NO_SUN 32
#define Test_IO 64
#define BL_FLASH 128
#define ERROR_CABLE_DEFECTIVE 256 // PP (Proximity Pilot) defective
#define ERROR_LOCK 512 // Lock failed

#define SOLENOID_LOCK {LATAbits.LATA4 = 1;LATAbits.LATA5 = 0;}
#define SOLENOID_UNLOCK {LATAbits.LATA4 = 0;LATAbits.LATA5 = 1;}
#define SOLENOID_OFF {LATAbits.LATA4 = 1;LATAbits.LATA5 = 1;}

#define SOLENOID_REALY_DELAY_MAX 1000 // max wait time for Lock in Realy mode
#define SOLENOID_REALY_ON {LATAbits.LATA4 = 0;LATAbits.LATA5 = 1;}
#define SOLENOID_REALY_OFF {LATAbits.LATA4 = 0;LATAbits.LATA5 = 0;}

#define CONTACTOR_OFF LATBbits.LATB4 = 0; // Contactor OFF
#define CONTACTOR_ON LATBbits.LATB4 = 1; // Contactor ON

Expand Down Expand Up @@ -159,6 +165,9 @@
#define STATUS_CURRENT 70
#define STATUS_ACCESS 71
#define STATUS_MODE 72
#define STATUS_TEMP 73

#define EX_LOCK_MENU 100

#define EM_SENSORBOX 1 // Mains meter types
#define EM_PHOENIX_CONTACT 2
Expand Down Expand Up @@ -210,10 +219,12 @@ extern unsigned char PVMeterAddress;
extern unsigned char EVSEMeter; // Type of EVSE electric meter (0: Disabled / 10: Phoenix Contact / 20: Finder)
extern unsigned char EVSEMeterAddress;

extern unsigned char EX_disable_menu;

extern signed double Irms[3]; // Momentary current per Phase (Amps *10) (23 = 2.3A)

extern unsigned char State;
extern unsigned char Error;
extern unsigned int Error;
extern unsigned char NextState;

extern unsigned int MaxCapacity; // Cable limit (Amps)(limited by the wire in the charge cable, set automatically, or manually if Config=Fixed Cable)
Expand Down Expand Up @@ -258,7 +269,7 @@ const far struct {
{"LOADBL", "LOAD BAL", "Set Load Balancing mode for 2-4 SmartEVSEs", 0, 4, LOADBL},
{"MIN", "MIN", "Set MIN Charge Current the EV will accept", 6, 16, MIN_CURRENT},
{"CIRCUIT","CIRCUIT", "Set EVSE Circuit max Current", 10, 80, MAX_CIRCUIT},
{"LOCK", "LOCK", "Cable locking actuator type", 0, 2, LOCK},
{"LOCK", "LOCK", "Cable locking actuator type", 0, 3, LOCK},
{"START", "START", "Surplus energy start Current", 1, 16, START_CURRENT},
{"STOP", "STOP", "Stop solar charging at 6A after this time", 0, 60, STOP_TIME},
{"IMPORT", "IMPORT", "Allow grid power when solar charging", 0, 6, IMPORT_CURRENT},
Expand Down
24 changes: 20 additions & 4 deletions version2/SmartEVSE2.X/GLCD.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ void GLCD(void) {
unsigned int seconds, minutes;
static unsigned char energy_mains = 20; // X position
static unsigned char energy_ev = 74; // X position
unsigned char buf[8] = {0};

if (LCDNav) {
if (LCDTimer++ == 120) {
Expand Down Expand Up @@ -477,6 +478,16 @@ void GLCD(void) {
GLCD_print2(2, (const far char *) "BOOTLOADER");
GLCD_print2(4, (const far char *) "UPDATE ERR");
return;
} else if (Error & ERROR_LOCK) {
GLCD_print2(2, (const far char *) "ERROR");
GLCD_print2(4, (const far char *) "LOCK");
GLCD_print2(6, (const far char *) "FAILED");
return;
} else if (Error & ERROR_CABLE_DEFECTIVE) {
GLCD_print2(2, (const far char *) "ERROR");
GLCD_print2(4, (const far char *) "CABLE");
GLCD_print2(6, (const far char *) "DEFECTIVE");
return;
}
}

Expand Down Expand Up @@ -516,8 +527,11 @@ void GLCD(void) {
{ // STATE A and STATE B
glcd_clrln(0, 0x00);
glcd_clrln(1, 0x04); // horizontal line

if (Access_bit) {
if (Error) {
GLCD_print2(2, (const far char *) "ERROR");
sprintf(buf, "%d", Error);
GLCD_print2(4, (const far char *) &buf[0]);
} else if (Access_bit) {
GLCD_print2(2, (const far char *) "READY TO");
GLCD_print2(4, (const far char *) "CHARGE ");
if (ChargeDelay) { // show chargedelay
Expand Down Expand Up @@ -713,11 +727,13 @@ void GLCDMenu(unsigned char Buttons) {
Error &= ~RCD_TRIPPED; // Clear RCD error bit, by pressing any button
}

if ((LCDNav == 0) && (Buttons == 0x5) && (ButtonRelease == 0)) // Button 2 pressed ?
if ((LCDNav == 0) && (Buttons == 0x5) && (ButtonRelease == 0) // Button 2 pressed ?
&& EX_disable_menu != 1) // menu not disabled
{
LCDNav = MENU_ENTER; // about to enter menu
ButtonTimer = Timer;
} else if (LCDNav == MENU_ENTER && ((ButtonTimer + 2000) < Timer)) // <CONFIG>
} else if (LCDNav == MENU_ENTER && ((ButtonTimer + 2000) < Timer) // <CONFIG>
&& EX_disable_menu != 1) // menu not disabled
{
LCDNav = MENU_CONFIG; // Main Menu entered
ButtonRelease = 1;
Expand Down