Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BufferedSerial Servo2 PCT2075 I2CEeprom FastPWM
Diff: Alternator.h
- Revision:
- 2:8e7b51353f32
- Parent:
- 1:450090bdb6f4
- Child:
- 3:43cb067ecd00
diff -r 450090bdb6f4 -r 8e7b51353f32 Alternator.h
--- a/Alternator.h Sat Apr 25 15:35:58 2020 +0000
+++ b/Alternator.h Mon Jun 08 13:46:52 2020 +0000
@@ -1,38 +1,34 @@
#include "Servo.h"
#include "BufferedSerial.h"
-#define SPEED_CONTROL_ENABLE // Includes engine revs servo control loop
+//#define SPEED_CONTROL_ENABLE // Includes engine revs servo control loop
-const int TICKOVER_RPM = 2500;
-const int MAX_RPM_LIMIT = 7500;
-const double SERVO_MAX = 0.5;
-const int eeprom_page = 17; // Determines where in eeprom 'settings' reside
+const uint32_t TICKOVER_RPM = 2500;
+const uint32_t PWM_OFF_RPM_LIMIT = (TICKOVER_RPM * 9) / 10;
+const uint32_t MAX_RPM_LIMIT = 7500;
+const double MAX_FIELD_PWM = 0.47;
+const double SERVO_MAX = 0.5;
+const double DRIVER_NEUTRAL = 0.18;
+const uint32_t eeprom_page = 17; // Determines where in eeprom 'settings' reside
-const int lut_seg_size = 60; // steps per thousand RPM
-const int lut_size = lut_seg_size * 8; // 8 segments - 0-1, 1-2, 2-3, 3-4 etc 000 rpm
+//const int lut_seg_size = 60; // steps per thousand RPM
+//const int lut_size = lut_seg_size * 8; // 8 segments - 0-1, 1-2, 2-3, 3-4 etc 000 rpm
class VEXT_Data {
public:
- uint32_t t_on, t_off, measured_pw_us, measured_period, rise_count, fall_count;
+ uint64_t t_on, t_off, measured_pw_us, measured_period, rise_count, fall_count;
double duty_cycle () {
return (double) measured_pw_us / (double) measured_period;
} ;
VEXT_Data () { // constructor
- t_on = t_off = measured_pw_us = measured_period = rise_count = fall_count = 0;
+ t_on = t_off = measured_pw_us = measured_period = rise_count = fall_count = 0L;
} ;
} ;
class eeprom_settings {
char settings [36];
- double max_pwm_lut [lut_size + 4];
-// bool rd_24LC64 (int start_addr, char * dest, int length) ;
-// bool wr_24LC64 (int start_addr, char * dest, int length) ;
-// bool set_24LC64_internal_address (int start_addr) ;
-// bool ack_poll () ;
- void build_lut () ;
public:
eeprom_settings (); // Constructor
- double get_pwm (int) ;
char rd (uint32_t) ; // Read one setup char value from private buffer 'settings'
bool rd (char *, uint32_t) ; // Read one setup char value from private buffer 'settings'
bool wr (char, uint32_t) ; // Write one setup char value to private buffer 'settings'
@@ -50,12 +46,12 @@
const char * t; // description
} ;
-const int MAX_PARAMS = 10;
+const int MAX_PARAMS = 12; // Up from 10 May 2020
struct parameters {
int32_t times[50];
int32_t position_in_list, last_time, numof_dbls;
double dbl[MAX_PARAMS];
} ;
-const int PWM_PERIOD_US = 2400 ;
+const int PWM_PERIOD_US = 1800 ; // Was 2400, May want to reduce this, note would require change of resistor value on board