source: trunk/firmware_v3/SES/src/relais.c

Last change on this file was 41, checked in by f.jahn, 8 days ago

V3 Version soweit fertig. Relais ansteuerung, modbus, temperatursensor ist implementiert
Commit vor Änderung auf neuen Controller mit mehr Speicher

File size: 1.8 KB
Line 
1#include "relais.h"
2#include "main.h"
3
4
5#define PULS_TIME 50
6
7
8
9unsigned int onTimeCounterSET; //Set Coil
10unsigned int onTimeCounterRESET; //Reset Coil
11unsigned int relaisState;
12int32_t relais_temperature;
13
14
15uint16_t RELAIS_GetTemp(void)
16{
17 return relais_temperature;
18}
19
20void RELAIS_Exec(uint32_t adcValue)
21{
22
23
24 int32_t temp = adcValue;
25 temp = temp * VREF;
26 temp = temp / 65635; // Spannung
27 temp = (temp - 600) / 10; //Temperatur
28 relais_temperature = temp;
29
30
31 if (onTimeCounterSET > 0)
32 {
33 onTimeCounterSET--;
34 if (onTimeCounterSET == 0)
35 {
36 HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_SET_GPIO_Port, GPIO_OUTPUT_RELAIS_SET_Pin, GPIO_PIN_RESET);
37 }
38 }
39
40
41
42if (onTimeCounterRESET > 0)
43 {
44 onTimeCounterRESET--;
45 if (onTimeCounterRESET == 0)
46 {
47 HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_RESET_GPIO_Port, GPIO_OUTPUT_RELAIS_RESET_Pin, GPIO_PIN_RESET);
48 }
49 }
50
51}
52
53void RELAIS_SetPuls(void)
54{
55
56 //Sicherstellen das nicht noch die Reset Spule aktiv geschaltet ist
57 HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_RESET_GPIO_Port, GPIO_OUTPUT_RELAIS_RESET_Pin, GPIO_PIN_RESET);
58
59 //Puls starten
60 HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_SET_GPIO_Port, GPIO_OUTPUT_RELAIS_SET_Pin, GPIO_PIN_SET);
61 onTimeCounterSET = PULS_TIME;
62 relaisState = 1;
63
64}
65
66void RELAIS_ResetPuls(void)
67{
68
69 //Sicherstellen das nicht noch die Set Spule aktiv geschaltet ist
70 HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_SET_GPIO_Port, GPIO_OUTPUT_RELAIS_SET_Pin, GPIO_PIN_RESET);
71
72 //Puls starten
73 HAL_GPIO_WritePin(GPIO_OUTPUT_RELAIS_RESET_GPIO_Port, GPIO_OUTPUT_RELAIS_RESET_Pin, GPIO_PIN_SET);
74 onTimeCounterRESET = PULS_TIME;
75 relaisState = 0;
76
77}
78
79
80unsigned int RELAIS_GetState(void)
81{
82 return relaisState;
83}
Note: See TracBrowser for help on using the repository browser.