Skip to content

Conversation

@javerik
Copy link

@javerik javerik commented Jan 22, 2025

Just to keep the development in sync with main repository.

Library is still under development.

Current state

  • Complete read of all SPI register
  • Write of register with selection of inner values
  • C++ Wrapper
  • Documentation
  • Propper Arduino style library

@javerik
Copy link
Author

javerik commented Jan 22, 2025

Readout of TUSS register unchanged

TUSS4470 Configuration:
Register 0x10: 0x0
Register 0x11: 0x0
Register 0x12: 0xD
Register 0x13: 0x0
Register 0x14: 0x0
Register 0x16: 0x20
Register 0x17: 0x7
Register 0x18: 0x14
Register 0x1A: 0x0
Register 0x1B: 0x0
Register 0x1C: 0x0
Register 0x1D: 0xB9
Register 0x1E: 0x2

@Neumi Could be a save of the register set be helpful, such in eeprom ? And then a load and write of specific sets ?

@Neumi
Copy link
Owner

Neumi commented Jan 23, 2025

@javerik I'd say no.
I'd think we should keep it as platform independent as possible. Let's keep SPI and EEPROM out if possible. If we can use the external libraries like SPI (or EEPROM) only in the examples, that would be awesome, and would make the lib more usable for other platforms (like STM32 or ESP32).
If we could get a understandable and useable implementation for the settings registers using methods rather than just addresses and HEX values with human readable names, that would be the best imo. (if that answers the question :D)
I'd also like to avoid EEPROM, due to the very limited read and write cycles on atmega328. For examples, we should not need a permanent storage on the MCU if possible.

i have something like this in mind:

void setup() {
  tuss4470.begin(5,6,8,9,10,11,12,13);  // IO_1, IO_2, OUT_1, OUT_2, CS, MISO, MOSI, CLK
  tuss4470.setBPFcenterFrequency(0x1D);
  tuss4470.setLNAgain(0x02); 
  tuss4470.setPulses(8);
  tuss4470.setExternalVDRV(1);
  ...
  ...
  ...
  tuss4470.writeSettings();
}

void loop() {
  tuss4470.startTOFmeasurement();
  for (int i = 0; i < numSamples; i++) {
      while (!(ADCSRA & (1 << ADIF)));
      ADCSRA |= (1 << ADIF);
      analogValues[i] = ADC;
    }
  tuss4470.stopTOFmeasurement();

}

Pulse generation and echo sampling should stay external from the library to be more platform independence. Having a small set of code examples should be enough. The library should only do the settings management IMO.

…er. Added a beginCustomSPI to set a custom spi callback when other SPI settings are used or different platform
@javerik
Copy link
Author

javerik commented Jan 26, 2025

Wrapper for all register and there subfunctions are now as own cpp functions.

       // region specific register access
        int setBPF_HPFFreq(uint8_t freq);
        int setBPF_Bypass(bool value);
        int setBPF_FCTrimFrc(bool value);

        int setBPF_QSel(uint8_t qSel);
        int setBPF_FCTrim(uint8_t fcTrim);

        int setDEV_LogAmpFrc(bool value);
        int setDEV_LogAmpSlopeAdj(uint8_t value);
        int setDEV_LogAmpIntAdj(uint8_t value);

        int setLogAmpDisableFirstStage(bool value);
        int setLogAmpDisableLastStage(bool value);
        int setVOUTScaling(bool value);
        int setLNAGain(uint8_t gain);


        int setDriverPulseFaultDeglitchTime(uint8_t time);
        int setLowVoltageIOConfig(uint8_t config);


        int setDisableVDRVRegulationInListenMode(bool value);
        int setVDRVHighImpedance(bool value);
        int setVDRVCurrentLevel(bool value);
        int setVDRVVoltageLevel(uint8_t level);


        int setEchoInterruptComparatorEnable(bool value);
        int setEchoInterruptThreshold(uint8_t threshold);

        int setZeroCrossComparatorEnable(bool value);
        int setZeroCrossEnableEchoInterrupt(bool value);
        int setZeroComparatorInputSelect(bool value);
        int setZeroCrossComparatorStageSelect(uint8_t stage);
        int setZeroCrossComparatorHysteresis(uint8_t hysteresis);

        int setHalfBridgeMode(bool value);
        int setPreDriverMode(bool value);
        int setBurstPulseNumber(uint8_t pulseCount);

        int setSleepModeEnable(bool value);
        int setStandbyModeEnable(bool value);
        int setVDRVTriggerControl(bool value);
        int setCommandTriggerControl(bool value);

        // endregion

Furthermore there is now a function to pass a custom SPI callback into the wrapper, when other platforms than Arduino is used. The standard begin() function uses the default SPI from SPI.h

    SPI.begin();
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV16);
    SPI.setDataMode(SPI_MODE1);  // CPOL=0, CPHA=1
    // Configure GPIOs
    pinMode(_default_cs, OUTPUT);

@yangguowei-jpg
Copy link

Can a 40kHz square wave signal input from PIN9 drive the TUSS4470?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants