Dual Brushless Motor ESC, 10-62V, up to 50A per motor. Motors ganged or independent, multiple control input methods, cycle-by-cycle current limit, speed mode and torque mode control. Motors tiny to kW. Speed limit and other parameters easily set in firmware. As used in 'The Brushless Brutalist' locomotive - www.jons-workshop.com. See also Model Engineer magazine June-October 2019.
Dependencies: mbed BufferedSerial Servo PCT2075 FastPWM
Update 17th August 2020 Radio control inputs completed
Diff: 24LC64_eeprom.cpp
- Revision:
- 14:acaa1add097b
- Parent:
- 13:ef7a06fa11de
- Child:
- 16:d1e4b9ad3b8b
--- a/24LC64_eeprom.cpp Sun Sep 29 16:34:37 2019 +0000 +++ b/24LC64_eeprom.cpp Sat Nov 30 16:34:58 2019 +0000 @@ -6,8 +6,8 @@ // Code for 24LC64 8k x 8 bit eeprom // Code based on earlier work using memory FM24W256, also at i2c address 0xa0; -const int addr_rd = 0xa1; // set bit 0 for read, clear bit 0 for write -const int addr_wr = 0xa0; // set bit 0 for read, clear bit 0 for write +const int addr_rd = 0xa1; // set bit 0 for read, clear bit 0 for write 24LC64 +const int addr_wr = 0xa0; // set bit 0 for read, clear bit 0 for write 24LC64 const int ACK = 1; struct optpar { @@ -47,6 +47,8 @@ class eeprom_settings { I2C i2c; uint32_t errors; + uint32_t i2c_device_count; + uint32_t i2c_device_list[12]; // max 12 i2c devices char settings [36]; bool rd_24LC64 (int start_addr, char * dest, int length) ; bool wr_24LC64 (int start_addr, char * dest, int length) ; @@ -54,6 +56,7 @@ bool ack_poll () ; public: eeprom_settings (PinName sda, PinName scl); // Constructor + bool do_we_have_i2c (uint32_t x) ; char rd (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' bool save () ; // Write 'settings' buffer to EEPROM @@ -71,31 +74,44 @@ return errors; } +bool eeprom_settings::do_we_have_i2c (uint32_t x) { + for (int i = 0; i < i2c_device_count; i++) { + if (i2c_device_list[i] == x) + return true; + } + return false; +} + // Use : eeprom_settings (SDA_PIN, SCL_PIN); eeprom_settings::eeprom_settings (PinName sda, PinName scl) : i2c(sda, scl) // Constructor { - errors = 0; + errors = i2c_device_count = 0; for (int i = 0; i < 36; i++) settings[i] = 0; + for (int i = 0; i < 12; i++) + i2c_device_list[i] = 0; i2c.frequency(400000); // Speed 400000 max. - int last_found = 0, q; // Note address bits 3-1 to match addr pins on device +// int last_found = 0, q; // Note address bits 3-1 to match addr pins on device + int q; for (int i = 0; i < 255; i += 2) { // Search for devices at all possible i2c addresses i2c.start(); q = i2c.write(i); // may return error code 2 when no start issued switch (q) { case ACK: pc.printf ("I2C device found at 0x%x\r\n", i); - last_found = i; +// last_found = i; + i2c_device_list[i2c_device_count++] = i; case 2: // Device not seen at this address break; default: - pc.printf ("Unknown error %d in check_24LC64\r\n", q); + pc.printf ("Unknown error %d from i2c.write while looking for i2c devices\r\n", q); errors |= 512; break; } } i2c.stop(); - if (errors || last_found != 0xa0) { +// if (errors || last_found != 0xa0) { + if (errors || !do_we_have_i2c(0xa0)) { pc.printf ("Error - EEPROM not seen %d\r\n", errors); errors |= 0xa0; ESC_Error.set (FAULT_EEPROM, errors); // Set FAULT_EEPROM bits if 24LC64 problem