Hot Rod did an article on the Prius column, in case you hadn't seen it:
https://www.hotrod.com/how-to/150-elect ... -delivers/
Hot Rod did an article on the Prius column, in case you hadn't seen it:
Code: Select all
#include <mcp_can_dfs.h>
#include <mcp_can.h>
#include <SPI.h>
#include <Arduino.h>
const int STEERING_ANGLE_PIN_A = 4;
const int STEERING_ANGLE_PIN_B = 5;
const int INT_PUMP = 6;
const int SPI_CS_PUMP = 8;
MCP_CAN can_pump(SPI_CS_PUMP);
short int previous_steering_angle = 0;
short int current_steering_angle = 0;
short int target_steering_angle = 0;
bool current_steering_angle_valid = false;
long last_steering_time = 0;
// Globals for CANBUS debug / testing
uint32_t counter = 0;
void convert_201_values(uint8_t buf[]) {
// RPM = uint16_t(bytes 0, 1) * 4
uint16_t engine_speed = ((buf[0] * 256) + buf[1]) / 4;
// Speed in KM/hr = (uint16_t(bytes 4. 5) + 100) * 100
uint16_t vehicle_speed = (((buf[4] * 256) + buf[5]) / 100) - 100;
// Mazda 3 pump expects RPM as raw bytes, no scalar like MX5
// Mazda 3 pump expects km/hr*100, no 100 km offset like MX5
vehicle_speed *= 100;
// Write modified values back into buffer
buf[0] = engine_speed / 256;
buf[1] = engine_speed % 256;
buf[4] = vehicle_speed / 256;
buf[5] = vehicle_speed % 256;
}
// current_steering_angle and target_steering_angle are doubled to allow for .5* resolution without floating point conversion.
void update_steering_outputs() {
// Don't update pin outputs too frequently
if (micros() - last_steering_time < 500) return;
if (target_steering_angle > current_steering_angle) {
current_steering_angle++;
} else if (target_steering_angle < current_steering_angle) {
current_steering_angle--;
}
digitalWrite(STEERING_ANGLE_PIN_A, abs((current_steering_angle / 6) % 2));
digitalWrite(STEERING_ANGLE_PIN_B, abs((((current_steering_angle + 3 )/ 6)% 2)));
last_steering_time = micros();
}
void setup()
{
// Setup digital outputs for steering angle sensor
pinMode(STEERING_ANGLE_PIN_A, OUTPUT);
pinMode(STEERING_ANGLE_PIN_B, OUTPUT);
digitalWrite(STEERING_ANGLE_PIN_A, LOW);
digitalWrite(STEERING_ANGLE_PIN_B, LOW);
uint8_t ret;
ret = can_pump.begin(MCP_ANY, 13, MCP_8MHZ);
if (ret == CAN_OK)
{
can_pump.setMode(MCP_NORMAL);
}
}
// Main program loop. Poll both CAN networks. If 0x201 received from vehicle network, modify and rebroadcast to pump network.
void loop()
{
update_steering_outputs();
uint32_t id;
uint8_t len;
uint8_t buf[24];
uint8_t ret;
// Check interrupt pin for vehicle CAN
// Check if 0x201 ID
if (id == 0x201) {
// 0x201 - modify and rebroadcast to pump
// RPM = uint16_t(bytes 0, 1) * 4
uint16_t engine_speed = ((buf[0] * 256) + buf[1]) / 4;
// Speed in KM/hr = (uint16_t(bytes 4. 5) + 100) * 100
uint16_t vehicle_speed = (((buf[4] * 256) + buf[5]) / 100) - 100;
// Mazda 3 pump expects RPM as raw bytes, no scalar like MX5
// Mazda 3 pump expects km/hr*100, no 100 km offset like MX5
vehicle_speed *= 100;
// Write modified values back into buffer
buf[0] = engine_speed / 256;
buf[1] = engine_speed % 256;
buf[4] = vehicle_speed / 256;
buf[5] = vehicle_speed % 256;
} else if (id == 0x081) {
// Convert from steering angle message format to degrees
int16_t steering_angle;
unsigned char *ip = (unsigned char *) &steering_angle;
ip[0] = buf[3];
ip[1] = buf[2];
uint16_t u_steering_angle = (steering_angle * 10 ) + 1600;
ip = (unsigned char *) &u_steering_angle;
// We initialize steering angle to zero. This conditional makes sure there aren't any wild jumps in output from the first steering message.
if (!current_steering_angle_valid) {
current_steering_angle_valid = true;
current_steering_angle = steering_angle * 2;
previous_steering_angle = current_steering_angle;
}
// Drive outputs for early version Mazda 3 pump (pre 2009)
target_steering_angle = steering_angle * 2;
update_steering_outputs();
previous_steering_angle = current_steering_angle;
}
}
So does this have partial load no load pwm functions? Or just on like they were on older ICE vehicles?
Jacobsmess wrote: ↑Mon Jan 13, 2025 9:27 am So does this have partial load no load pwm functions? Or just on like they were on older ICE vehicles?
It always seems to happen that way, doesn't it? Nothing is more annoying.
grinder and paint will fix itP.S.Mangelsdorf wrote: ↑Sat Mar 01, 2025 5:33 pm It always seems to happen that way, doesn't it? Nothing is more annoying.