Procházet zdrojové kódy

Manual Heater Power control.

Vladimir N. Shilov před 3 roky
rodič
revize
97c6489a02
3 změnil soubory, kde provedl 86 přidání a 52 odebrání
  1. 1 0
      Dryer.cbp
  2. 32 27
      Dryer.layout
  3. 53 25
      src/main.c

+ 1 - 0
Dryer.cbp

@@ -50,6 +50,7 @@
 			<Add after="avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).eep" />
 			<Add after="avr-objcopy --no-change-warnings -j .fuse --change-section-lma .fuse=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).fuse" />
 		</ExtraCommands>
+		<Unit filename="inc/bresenham.h" />
 		<Unit filename="inc/i2c.h" />
 		<Unit filename="inc/main.h" />
 		<Unit filename="inc/sensor.h" />

+ 32 - 27
Dryer.layout

@@ -2,74 +2,79 @@
 <CodeBlocks_layout_file>
 	<FileVersion major="1" minor="0" />
 	<ActiveTarget name="Debug" />
-	<File name="lib\ssd1306xled\ssd1306xledtx.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xledtx.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="951" topLine="0" />
+			<Cursor1 position="2451" topLine="66" />
 		</Cursor>
 	</File>
-	<File name="lib\tinyavrlib\num2str.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\font8x16.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="3534" topLine="43" />
+			<Cursor1 position="1017" topLine="24" />
+		</Cursor>
+	</File>
+	<File name="lib\rtos\rtos.c" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="4343" topLine="110" />
 		</Cursor>
 	</File>
 	<File name="inc\sensor.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="388" topLine="0" />
+			<Cursor1 position="257" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="src\sensor.c" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xled.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="3362" topLine="165" />
+			<Cursor1 position="1177" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="src\i2c.c" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\i2c.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2571" topLine="71" />
+			<Cursor1 position="88" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="lib\ssd1306xled\font8x16.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1017" topLine="24" />
+			<Cursor1 position="3098" topLine="72" />
 		</Cursor>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xled.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\rtos\rtos.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1177" topLine="0" />
+			<Cursor1 position="2615" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xledtx.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xled.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2451" topLine="66" />
+			<Cursor1 position="5259" topLine="23" />
 		</Cursor>
 	</File>
-	<File name="inc\main.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\sensor.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2252" topLine="56" />
+			<Cursor1 position="3362" topLine="54" />
 		</Cursor>
 	</File>
-	<File name="lib\rtos\rtos.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\i2c.c" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2615" topLine="0" />
+			<Cursor1 position="2571" topLine="71" />
 		</Cursor>
 	</File>
-	<File name="lib\rtos\rtos.c" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\main.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="4343" topLine="110" />
+			<Cursor1 position="2252" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="src\main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\bresenham.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1393" topLine="41" />
+			<Cursor1 position="786" topLine="13" />
 		</Cursor>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xled.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\tinyavrlib\num2str.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="5259" topLine="23" />
+			<Cursor1 position="3534" topLine="43" />
 		</Cursor>
 	</File>
-	<File name="inc\i2c.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xledtx.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="88" topLine="0" />
+			<Cursor1 position="951" topLine="0" />
 		</Cursor>
 	</File>
 </CodeBlocks_layout_file>

+ 53 - 25
src/main.c

@@ -10,9 +10,13 @@
 #include "ssd1306xled/ssd1306xled.h"
 #include "ssd1306xled/ssd1306xledtx.h"
 #include "tinyavrlib/num2str.h"
+#include "bresenham.h"
 #include "string.h"
 
 /* Defines */
+#define HEATER_PERIOD_MS  1000
+#define HEATER_STEP_MS    10
+#define HEATER_POWER_MAX  (uint8_t)((HEATER_PERIOD_MS / HEATER_STEP_MS) - 1)
 
 /* Variables */
 static volatile struct {
@@ -20,8 +24,9 @@ static volatile struct {
   uint8_t AHT10state: 1;
   uint8_t rezerv:     6;
 } Flag;
-uint8_t TemperatureSetpoint;
-aht20_t Sensor;
+static uint8_t TemperatureSetpoint = 0;
+static aht20_t Sensor;
+static bresenham_t Heater;
 
 /* Function prototypes */
 static void board_Init(void);
@@ -30,6 +35,7 @@ static void sensorStart(void);
 static void sensorGetData(void);
 static void LedOn(void);
 static void LedOff(void);
+static void HeaterCtrl(void);
 
 int main(void) {
   /* Init all */
@@ -44,10 +50,18 @@ int main(void) {
   Flag.newTempSet = 1;
   Flag.AHT10state = 0;
 
+  /* Bresenham init.
+   * step - 10 ms, period - 1 sek, heater - off */
+  bresenham_Init(&Heater, HEATER_POWER_MAX);
+  bresenham_setValue(&Heater, TemperatureSetpoint);
+  RTOS_SetTask(HeaterCtrl, HEATER_PERIOD_MS, HEATER_PERIOD_MS);
+
   /* Set tasks */
+  RTOS_SetTask(sensorStart, 502, 1000);
+  RTOS_SetTask(sensorGetData, 952, 1000);
   RTOS_SetTask(checkTemperatureSetpoint, 5, 50);
-  RTOS_SetTask(sensorStart, 50, 1000);
-  RTOS_SetTask(sensorGetData, 800, 1000);
+
+  /* HeartBeat */
   RTOS_SetTask(LedOn, 1, 1000);
   RTOS_SetTask(LedOff, 201, 1000);
 
@@ -59,7 +73,7 @@ int main(void) {
   tdelay_ms(1000);
 
   ssd1306_clear();
-  ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 0, "Set:");
+  ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 0, "Pwr:"); // Set
   ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 3, "  T:");
   ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 5, "  H:");
   char buffer[9] = {0};
@@ -72,11 +86,13 @@ int main(void) {
     Flag.newTempSet = 0;
     if (TemperatureSetpoint != 0) {
       digits = usint2decascii(TemperatureSetpoint, buffer);
-      strncpy(buffer+5, " C \0", 4);
+      strncpy(buffer+5, " % \0", 4); // C
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 0, buffer+digits);
     } else {
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 0, " Off");
     }
+    // set new Heater Power
+    bresenham_setValue(&Heater, TemperatureSetpoint);
   }
 
     if (Flag.AHT10state == 0) {
@@ -88,9 +104,8 @@ int main(void) {
       strncpy(buffer+5, " %\0", 3);
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 5, buffer+digits);
     } else {
-      //ssd1306tx_string("AHT10 error");
-      ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 3, "Error");
-      ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 5, "     ");
+      ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 3, " I2C ");
+      ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 5, "Error");
     }
 
     RTOS_DispatchTask();
@@ -140,6 +155,9 @@ static void board_Init(void) {
   ENABLE_INTERRUPT;
 }
 
+/**
+ * Setup Temperature Set Point by valcoder value
+ */
 static void checkTemperatureSetpoint(void) {
   static uint8_t oldTempSet = 0;
   uint8_t pvalue;
@@ -147,29 +165,29 @@ static void checkTemperatureSetpoint(void) {
   pvalue = ~(PIND);
   if (pvalue != 0) {
     switch (pvalue) {
-    case 1<<PB0:
-      TemperatureSetpoint = 55;
+    case 1<<PD0:
+      TemperatureSetpoint = 20; //55;
       break;
-    case 1<<PB1:
-      TemperatureSetpoint = 50;
+    case 1<<PD1:
+      TemperatureSetpoint = 10; //50;
       break;
-    case 1<<PB2:
-      TemperatureSetpoint = 60;
+    case 1<<PD2:
+      TemperatureSetpoint = 30; //60;
       break;
-    case 1<<PB3:
-      TemperatureSetpoint = 65;
+    case 1<<PD3:
+      TemperatureSetpoint = 40; //65;
       break;
-    case 1<<PB4:
-      TemperatureSetpoint = 70;
+    case 1<<PD4:
+      TemperatureSetpoint = 50; //70;
       break;
-    case 1<<PB5:
-      TemperatureSetpoint = 75;
+    case 1<<PD5:
+      TemperatureSetpoint = 60; //75;
       break;
-    case 1<<PB6:
-      TemperatureSetpoint = 80;
+    case 1<<PD6:
+      TemperatureSetpoint = 70; //80;
       break;
-    case 1<<PB7:
-      TemperatureSetpoint = 85;
+    case 1<<PD7:
+      TemperatureSetpoint = 80; //85;
       break;
     default:
       TemperatureSetpoint = 0;
@@ -221,6 +239,16 @@ static void LedOff(void) {
   PORTB &= ~(1<<PB5);
 }
 
+/**
+ * On/Off heater by Bresenham algorithm
+ */
+static void HeaterCtrl(void) {
+  if (bresenham_getNext(&Heater)) {
+    PORTB &= ~(1<<PB1); // Heater ON
+  } else {
+    PORTB |= (1<<PB1);// Heater OFF
+  }
+}
 
 /**
  * I n t e r r u p t s