Skip to content

Commit 0bdccff

Browse files
added defines for INA226 and ADS1115
1 parent 23127b8 commit 0bdccff

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

CyphalRobotController07-CAN-firmware.ino

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#include "pio_encoder.h"
2727
#include "RPi_Pico_TimerInterrupt.h"
2828

29-
29+
//#define CTRL_INA226
30+
//#define CTRL_ADS115
3031
#define DBG_ENABLE_ERROR
3132
#define DBG_ENABLE_WARNING
3233
#define DBG_ENABLE_INFO
@@ -96,8 +97,12 @@ Ifx007t mot0;
9697
Ifx007t mot1;
9798
PioEncoder encoder0(ENCODER0_A, pio1);
9899
PioEncoder encoder1(ENCODER1_A, pio1);
100+
#ifdef CTRL_INA226
99101
INA226_WE ina226 = INA226_WE();
102+
#endif
103+
#ifdef CTRL_ADS1115
100104
ADS1115_WE ads1115 = ADS1115_WE();
105+
#endif
101106
RPI_PICO_Timer ITimer0(0);
102107

103108
static int motor0_ticks_per_100ms = 0;
@@ -610,17 +615,21 @@ void setup()
610615
delay(100);
611616
neo_pixel_ctrl.light_green();
612617

618+
#ifdef CTRL_INA226
613619
/* configure INA226, current sensor, set conversion time and average to get a value every two seconds */
614620
ina226.init();
615621
ina226.setResistorRange(0.020,4.0); // choose resistor 20 mOhm and gain range up to 4 A
616622
ina226.setAverage(AVERAGE_512);
617623
ina226.setConversionTime(CONV_TIME_4156);
624+
#endif
618625

626+
#ifdef CTRL_ADS1115
619627
/* configure ADS1115 */
620628
ads1115.init();
621629
ads1115.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range
622630
ads1115.setCompareChannels(ADS1115_COMP_0_GND); //comment line/change parameter to change channel
623631
ads1115.setMeasureMode(ADS1115_CONTINUOUS); //comment line/change parameter to change mode
632+
#endif
624633

625634
/* Enable watchdog. */
626635
rp2040.wdt_begin(WATCHDOG_DELAY_ms);
@@ -686,6 +695,7 @@ void loop()
686695
mot1.pwm(0);
687696
}
688697

698+
#ifdef CTRL_ADS1115
689699
/* get ADS1115 data ever 100 ms */
690700
if((now - prev_ads1115) > 100)
691701
{
@@ -715,6 +725,8 @@ void loop()
715725
ads1115.setCompareChannels_nonblock(ADS1115_COMP_0_GND);
716726
}
717727
}
728+
#endif
729+
#ifdef CTRL_INA226
718730
/* get INA226 data once/second */
719731
if((now - prev_ina226) > 1000)
720732
{
@@ -727,6 +739,7 @@ void loop()
727739
ina226_current_total_mAh += ina226_current_mA/3600.0;
728740
ina226_power_total_mWh += ina226_power_mW/3600.0;
729741
}
742+
#endif
730743
/* check motor timeout */
731744
if(timeout_ms_motor0<0xFFFF)
732745
{

0 commit comments

Comments
 (0)