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:
4:28cc0cf01570
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 5:6ca3e7ffc553 1 /*******************************************************************************
JonFreeman 5:6ca3e7ffc553 2 DON'T FORGET TO REMOVE SOLDER LINKS SB16 AND SB18 ON L432KC BOARD
JonFreeman 5:6ca3e7ffc553 3 *******************************************************************************/
JonFreeman 1:450090bdb6f4 4
JonFreeman 5:6ca3e7ffc553 5 //#define GPS_ // Not the crap one I tried!
JonFreeman 1:450090bdb6f4 6
JonFreeman 3:43cb067ecd00 7 const double ALTERNATOR_DESIGN_VOLTAGE = 14.0; // Used to scale down max field pwm when available voltage higher than this
JonFreeman 3:43cb067ecd00 8 const double DRIVER_NEUTRAL = 0.18; // Proportion of driver's pot travel deemed to be zero power request
JonFreeman 3:43cb067ecd00 9 const uint32_t eeprom_page = 17; // Determines where in eeprom 'settings' reside
JonFreeman 3:43cb067ecd00 10 const int eeprom_page_size = 32;
JonFreeman 3:43cb067ecd00 11 const int PWM_PERIOD_US = 1800 ; // Was 2400, May want to reduce this, note would require change of resistor value on board
JonFreeman 0:77803b3ee157 12
JonFreeman 3:43cb067ecd00 13 enum {TABL0, TABL1, TABL2, TABL3, TABL4, TABL5, TABL6, TABL7, TABL8, TABL9, TABL10,
JonFreeman 3:43cb067ecd00 14 TABL11, TABL12, TABL13, TABL14, TABL15, TABL16, TABL17, TABL18, TABL19, TABL20,
JonFreeman 3:43cb067ecd00 15 WARM_UP_DELAY, WARMUP_SERVO_POS, OP_MODE, SPEED_CTRL_P, SERVO_DIR, FUT27, FUT28, FUT29, FUT30, FUT31 } ;
JonFreeman 0:77803b3ee157 16
JonFreeman 3:43cb067ecd00 17 struct sldandt {
JonFreeman 3:43cb067ecd00 18 const uint32_t min, max, de_fault; // min, max, default
JonFreeman 3:43cb067ecd00 19 const char * txt; // description
JonFreeman 3:43cb067ecd00 20 char val;
JonFreeman 1:450090bdb6f4 21 } ;
JonFreeman 1:450090bdb6f4 22
JonFreeman 3:43cb067ecd00 23
JonFreeman 3:43cb067ecd00 24 class ee_settings_2020 {
JonFreeman 3:43cb067ecd00 25 char new_settings[eeprom_page_size + 2];
JonFreeman 0:77803b3ee157 26 public:
JonFreeman 3:43cb067ecd00 27 ee_settings_2020 () ; // Constructor
JonFreeman 3:43cb067ecd00 28 int load () ;
JonFreeman 3:43cb067ecd00 29 int save () ;
JonFreeman 3:43cb067ecd00 30 char rd (uint32_t i) ;
JonFreeman 3:43cb067ecd00 31 bool wr (char c, uint32_t i) ; // Write one setup char value to private buffer 'settings'
JonFreeman 3:43cb067ecd00 32 sldandt * inform (uint32_t which) ;
JonFreeman 0:77803b3ee157 33 } ;
JonFreeman 0:77803b3ee157 34
JonFreeman 2:8e7b51353f32 35 const int MAX_PARAMS = 12; // Up from 10 May 2020
JonFreeman 3:43cb067ecd00 36 struct parameters { // Used in Command Line Interpreter, stores user input values
JonFreeman 3:43cb067ecd00 37 int32_t position_in_list, numof_dbls;
JonFreeman 1:450090bdb6f4 38 double dbl[MAX_PARAMS];
JonFreeman 1:450090bdb6f4 39 } ;
JonFreeman 0:77803b3ee157 40
JonFreeman 1:450090bdb6f4 41
JonFreeman 3:43cb067ecd00 42 /*
JonFreeman 3:43cb067ecd00 43 - Position the Cursor:
JonFreeman 3:43cb067ecd00 44 \033[<L>;<C>H
JonFreeman 3:43cb067ecd00 45 Or
JonFreeman 3:43cb067ecd00 46 \033[<L>;<C>f
JonFreeman 3:43cb067ecd00 47 puts the cursor at line L and column C.
JonFreeman 3:43cb067ecd00 48 - Move the cursor up N lines:
JonFreeman 3:43cb067ecd00 49 \033[<N>A
JonFreeman 3:43cb067ecd00 50 - Move the cursor down N lines:
JonFreeman 3:43cb067ecd00 51 \033[<N>B
JonFreeman 3:43cb067ecd00 52 - Move the cursor forward N columns:
JonFreeman 3:43cb067ecd00 53 \033[<N>C
JonFreeman 3:43cb067ecd00 54 - Move the cursor backward N columns:
JonFreeman 3:43cb067ecd00 55 \033[<N>D
JonFreeman 3:43cb067ecd00 56
JonFreeman 3:43cb067ecd00 57 - Clear the screen, move to (0,0):
JonFreeman 3:43cb067ecd00 58 \033[2J
JonFreeman 3:43cb067ecd00 59 - Erase to end of line:
JonFreeman 3:43cb067ecd00 60 \033[K
JonFreeman 3:43cb067ecd00 61
JonFreeman 3:43cb067ecd00 62 - Save cursor position:
JonFreeman 3:43cb067ecd00 63 \033[s might not work
JonFreeman 3:43cb067ecd00 64 - Restore cursor position:
JonFreeman 3:43cb067ecd00 65 \033[u might not work
JonFreeman 3:43cb067ecd00 66 */
JonFreeman 3:43cb067ecd00 67