Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:92d505d15a7b
- Parent:
- 1:a9315bd73ea5
--- a/main.cpp Wed Nov 02 16:51:12 2016 +0000
+++ b/main.cpp Wed Nov 02 20:42:19 2016 +0000
@@ -21,7 +21,7 @@
DigitalOut blue(D11);
unsigned char control_pilot;
-float pwm;
+float pwmSet;
#define PILOT_12V 1
#define PILOT_9V 2
@@ -39,11 +39,8 @@
float CP_average=0;
float CP_previous_average=0;
-float PP_value;
-float PP_reading;
unsigned char cableType;
-unsigned char chargerType;
void timedOut() {
resetCharger = true;
@@ -83,102 +80,64 @@
button.rise(&resetRelease);
while(1){
-
- //----------------------END Cable detection, Charger Power Check, Cable Power Check---------------------------//
- float PP_value = pp_value.read();
- PP_value = PP_value * 3300;
-
- if(PP_value == 3300){
- printf("Cable not detected \r\n");
- printf("Charger Type %u AMP \r\n", CHARGER_PRESET);
- chargerType = 0;
- }//end if
- else{
- if(CHARGER_PRESET == 16){
- chargerType = 16;
- printf("Charger 16AMP ONLY \r\n");
- pwm=0.734;
- printf("PWM @ 26.6% \r\n");
- }// end if
- else if(CHARGER_PRESET == 32){
- if((PP_value > 200) && (PP_value < 300)){
- printf("32 AMP charger \n\r\r");
- printf("16 AMP cable detected \n\r\r");
- chargerType = 16;
- pwm=0.734; //////////////////////////////////////////////////////////////////
- printf("PWM @ 26.6%\r\n"); //////////////////////////////////////////////////////////////////
- }
- if((PP_value > 0 ) && (PP_value < 100)){
- printf("32 AMP charger \n\r\r");
- printf("32 AMP cable detected \r\n");
- chargerType = 32;
- pwm=0.468;
- printf("PWM @ 52.2%\r\n");
- }
- }
-
- }
- //--------------------------------------Post instertatiom signaling CP-----------------------------------------//
-
-
-
+
+ float PP_value = pp_value.read();
+ PP_value = PP_value * 3300;
- for (int i = 0; i < NUM_SAMPLES ; i++){
- float CP_sample_value = cp_value.read_u16();
- CP_sample_value = (float) 3300 / 65535 * (float) CP_sample_value; // convert sample to voltage
- CP_average = ((CP_sample_value + (i * CP_previous_average)) / (i+1));
- CP_previous_average = CP_average;
- }
- printf("CP Average Value = %.f \n\r", CP_average);
- printf("PP Value = %.0f mV\n\r",PP_value);
- printf("\n\r");
-
-
-
- //--------------------------------------------- PILOT CHECK --------------------------------------------------//
+
+
+
+ for (int i = 0; i < NUM_SAMPLES ; i++){
+ float CP_sample_value = cp_value.read_u16();
+ CP_sample_value = (float) 3300 / 65535 * (float) CP_sample_value; // convert sample to voltage
+ CP_average = ((CP_sample_value + (i * CP_previous_average)) / (i+1));
+ CP_previous_average = CP_average;
+ }
+ printf("CP Average Value = %.f \n\r", CP_average);
+ printf("PP Value = %.0f mV\n\r",PP_value);
+ printf("\n\r");
-if(chargerType == 0){
- control_pilot = PILOT_12V;
- resetCharger = false; //-----check this for restet------//
- printf("12 V \n\r");
- printf("\n\r");
-}
+if(PP_value>3200){ //NO CABLE IN
-if(chargerType == 16){
- if(((CP_average > 1900)&&(2100 > CP_average))||((CP_average > 550)&&(650 > CP_average))){
- control_pilot = PILOT_9V;
- printf("16amp@ 9 V \n\r");
- printf("\n\r");
- }
+ if ((2750 > CP_average) && (CP_average > 2650) || (800 > CP_average) && (CP_average > 700)){
+ control_pilot = PILOT_12V; // Pilot at 12V
+ }
+ if (CP_average < 100){ // first reading ˜2702 & ˜755 after
+ control_pilot = PILOT_12V; // Pilot at 12V
+ resetCharger = false;
+ }
+}
- if((CP_average > 400)&&(500 > CP_average)){
- control_pilot = PILOT_6V;
- printf("16amp@ 6 V \n\r");
- printf("\n\r");
- }
-
- if((resetCharger == true)||((CP_average > 700)&&(800 > CP_average))){
- control_pilot = PILOT_RESET;
- printf("reset \n\r");
- printf("\n\r");
- }
+if((300 > PP_value) && (PP_value >200)){ //16AMP CABLE IN
+ pwmSet=0.734;
+ if(((CP_average > 1900)&&(2100 > CP_average))||((CP_average > 550)&&(650 > CP_average))){
+ control_pilot = PILOT_9V;
+ printf("16amp@ 9 V \n\r");
+ }
+ if((CP_average > 400)&&(500 > CP_average)){
+ control_pilot = PILOT_6V;
+ printf("16amp@ 6 V \n\r");
+ }
+ if((resetCharger == true)||((CP_average > 700)&&(800 > CP_average))){
+ control_pilot = PILOT_RESET;
+ printf("reset \n\r");
+ }
}
-if(chargerType == 32){
- if(((CP_average > 1900)&&(2100 > CP_average))||((CP_average > 1070)&&(1170 > CP_average))){
- control_pilot = PILOT_9V;
- printf("32amp@ 9 V \n\r");
- printf("\n\r");
- }
- if((CP_average > 730)&&(830 > CP_average)){
- control_pilot = PILOT_6V;
- printf("32amp@ 6 V \n\r");
- printf("\n\r");
- }
- if(resetCharger == true){
- control_pilot = PILOT_RESET;
- printf("reset \n\r");
- printf("\n\r");
- }
+
+if(100 > PP_value){//32AMP CABLE IN
+ pwmSet=0.468;
+ if(((CP_average > 1900)&&(2100 > CP_average))||((CP_average > 1070)&&(1170 > CP_average))){
+ control_pilot = PILOT_9V;
+ printf("32amp@ 9 V \n\r");
+ }
+ if((CP_average > 730)&&(830 > CP_average)){
+ control_pilot = PILOT_6V;
+ printf("32amp@ 6 V \n\r");
+ }
+ if(resetCharger == true){
+ control_pilot = PILOT_RESET;
+ printf("reset \n\r");
+ }
}
//------------------------------------------- STATE ASSIGNED ------------------------------------------------//
@@ -197,12 +156,10 @@
case PILOT_9V:
contactor =0;
- // relay=0;
lock=1;
my_pwm.period_ms(1);
my_pwm.pulsewidth_ms(1);
- //my_pwm.write(0.734);
- my_pwm.write(pwm);
+ my_pwm.write(pwmSet);
printf("Charger in STATE b\r\n");
printf("PILOT_9V - Pilot at 9 V \n\r");
red = 1;
@@ -216,9 +173,7 @@
lock=1;
my_pwm.period_ms(1);
my_pwm.pulsewidth_ms(1);
- my_pwm.write(pwm); // 8 amp charger setup
- //my_pwm.write(0.734); // 16 amp charger setup
-
+ my_pwm.write(pwmSet);
printf("Charger in STATE c\r\n");
printf("PILOT_6V - Pilot at 6 V \n\r");
red = 0;
@@ -254,7 +209,7 @@
}//end switch
- //wait(2);
+wait(2);
} //end while(1)