Code for 'Smart Regulator' featured in 'Model Engineer', November 2020 on. Contains all work to August 2020 including all code described. Top level algorithm development is quite spares, leaving some work for you! Any questions - jon@jons-workshop.com

Dependencies:   mbed BufferedSerial Servo2 PCT2075 I2CEeprom FastPWM

Committer:
JonFreeman
Date:
Sat Dec 05 12:40:17 2020 +0000
Revision:
5:6ca3e7ffc553
Parent:
3:43cb067ecd00
Code for 'Smart Regulator' to August 2020, published as is. Basic low-level functions all thoroughly tested and debugged, top level algorithms have scope for further development - over to you! For help contact jon @ jons-workshop[.com

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JonFreeman 3:43cb067ecd00 1 #include "mbed.h"
JonFreeman 3:43cb067ecd00 2 /**
JonFreeman 3:43cb067ecd00 3 Functions to control alternator field
JonFreeman 3:43cb067ecd00 4 */
JonFreeman 3:43cb067ecd00 5
JonFreeman 3:43cb067ecd00 6
JonFreeman 3:43cb067ecd00 7 /**void set_pwm (double d) { Range 0.0 to 1.0
JonFreeman 3:43cb067ecd00 8 This PWM used to limit max duty ratio of alternator field energisation.
JonFreeman 3:43cb067ecd00 9 With R25=33k and C4=100n controlling ramp input to CS pin of MCP1630 (not MCP1630V),
JonFreeman 3:43cb067ecd00 10 ramp terminates fet 'on' pulse after a max of approx 980 us.
JonFreeman 3:43cb067ecd00 11 With const int PWM_PERIOD_US = 2000 , duty ratio is thus limited to approx 50% max.
JonFreeman 3:43cb067ecd00 12 This is about right when using 12V alternator on 24V systems
JonFreeman 3:43cb067ecd00 13 A 1.225V reference (U7) is fed to the MCP1630 error amp which compares this to fed-back proportion of system voltage.
JonFreeman 3:43cb067ecd00 14 This adjusts final PWM down to zero % as needed to maintain alternator output voltage.
JonFreeman 3:43cb067ecd00 15 */
JonFreeman 3:43cb067ecd00 16
JonFreeman 3:43cb067ecd00 17 class FieldControl {
JonFreeman 3:43cb067ecd00 18 uint8_t privatemadetab[440];
JonFreeman 3:43cb067ecd00 19 uint64_t t_on, t_off, measured_pw_us, measured_period, rise_count, fall_count;
JonFreeman 3:43cb067ecd00 20 uint32_t old_percent;
JonFreeman 3:43cb067ecd00 21 PwmOut pwm_osc_in; // Controller PWM driving MCP1630
JonFreeman 3:43cb067ecd00 22 InterruptIn V_ext; // Connected to MCP1630 output to MOSFET
JonFreeman 3:43cb067ecd00 23 void VextRise (); // Handles - MCP1630 has just turned mosfet on
JonFreeman 3:43cb067ecd00 24 void VextFall (); // Handles - MCP1630 has just turned mosfet off
JonFreeman 3:43cb067ecd00 25 public:
JonFreeman 3:43cb067ecd00 26 FieldControl (PinName pwmoscin, PinName vext) ; // Constructor
JonFreeman 3:43cb067ecd00 27 void set_pwm (double); // What it says, 0.0 to 1.0 but inverts to suit MCP1630
JonFreeman 3:43cb067ecd00 28 void maketable ();
JonFreeman 3:43cb067ecd00 29 uint32_t set_for_speed (uint32_t rpm);
JonFreeman 3:43cb067ecd00 30 double get_duty_ratio () ;
JonFreeman 3:43cb067ecd00 31 } ;
JonFreeman 3:43cb067ecd00 32