From 25d877362839a1a4e55d907a3067583351b901d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 24 Feb 2023 15:09:43 +0100 Subject: [PATCH 1/5] value in mV #TODO fix ghost caractere when under100 mV --- solar_panel.X/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c index f217874..5c912bc 100644 --- a/solar_panel.X/main.c +++ b/solar_panel.X/main.c @@ -72,11 +72,12 @@ void main(void) while (1) { - uint16_t value; + float value; - value = ADC_GetConversion(voltage); - char* msg; - sprintf(msg, "%i", value); + value =(float)( ADC_GetConversion(voltage)/19.859); + char msg[16]; + sprintf(msg, "Value : %3.1f mV", value); + // LCD_2x16_WriteCmd(0x01); // clear display LCD_2x16_WriteMsg(msg,0); From d9c91bdcb04f9a01b7f81b518ce5f01bfcf6929c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Fri, 24 Feb 2023 16:23:53 +0100 Subject: [PATCH 2/5] Update .gitignore --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index de7f2fd..4c111fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/build/ -/debug/ -/dist/ \ No newline at end of file +solar_panel.X/build/ +solar_panel.X/debug/ +solar_panel.X/dist/ \ No newline at end of file From 9c30b42e77f9c3a519f98e19e2eabe0aaf91e9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 28 Feb 2023 13:27:23 +0100 Subject: [PATCH 3/5] finish reading voltage --- solar_panel.X/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c index 5c912bc..ad5b932 100644 --- a/solar_panel.X/main.c +++ b/solar_panel.X/main.c @@ -44,6 +44,7 @@ #include "mcc_generated_files/mcc.h" #include "lcd/lcd.h" +#define MAX_COL 16 /* Main application */ @@ -75,9 +76,11 @@ void main(void) float value; value =(float)( ADC_GetConversion(voltage)/19.859); - char msg[16]; - sprintf(msg, "Value : %3.1f mV", value); - // LCD_2x16_WriteCmd(0x01); // clear display + char msg[MAX_COL+1]; + + snprintf(msg, MAX_COL+1, "Value : %3.1f mV ", value); + + //LCD_2x16_WriteCmd(0x01); // clear display LCD_2x16_WriteMsg(msg,0); From 96bcb1c132aad9f1b79d34dd275f104991caf12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 28 Feb 2023 14:08:25 +0100 Subject: [PATCH 4/5] reading current TODO refactor all code --- solar_panel.X/main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c index ad5b932..26348da 100644 --- a/solar_panel.X/main.c +++ b/solar_panel.X/main.c @@ -73,18 +73,24 @@ void main(void) while (1) { - float value; + float valueV; - value =(float)( ADC_GetConversion(voltage)/19.859); + valueV =(float)( ADC_GetConversion(voltage)/19.859); // TODO explain values char msg[MAX_COL+1]; - snprintf(msg, MAX_COL+1, "Value : %3.1f mV ", value); + snprintf(msg, MAX_COL+1, "U = %3.1f [mV] ", valueV); //LCD_2x16_WriteCmd(0x01); // clear display LCD_2x16_WriteMsg(msg,0); + float valueI; + valueI =(float)( ADC_GetConversion(current)/57.667-220.9); // TODO explain values + + snprintf(msg, MAX_COL+1, "I = %3.1f [mA] ", valueI); + + LCD_2x16_WriteMsg(msg,1); From 3af88e833713609e94af83f690b30ea6bc60f065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 28 Feb 2023 14:53:54 +0100 Subject: [PATCH 5/5] refactor done TODO fix Current offset --- solar_panel.X/main.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/solar_panel.X/main.c b/solar_panel.X/main.c index 26348da..0dbb396 100644 --- a/solar_panel.X/main.c +++ b/solar_panel.X/main.c @@ -43,6 +43,7 @@ #include "mcc_generated_files/mcc.h" #include "lcd/lcd.h" +#include "measure.h" #define MAX_COL 16 /* @@ -54,6 +55,7 @@ void main(void) SYSTEM_Initialize(); Lcd_Init(); + adc_init(); // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts @@ -73,38 +75,19 @@ void main(void) while (1) { - float valueV; - valueV =(float)( ADC_GetConversion(voltage)/19.859); // TODO explain values + uint16_t valueV = measure_voltage(); + uint16_t valueI = measure_current(offsetCurrent); + char msg[MAX_COL+1]; - - snprintf(msg, MAX_COL+1, "U = %3.1f [mV] ", valueV); - //LCD_2x16_WriteCmd(0x01); // clear display + snprintf(msg, MAX_COL+1, "U = %4i [mV] ", valueV); LCD_2x16_WriteMsg(msg,0); - float valueI; - - valueI =(float)( ADC_GetConversion(current)/57.667-220.9); // TODO explain values - - snprintf(msg, MAX_COL+1, "I = %3.1f [mA] ", valueI); - + snprintf(msg, MAX_COL+1, "I = %4i [uA] ", valueI); LCD_2x16_WriteMsg(msg,1); - - - - - /* - LCD_2x16_WriteMsg("TURBOPUTE",0); - LCD_2x16_WriteMsg("bip ",1); - for(uint32_t i = 0; i<100000; i++) - {} - LCD_2x16_WriteMsg("boup",1); - for(uint32_t i = 0; i<100000; i++) - {} - */ } } /**