Skip to content

Commit 1cf5d43

Browse files
committed
WORKING: Outputs of IOManagement output specified values correctly
* Use new DAC library for analog outputs * Add output testing code in main.cpp
1 parent bf0ac46 commit 1cf5d43

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

include/IOManagement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __IO_MANAGER_H__
33

44
#include "PID.h"
5+
#include "dac.h"
56
#include "adc.h"
67
#include "const.h"
78
#include "STM32TimerInterrupt_Generic.h"

src/IOManagement.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ void initIO() {
2222

2323
initADC(ADC1);
2424

25-
if(IOTimer.attachInterruptInterval(IO_UPDATE_PERIOD, readIO))
26-
{
25+
uint32_t channels[2] = {DAC_CHANNEL_1, DAC_CHANNEL_2};
26+
initDAC(DAC1, channels, 2);
27+
28+
if(IOTimer.attachInterruptInterval(IO_UPDATE_PERIOD, readIO)) {
2729
printf("starting IO timer\n");
28-
}
29-
else
30-
{
30+
} else {
3131
printf("problem starting IO timer\n");
3232
}
3333
}
@@ -56,10 +56,10 @@ void set_eco_mode(bool eco){
5656

5757
void writeAccOut(float newAccOut) {
5858
acc_out = newAccOut;
59-
analogWrite(PA5, acc_out);
59+
writeDAC(DAC_CHANNEL_2, newAccOut); // PA_5
6060
}
6161

6262
void writeRegenBrake(float newRegenBrake) {
6363
regen_brake = newRegenBrake;
64-
analogWrite(PA4, regen_brake);
64+
writeDAC(DAC_CHANNEL_1, newRegenBrake); // PA_4
6565
}

src/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#include <Arduino.h>
22
#include "IOManagement.h"
3+
#include "dac.h"
34
#include "const.h"
45
#include "canPDC.h"
56
#include "speed_calc.h"
67

78
CANPDC canBus(CAN1, DEF);
89

910
uint8_t counter = 0;
11+
bool digital_output = false;
1012

1113
void setup() {
1214
Serial.begin(115200);
@@ -35,5 +37,15 @@ void loop() {
3537
printf("5V current: %f\n", lv_5V_current);
3638
printf("current in: %f\n", current_in_telem);
3739
printf("brake pressure: %f\n", brake_pressure_telem);
40+
41+
// digital outputs
42+
digital_output = !digital_output;
43+
printf("direction: %d\n", digital_output);
44+
set_direction(digital_output);
45+
set_eco_mode(!digital_output);
46+
47+
// analog outputs
48+
writeAccOut(0.5);
49+
writeRegenBrake(0.75);
3850
}
3951
}

0 commit comments

Comments
 (0)