2022年3月2日 星期三

SigmaDsp Agents - Object Hierarchy


A top-level view of object hierarchy

Items in yellow color below are the main object classes in my package.
  • Dsp hardware-related:
    • ADAU1401: represents the hardware chip. We operate hardware functions through this object. 
    • Messages: data in EEPROM is organized in "Message" format, which can be operated through this object.
  • SigmaStudio related:
    • IC: there will be a *.xml file when you export your SigmaStudio project, which contains the following data, we can operate with the "IC" object.
      • parameter RAM data 
      • program RAM data
      • control registers data
    • Cell: represents SigmaStudio cells, like SineTone, VolumeControl, Filters..., we can operate DSP functions in real-time through the "Cell" object.
  • Factory: this object gets whatever you need for you. Start here. 

Top-level view of object hierarchy



Object hierarchy of ADAU1401

class ADAU1401 actually contains several sub-classes, most importantly are Control, RAM, and EEPROM. 
Object hierarchy of ADAU1401



class ADAU1401

Object ADAU1401 holds a copy of registers data in memory and synchronizes with hardware registers when needed. 

Important methods:
  • enable/toggle/mute: enable/disable output.
  • start/stop/close/pause/resume: actually equvilant with enable/disable/mute.
  • read/write_accress_bytes: I2C read/write data from and to any address of ADAU1401 address space. 
  • read/write_parameter: "Parameter" is a data wrapper object. These two functions operate Parameter and call "read/write_accress_bytes" functions to access hardware. 
  • load_registers: load registers configuration data from a list to PC's memory.
  • registers_values: current registers values held in PC's memory.
  • write_all_registers/update: write registers value from PC's memory to hardware.
  • read_all_registers: read registers value from hardware to PC's memory.
  • print: print a report of all registers' values.

Important methods of class ADAU1401



class Control

Important methods:
  • "Message" related:
    • messages_from_bytes: parse data bytes into a collection of "Message" objects. 
    • write_message: write a "Message" to hardware.
  • XML related:
    • write_xml_ic: read SigmaStudio project XML file and re-write the whole configuration (program, parameters).
  • Text file related:
    • load_SigmStudio_files: load SigmaStudio files and re-write the whole configuration (program, parameters).
  • EEPROM related:
    • load_eeprom_from_file: load data of EEPROM from a binary file.
    • dump_eeprom_to_file: dump data of EEPROM to a binary file.
    • reload_from_eeprom: re-write the whole configuration (program, parameters, control registers), equivalent to software reset.
Important methods of class Control




Important methods:    

    "RAM" is the base class, which has:
  • read/write: read/write data from and to any address of ADAU1401's memory space. 
  • to_file/from_file: dump to and load from binary files.
    Program RAM (inherit RAM):
  • read/write: inherit RAM's function.
   Parameter RAM (inherit RAM):
  • read/write_parameter: actually delegate to ADAU1401's functions.
  • safe_load: safe load a single 4 bytes parameter.
  • safe_loads: safe load up to five parameters at once.
  • read/write: inherit RAM's function.
   EEROM (inherit RAM):
  • messages: pack the data of EEPROM into "Messages".
  • read/write: inherit RAM's function.
Important methods of class RAM and EEPROM




"Messages" is just a collection of many "Message".

Important methods:  
  • from_bytes: parse data bytes into a "Message".
  • messages_from_bytes:
  • messages_from_SigmStudio_files: load SigmaStudio text data files into "Messages".
Important methods of class Message and Messages




The project's XML file you export from SigmaStudio contains descriptions of :
  • IC: hardware's part number...
  • Module: corresponds to SigmaStudio's Cell (like SineTone...), contains one or many Algorithms.
  • Algorithm: descript which algorithm should be used.
  • Parameter: contains parameters' value/type/address. parameters are stored in hardware's parameter RAM space and are used to manipulate DSP hardware's behavior.

Top view of  XML-related object hierarchy

Important methods and properties:  
  • df: a Pandas DataFrame report of parameters configuration. You need Pandas installed to show the report.
  • Parameter:
    • set_value: set a value, if the parameter is a 4 bytes parameter.
    • set_numbers: set a list of values at once. if the parameter contains n values, in turn, has 4 x n bytes.
    • numbers: get a list of values from a parameter, which contains n values, in turn, has 4 x n bytes.
    • to_integer: force into integer.
    • to_float: force into float.

Important methods of XML-related classes



SigmaStudio Toolbox Cell related classes

Important methods and properties:  
  • df: a Pandas DataFrame report of parameters configuration. You need Pandas installed to show the report.:
  • get_param/set_param: read/write and synchronize a parameter's data with hardware.
  • get_parameters_values/set_parameters_values: synchronize many parameters' data at once.
  • read_parameter/write_parameter: read/write a "Parameter" object data from/to hardware (delegated to ADAU1401 object).
  • show_methods: show a report of a Cell's methods signature.
Important methods of Cell-related classes


class Factory

Important methods and properties:  
  • get_ic: read and wrap project XML file into an "IC" object.
  • get_cells: get all the "Cell" objects of a SigmaStudio project. A "Cell" has methods (like set_frequency...) with which we can control Dsp behavior.
  • get_cell_by_name: get a "Cell" object by name.
  • get_cells_manifest: generate a script for embodying Cell objects 
  • show_methods: show a report of every Cell's methods signature in a SigmaStudio project.
  • save_parameters_to_eeprom: save current parameters' value to EEPROM.
Important methods of class Factory




2020年6月22日 星期一

FM Transceivers (en)




Why this

  With these strategies, it is now much easier to develop device drivers. Therefore, I wrote Python drivers for several FM transceiver modules (Si4713RDA5820NKT0803L).  Repository is here.


Transceiver modules 
 Si4713 
  • A transmitter which can also measure noise(signal) level of a particular frequency.
  • Can send RDS message.
  • Popular, resource (documents and sample code are well available).
KT0803L
  • Transmitter mode only.
  • Noisy.
  • Cheap and well available.
RDA5820N
  • Can switch between transmitter / receiver / audio-amplifier / ADC modes.
  • Can send RDS message.
  • PLL locks very slowly.
  • Rare, documents and resources are rare.
  • Website is not reachable.

How to use
  • Usage and test methods are here and here
  • USB-I2C converter is required if you want to control transceivers with PC, options are:
  • There are xxxxx_proxy.py modules with smaller size to be used on ESP32.

Test Results
Si4713
Basic functional test
with FX2LP USB-I2C converter and Jupyter notebook

Basic functional test
with ESP32 and MicroPython Remote Kernel + Jupyter notebook

RDS transmission test 


RDA5820N
Basic functional test

KT0803L
to be added

Dependencies:

FM Transceivers


緣由
  採用 這套策略 之後,開發 device driver 變得容易且快速多了,於是為手上的幾個 FM transceiver 模組 (Si4713, RDA5820N, KT0803L) 也寫了 Python drivers,放在 這裡

模組特性
 Si4713 
  • 主要是 transmitter 的功能。
  • 也可以 量測指定頻率的訊號強度。
  • 可以發送 RDS 訊息。
  • 市面上較常見,開發資源較多。
KT0803L
  • 只有 transmitter 的功能。
  • Noise floor 會整個被抬高,很吵。
  • 市面上常見,較便宜。
RDA5820N
  • 具有 transmitter / receiver / audio-amplifier / ADC 的功能,可以任選一種模式切換。
  • 可以發送 RDS 訊息。
  • 切換頻率的時候 PLL lock 的速度很慢。
  • 使面上較少見,開發資源較少。
  • 官網 連不上。
使用方式
  • 所有的 測試與使用方式 ,都記錄在 這裡 和 這裡
  • 需搭配 USB-I2C converter,例子:
  • 如果要上傳到 ESP32 上面使用,可以用體積較小的 xxxxx_proxy.py 。

測試結果
Si4713
Basic functional test
with FX2LP USB-I2C converter and Jupyter notebook

Basic functional test
with ESP32 and MicroPython Remote Kernel + Jupyter notebook

RDS transmission test 


RDA5820N
Basic functional test

KT0803L
to be added

Dependencies:

Si5351 Clock Generator (en)




Why This
  As stated in previous article ,I wrote python drivers for several popular signal generator modules.
 Soon the Si5351 module I ordered arrived. It has unique characteristic. I put the driver for Si5351 in this repository.
  Si5351 has  3 ~ 8 clock outputs with frequency ranging from  2.5KHz to 225MHz. Spread Spectrum mode is supported. Phase offset between clock outputs can be set. Si5351 functions as quadrature clock source if the phase offset is 90 degree.
  It's difficult to develop a complete device driver for Si5351 because it has 108 registers. Fortunately, with USB-I2C converter we can test Si5351 directly with PC without uploading code to a MCU repeatedly, saving us lots of time and patience. Additionally, being able to set breakpoints and use the debug mode provided by PyCharm to trace code also speeds up the development.
Design and Features
 
    • Python package used to communicate with FX2LP is here.
  • Showing current configuration :

  • Registers value comparision:
    • We can compare two sets of register values, showing all register fields or just the mis-matched ones. This is very useful during device driver development.
  • Find integer divider solution for PLL,  in order to generate specific clock frequencies:

Test Results
Functional tests:
Frequency Dancing (Sweeping)
Control Si5351 with PC + FT232H (USB-I2C converter)  

Control Si5351 with PC + FX2LP (USB-I2C converter) 

  • Also, we can upload the driver to an ESP32 and control Si5351 from there.
Control Si5351 with ESP32+MicroPython
  • We can control an ESP32 with MicroPython Remote Kernel, via a Jupyter notebook
Control Si5351 with ESP32+MicroPython Remote Kernel
  • Spread Spectrum test:
  • Quadrature Clock test:
    • can goes as low as 1.3MHz (with a little bit messing around, out of spec.)

Dependencies: