gaje Happy making


MCP2515 beyond 1MHz

Filed under: analog3,CAN,tech notes — Gan @ 9:50 PM

For archival purpose:

you are certainly right about 1Mbps being the maximum speed of the official CAN spec. However, some of us like to break the rules :)

I do :)
I’m using CAN for a purpose different from controlling automobile so my breaking rule would not cause any death.


Use USB-UART Bridge on PSoC CY8CKIT-049-42xx Kit

Filed under: analog3,PSoC,tech notes — Gan @ 11:26 PM

You need miniprog3 to program this, despite typical programming to this kit is via boot loader.

1. Put a SCB UART component. Change baud rate to 9600.

2. Assign pins as follows:

UART RX : P4[0]
UART TX : P4[1]


3. And then, here is the main.c source code

int main()
    CyGlobalIntEnable; /* Enable global interrupts. */

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    UART_1_UartPutString("Hello world from CY8CKIT-049-42xx\r\n");

        /* Place your application code here. */

4. Build it, program it, and connect the CY8CKIT-049-42xx to the PC.

That’s it.


Generating MCP2515 SPI ‘READ’ Operation Request Using PSoC 42xx

Filed under: analog3,tech notes — Gan @ 7:21 AM

PSoC 42xx provides SPI component that supports up to 4MHz clock speed. Communicating with MCP2515 via this component, however, is not straightforward when you try the highest clock speed.

The problem is concept of ‘operation’ of MCP2515. An operation consists of multiple SPI bytes bundled by ‘enable’ signal on the CS pin. Lowering the CS pin initiates an operation and it must stay low during the data transmission. See following timing chart quoted from the MCP2515 datasheet.


The PSoC SPI component lacks direct control on the CS pin signal. The component automatically lowers the CS level when the write API puts a byte to Tx FIFO and the component’s internal logic raises the CS level when all FIFO values are consumed. But auto-generated API functions are not fast enough due to overhead to make the functions generic. Then, the CS signal may split during an operation when Tx FIFO becomes empty due to the API failing to catch up with the desired speed.

I wrote a function that generates a valid READ operation frame and retrieves returned bytes. The strategy is:

  • Use lower-level component interfaces to avoid overhead.
  • The function pushes sending bytes to Tx FIFO as fast as possible to keep it non-empty during the operation.
  • Concurrently read data from Rx FIFO as fast as possible to avoid FIFO overflow.

There are limitations to use this functions:

  • Both Rx and Tx buffer sizes of the SPI component must be 4. PSoC Creator generates software buffer when the sizes are larger than 4. That makes source code management too complicated.
  • The first two bytes in output array are dummy that do not mean anything. Actual retrieve data starts from the third element.
  • The function may need to disable interrupts during the operation, though it is still missing in the implementation.

Here is the source code. In this example code, the SPI component name is ‘SPIM_CAN’ which is a master SPI component (non SCB).

#define CAN_CTL_READ 0x03

void mcp2515_read(uint8_t address, uint8_t data[], uint8_t length)
    /* initialization */
    uint8_t to_write = length;
    length += 2;

    /* flush rx buffer */
    while (SPIM_CAN_GetRxBufferSize())

    /* wait until Tx FIFO becomes empty */    

    CY_SET_REG8(SPIM_CAN_TXDATA_PTR, CAN_CTL_READ); // push instruction
    CY_SET_REG8(SPIM_CAN_TXDATA_PTR, address);      // push address

    // loop until all bytes are retrieved
    while (length > 0) {
        // transmit 0 to receive a byte
        if (to_write > 0 && (SPIM_CAN_TX_STATUS_REG & SPIM_CAN_STS_TX_FIFO_NOT_FULL)) {
            CY_SET_REG8(SPIM_CAN_TXDATA_PTR, 0);
        // retrieve a byte if there is any in Rx FIFO
            *data++ = CY_GET_REG8(SPIM_CAN_RXDATA_PTR);

Tried reading 16 bytes from MCP2515 using this read function from a 4MHz-clock SPI of a PSoC Pionner Kit. The CS (Enable) signal stays low during the operation, as expected.




Module Descriptor and Compiled Parameter Table

Filed under: analog3 — Gan @ 10:18 PM

I tried Google Protocol Buffers to describe and transfer modules’ schema before. This approach, however, did not work well because it required large amount of resources both in program and in RAM spaces of a PSoC processor. It limited available resources for module functionality. I finally gave up the approach.

I am trying another approach to describe a module using JSON and to compile it into a parameter table implemented using C macros. The module program does not have to include the schema. Sharing the JSON schema file by Analog 3 modules is good enough. It is nice if the module has the schema internally though. Google Protocol Buffer may help compressing the data in the case.

Here is an example of schema and generated table for MIDI Gateway module:

    "name": "midigw",
    "type": "Module",
    "member": [
            "name": "MIDI channel",
            "type": "NumberSelector",
            "min": 1,
            "max": 16
            "name": "Voices",
            "type": "Selector",
            "choices": ["mono", "duo", "poly 4", "poly 5", "poly 6", "poly 8", "poly 10", "poly 16"]
            "name": "Retrigger",
            "type": "Switch",
            "default": True

#define P_L_VOICES_OFFSET        1
#define P_B_RETRIGGER_OFFSET     2
#define P_BUFFER_SIZE            3

static uint8_t p_buffer[P_BUFFER_SIZE];

#define P_N1_MIDI_CHANNEL (*(uint8_t*)&p_buffer[P_N1_MIDI_CHANNEL_OFFSET])

#define P_L_VOICES       (*(uint8_t*)&p_buffer[P_L_VOICES_OFFSET])
#define P_L_VOICES__MONO     0
#define P_L_VOICES__DUO      1
#define P_L_VOICES__POLY_4   2
#define P_L_VOICES__POLY_5   2
#define P_L_VOICES__POLY_6   2
#define P_L_VOICES__POLY_8   2
#define P_L_VOICES__POLY_10  2
#define P_L_VOICES__POLY_16  2

#define P_B_RETRIGGER (*(uint8_t*)&p_buffer[P_B_RETRIGGER_OFFSET])


How to swap control-m and control-j in Emacs

Filed under: uncategorized — Gan @ 8:09 AM

Emacs often changes the behavior suddenly and drastically. Recent surprise to me was that role of ctrl-j (newline and indent) and ctrl-m (newline) switched out of the blue. I don’t understand the developer’s sense of changing user interface of a multi-decade years old software. But luckily, emacs has very powerful customization ability.

Adding this line reverts the key bindings back.
(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))

I appreciate this post


USB Serial Communication with PSoC Pioneer Kit

Filed under: analog3 — Gan @ 9:07 PM

Exchanging data with PSoC Pioneer Kit over serial communication is often useful. The kit CY8CKIT-042 has a built in USB-to-UART utility programmed in the PSoC 6LP device which is used for onboard debugger for the target PSoC 4. It is easy to use. See below.

Installed Necessary Applications

Filed under: analog3 — Gan @ 3:26 PM

I like OS X as a software development platform (and electronic stationery); On the other hand, it’s much better to use Windows for hardware development because of better coverage of development tools. As a compromise, I own MacBook and runs Windows under Parallels Desktop for hardware development. I have no issues with this style so far thanks to the powerful USB support by Parallels.

My Windows platform has reached disk size full at 64GB. I decided to extend the disk size and re-install everything. Here are highlights of my Windows platform:

  • Windows 10, display language = English
  • PSoC creator 3.2 for the PSoC development platform. 3.3 is installed by I am not using it yet since I saw some instability. (install image =PSoCCreatorSetup_3.2_sp1_b6175.exe)
  • Salae Logic 1.2.10 (Logic Setup 1.2.10.exe) for logic analyzer. No particular issue. Working fine with a normal installation.
  • PicoScope6.11.12 (PicoScope6_r6_11_12) for my oscilloscope PicoScope 2203. The hardware has become EOL already but it is working with this version of Oscilloscope app. Note that OS X version requires installing .NET libraries. I hate it so didn’t install on Mac.
  • Foxit Reader 7.2.8 (FoxitReader728.1124_enu_Setup.exe) for PDF reader. The version is important. Never upgrade this until FoxIt resumes support of classic toolbar mode. The latest version supports only ribbon mode and it painfully takes space on my small screen. Otherwise, this viewer is very comfortable to use. Note: Turn off the automatic upgrade functionality.
  • TeraTerm 4.91 (teraterm-4.91.exe) for terminal emulator. TeraTerm has several variations/providers for some reason. I always get confused by it. This is the one I use, for my future reference:
  • Eagle 5.12.0 It’s very old version but I keep using it because this is the version where I have commercial license (which was quite expensive). Cadsoft who were former provider of Eagle was acquired by some other company, so I’m not sure if the latest version is “better” or “improved”. I want to avoid spending extra time for researching it, so I will stay with this version as long as possible. I’m happy with the feature at this point anyway.

That is about it. I have not installed Cygwin yet. I’m waiting for Ubuntu/bash is officially supported by Windows 10.

I have archived these install images in my ‘software’ folder for any needs for recovery in future.


MIDI Receiver Module

Filed under: analog3 — Gan @ 10:17 PM



My PSoC Creator application became unstable suddenly. I could not work on software today. I’m now recovering the software.

Meanwhile, I made a MIDI receiver module instead. Developing and debugging MIDI Rx would be easier and less troublesome hopefully.

Not yet verified the behavior.


Analog2.0 is restored, started making Volume Control Module

Filed under: analog3 — Gan @ 9:44 PM


I restored the Analog2.0 set successfully. It’s working fine now.


The Volume Control Module substitutes existing VCA and envelope generator. EG part will generate linear volume control voltage for analog VCA. I will reuse VCA in Analog2.0 for analog part.


Analog3: The First Use Case

Filed under: analog3 — Gan @ 10:32 PM


One year has passed since I stopped working on Analog 3. Now it’s time to resume the development. The picture above is the first use case of Analog 3. This is a draft panel layout of the synth I want to make. The panel includes least set of parameters I want.

Many parameters on this panel has non-traditional style, like ones in VCA. I will need to revise and adjust such parameters. In order to avoid remaking hardware modules, I will control the risk by following approach:

  • Develop the synth by modifying a working complete set of synthesizer, i.e., the base platform. I will use the Analog2.0 fundamental set for it.
  • Modification is done by replacing a module.
  • New modules have analog panel.
  • Base platform keep using the existing hardware panel.

I can always verify the complete set is working by this approach.

The first task, then, is to build an Analog2.0 box.

Older Posts »

Powered by WordPress