Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
# HIL Tester for PER
# HIL2 Tester for PER

## Running
## Folders

- Code in `./TestBench` runs on the Arduino
- Basically it just reads commands over the serial port and either executs them or writes messages back over the serial port
- To flash it, use the Arduino IDE
- Code in `./scripts` starts the Python code that runs on your laptop
- It uses all the Python files
- Each file in `./scripts` can run a Pytest script to test some board or signal set on the car
- Make sure you correctly set `firmware_path` in `./hil_params.json` to the path of the primary PER firmware repo!
- `./TestBench`: the Teensy code
- `./hil2`: the main HIL "engine"
- `./mk_assert`: a simple and low magic test framework
- `./tests`: the test scripts and configuration files
- `./device_configs`: the device configuration files

## Python ibraries
## Python libraries

- `pyserial` for serial communication
- `pytest` (and `pytest-check`) for testing
- `python-can`, `cantools`, and `gs_usb` for CAN communication
- `numpy` for data types
- `jsonschema` for validating JSON files

## Notes

### Input vs Output

- `AI`/`DI` = inputs to hil (reads from the car/other board -> Arduino -> laptop/Python)
- `AO`/`DO` = outputs from hil (writes from laptop/Python -> Arduino -> car/other board)
- `cantools` for CAN DBC encoding/decoding
- `colorama` for cross platform colored terminal output
77 changes: 77 additions & 0 deletions TestBench/Adafruit_MCP4706.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**************************************************************************/
/*!
Authors:
- Original: K.Townsend (Adafruit Industries)
- Modified for MCP4706 by Pio Baettig
- Now modifed by Millan kumar for PER HIL 2.0 2025 usage
*/
/**************************************************************************/

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <Wire.h>

#include "Adafruit_MCP4706.h"

/**************************************************************************/
/*!
@brief Instantiates a new MCP4706 class
*/
/**************************************************************************/
Adafruit_MCP4706::Adafruit_MCP4706() { }

/**************************************************************************/
/*!
@brief Setups the HW
*/
/**************************************************************************/
void Adafruit_MCP4706::begin(uint8_t addr, TwoWire &wire) {
_i2caddr = addr;
_wire = &wire;
_wire->begin();
}

/**************************************************************************/
/*!
@brief Sets the output voltage to a fraction of source vref. (Value
can be 0..255)

@param[in] output
The 8-bit value representing the relationship between
the DAC's input voltage and its output voltage.
*/
/**************************************************************************/
void Adafruit_MCP4706::setVoltage(uint8_t output) {
uint8_t twbrback = TWBR;
TWBR = 12; // 400 khz
// TWBR = 72; // 100 khz
_wire->beginTransmission(_i2caddr);
_wire->write(MCP4706_CMD_VOLDAC); // First byte: Command (CMD_VOLDAC = 0)
_wire->write(output); // Second byte: Data bits (D7.D6.D5.D4.D3.D2.D1.D0)
_wire->endTransmission();
TWBR = twbrback;
}


/**************************************************************************/
/*!
@brief Puts the DAC into a low power state using the specified resistor mode

@param[in] mode
Power-down mode, one of:
- MCP4706_AWAKE
- MCP4706_PWRDN_1K
- MCP4706_PWRDN_100K
- MCP4706_PWRDN_500K
*/
/**************************************************************************/
void Adafruit_MCP4706::setMode(uint8_t mode) {
uint8_t config = (mode & ~MCP4706_PWRDN_MASK); // ensure only power-down bits are set
_wire->beginTransmission(_i2caddr);
_wire->write(config | MCP4706_CMD_VOLCONFIG); // command with config register
_wire->endTransmission();
}
42 changes: 42 additions & 0 deletions TestBench/Adafruit_MCP4706.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**************************************************************************/
/*!
Authors:
- Original: K.Townsend (Adafruit Industries)
- Modified for MCP4706 by Pio Baettig
- Now modifed by Millan kumar for PER HIL 2.0 2025 usage
*/
/**************************************************************************/

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <Wire.h>

// Power Down Mode definitions
#define MCP4706_PWRDN_MASK 0xF9
#define MCP4706_AWAKE 0x00
#define MCP4706_PWRDN_1K 0x02
#define MCP4706_PWRDN_100K 0x04
#define MCP4706_PWRDN_500K 0x06

// Command definitioins
#define MCP4706_CMD_MASK 0x1F
#define MCP4706_CMD_VOLDAC 0x00
#define MCP4706_CMD_VOLALL 0x40
#define MCP4706_CMD_VOLCONFIG 0x80
#define MCP4706_CMD_ALL 0x60

class Adafruit_MCP4706{
public:
Adafruit_MCP4706();
void begin(uint8_t addr, TwoWire &wire = Wire);
void setVoltage(uint8_t output);
void setMode(uint8_t mode);

private:
uint8_t _i2caddr;
TwoWire *_wire;
};
Loading