#include "Arduino.h"
#include "PrintStream.h"
#include "STM32FreeRTOS.h"
Go to the source code of this file.
Macros | |
#define | DIRECT 1 |
Macro definition for direct drive button state. | |
#define | COAST 2 |
Macro definition for coast mode button state. | |
#define | REGEN 3 |
Macro definition for regenerative braking button state. | |
#define | BOOST 4 |
Macro definition for boost mode button state. | |
#define | PEDAL 5 |
Macro definition for pedal charge button state. | |
#define | CAN_ERROR 9999 |
Macro definition for CAN error code. More... | |
#define | CAN_OTHER 9998 |
Macro definition for diagnosing other tranmsission errors. More... | |
Functions | |
void | task_display (void *params) |
Task which interacts with the Nextion display. More... | |
void | task_CAN (void *params) |
Task which interacts with the CAN bus. More... | |
void | task_HALL1 (void *params) |
Task which reads a hall effect sensor. More... | |
This is the header file for the inteface task functions.
#define CAN_ERROR 9999 |
Macro definition for CAN error code.
If a message is unable to be received from the ECDR 0506-A, then the CAN task will assign the stored message variable as this error code. This is used to alert the user if an error has occured in the CAN transmision.
#define CAN_OTHER 9998 |
Macro definition for diagnosing other tranmsission errors.
When debugging CAN transmission problems, it is sometimes helpful to determine if the physical connection is the problem, or if the problem is software-related. The CAN_ERROR message is used to diagnose hardware problems, either with the physical CAN wires or the MCP2515. This message is used if there isn't a problem with the physical link, but a different message was received from what the CAN task was looking for.
void task_CAN | ( | void * | p_params | ) |
Task which interacts with the CAN bus.
This task sends the current user-chosen drive mode to the PLC and reads the accumulator pressure, using the CAN bus. We interface with the CAN bus using an MCP2515 controller. On the custom PCB, the MCP2515 controller uses an 8 MHz crystal to clock the CAN bitrate. However, the mcp2515.cpp and mcp2515.h files clock the bitrate using a 16 MHz crystal. This parameter was altered in those files to set the correct bitrate.
The image above captures the function, setBitrate(), which is part of the MCP2515 library written by GitHub user autowp. The second argument provided to the function represents the type of oscillator used with the MCP2515 integrated-circuit. By default, this value is 16 MHz. However, the PCB designed for this project uses an 8 MHz crystal instead of a 16 MHz one. To establish the correct communication speed on the CAN bus, this parameter must be changed to MCP_8MHZ, as outlined in red in the image above.
p_params | A pointer to function parameters which we don't use. |
void task_display | ( | void * | p_params | ) |
Task which interacts with the Nextion display.
This task updates various data on the Nextion, which includes the accumulator pressure and the speed of the vehicle.
p_params | A pointer to function parameters which we don't use. |
void task_HALL1 | ( | void * | p_params | ) |
Task which reads a hall effect sensor.
This task polls the GPIO pin for the hall effect sensor. Whenever the triggers low, the task retains the elapsed time, in milliseconds, between pulses. We use the circumference of the wheel to calculate the distance traveled between pulses, and then divide by the time between pulses to calculate speed, which is subsequently converted to miles per hour.
p_params | A pointer to function parameters which we don't use. |