Skip to content

Commit fb805bf

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 e9595fb commit fb805bf

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
@@ -23,12 +23,12 @@ void initIO() {
2323

2424
initADC(ADC1);
2525

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

6060
void writeAccOut(float newAccOut) {
6161
acc_out = newAccOut;
62-
analogWrite(PA5, acc_out);
62+
writeDAC(DAC_CHANNEL_2, newAccOut); // PA_5
6363
}
6464

6565
void writeRegenBrake(float newRegenBrake) {
6666
regen_brake = newRegenBrake;
67-
analogWrite(PA4, regen_brake);
67+
writeDAC(DAC_CHANNEL_1, newRegenBrake); // PA_4
6868
}

src/main.cpp

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

67
CANPDC canBus(CAN1, DEF);
78

89
uint8_t counter = 0;
10+
bool digital_output = false;
911

1012
void setup() {
1113
Serial.begin(115200);
@@ -33,5 +35,15 @@ void loop() {
3335
printf("5V current: %f\n", lv_5V_current);
3436
printf("current in: %f\n", current_in_telem);
3537
printf("brake pressure: %f\n", brake_pressure_telem);
38+
39+
// digital outputs
40+
digital_output = !digital_output;
41+
printf("direction: %d\n", digital_output);
42+
set_direction(digital_output);
43+
set_eco_mode(!digital_output);
44+
45+
// analog outputs
46+
writeAccOut(0.5);
47+
writeRegenBrake(0.75);
3648
}
3749
}

0 commit comments

Comments
 (0)