element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test & Tools
  • Technologies
  • More
Test & Tools
Blog PST.. Experimental event / trigger support for Pico SCPI labTool - 2: design the registers
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 17 Sep 2023 5:44 PM Date Created
  • Views 626 views
  • Likes 10 likes
  • Comments 5 comments
  • pico_usbtmc_scpi
  • pico
  • USBTMC
  • Pico SCPI labTool
  • labview
  • scpi
Related
Recommended

PST.. Experimental event / trigger support for Pico SCPI labTool - 2: design the registers

Jan Cumps
Jan Cumps
17 Sep 2023
PST.. Experimental event / trigger support for Pico SCPI labTool - 2: design the registers

The Pico SCPI labTool (PST) allows you to connect your PC to equipment to control and monitor all sorts of things. It runs on a Raspberry Pico. It would be nice if the PST could supports device dependent SCPI registers. They can be used to notify a LabVIEW flow from the device. I'd be happy if we can notify LabVIEW when a GPIO input changed logic level.
In this post: implement instrument dependent registers, and a test of the register trickle process.

image

thank you ggabe and Gough Lui for the help.

part 1: PST.. Experimental event / trigger support for Pico SCPI labTool - 1: investigate 
part 2: PST.. Experimental event / trigger support for Pico SCPI labTool - 2: design the registers 
part 3: PST.. Experimental event / trigger support for Pico SCPI labTool - 3: Instrument Specific Registers Test
part 4: PST.. Experimental event / trigger support for Pico SCPI labTool - 4: let TinyUSB USBTMC code use SCPI-LIB's Status Byte register 
part 5:  PST.. Experimental event / trigger support for Pico SCPI labTool - 5: Propagation to IEEE488.2 SCPI Registers Test 
part 6: PST.. Experimental event / trigger support for Pico SCPI labTool - 6: Service Request from Instrument to LabVIEW flow 
part 7: PST.. Experimental event / trigger support for Pico SCPI labTool - 7: Test Service Request from Instrument to LabVIEW flow 

Implement real Instrument Specific Registers

The first post ended when I had created empty definitions for the registers and related infratructure:

#define USER_REGISTERS
#define USER_REGISTER_GROUPS
#define USER_REGISTER_DETAILS
#define USER_REGISTER_GROUP_DETAILS

Now I'm building the whole configuration to capture device settings and events, and promote them up the hierarchy:

image

scpi_user_config.h

#ifndef _SCPI_USER_CONFIG_H
#define _SCPI_USER_CONFIG_H

// define instrument specific registers
#define USE_CUSTOM_REGISTERS 1

#define USER_REGISTERS \
        USER_REG_DIGINEVENT, /* Digital In event status Register */ \
        USER_REG_DIGINEVENTE, /* Digital In event status enable Register */ \
        USER_REG_DIGINEVENTC, /* Digital In event status condition Register */ \
        USER_REG_DIGINEVENTP, /* Digital In event status positive filter Register */ \
        USER_REG_DIGINEVENTN, /* Digital In event status negative register Register */

#define USER_REGISTER_GROUPS \
        USER_REG_GROUP_DIGINEVENT,

#define USER_REGISTER_DETAILS \
    { SCPI_REG_CLASS_EVEN, USER_REG_GROUP_DIGINEVENT }, \
    { SCPI_REG_CLASS_ENAB, USER_REG_GROUP_DIGINEVENT }, \
    { SCPI_REG_CLASS_COND, USER_REG_GROUP_DIGINEVENT }, \
    { SCPI_REG_CLASS_PTR, USER_REG_GROUP_DIGINEVENT }, \
    { SCPI_REG_CLASS_NTR, USER_REG_GROUP_DIGINEVENT },

#define USER_REGISTER_GROUP_DETAILS \
{ \
        USER_REG_DIGINEVENT, \
        USER_REG_DIGINEVENTE, \
        USER_REG_DIGINEVENTC, \
		USER_REG_DIGINEVENTP, \
		USER_REG_DIGINEVENTN, \
		SCPI_REG_OPER, \
		1  /* TODO this defines to what bit of the parent we trickle through */ \
    }, /* USER_REG_GROUP_DIGINEVENT */

#endif // _SCPI_USER_CONFIG_H

I designed a user condition, event and enable register, with the OPERATION STATUS register as parent.

  • I can change values in the condition register.
  • the value trickles and  latches in the corresponding bit in the event register 
  • the value trickles down to a bit of my choice in the OPERATION STATUS register (also latched)

That means that I can listen to GPIO, and set a condition register bit. Library infra will manage the latching and clearing

I designed 2 additional registers to indicate if I want to listen to positive and/or negative transitions. The latching will only apply if the transition is requested to be monitored.

All is handled by the lib. It seems that I only have to define the user registers, configure the behaviour. And that results in changes in the standard OPERATION STATUS register.
Existing SCPI commands in the lib can take care that these trickle down further to standard OPERATION bit of the STATUS BYTE register

image

link to all posts

  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 1 year ago in reply to Jan Cumps

    to make the migration simple, I created two helper functions:

    uint8_t getSTB() {
        return (uint8_t) SCPI_RegGet(&scpi_context, SCPI_REG_STB);
    }

    void setSTB(uint8_t stb) {
        SCPI_RegSet(&scpi_context, SCPI_REG_STB, (scpi_reg_val_t) stb);
    }
    everywhere where the status byte is used in the tmcusb part, I first get it into a local variable with the helper function,
    then let the tmcusb code adapt the status
    then write it back with the helper function
    example:
    bool tud_usbtmc_msg_trigger_cb(usbtmc_msg_generic_t* msg) {
      (void)msg;
      // Let trigger set the SRQ
      uint8_t status = getSTB();
      status |= IEEE4882_STB_SRQ;
      setSTB(status);
      return true;
    }
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    Now ready for the step that I think is needed, to make the SQR / trigger mechanism work: merge the status byte of the USBTMC code, and the one from the SCPI-LIB

    I kept the one in the tmcusb code from the TinyUSB example. I think that's a mistake, and should have ported the STB of that example over to the STB of the SCPI-LIB.

    To make the work structured, I abuse the compiler: I commented out the status variable in the STB code part. To make the compilation fail. I marked the line with a TODO comment
    Then compiled the code, and also marked each of the compile error lines with a TODO command.

    VSCode (like many IDEs) has a TODO module that lists all the lines with a TODO comment. I can now navigate to these lines easily, and fix them one by one until the compilation succeeds again.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    This functionality is now available in the development branch: https://github.com/jancumps/pico_scpi_usbtmc_labtool/tree/develop-set-4

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    making the usbtmc event service request channel work is still a far dream, but I have progress on dealing with the registers.
    All required SCPI commands are now implemented:

        // instrument specific registers commands
        {.pattern = "STATus:OPERation:DIGItal:INPut:EVENt?", .callback = SCPI_StatusOperationDigitalInputEventQ,},
        {.pattern = "STATus:OPERation:DIGItal:INPut:CONDition?", .callback = SCPI_StatusOperationDigitalInputConditionQ,},
        {.pattern = "STATus:OPERation:DIGItal:INPut:ENABle", .callback = SCPI_StatusOperationDigitalInputEnable,},
        {.pattern = "STATus:OPERation:DIGItal:INPut:ENABle?", .callback = SCPI_StatusOperationDigitalInputEnableQ,},
        {.pattern = "STATus:OPERation:DIGItal:INPut:PTRansition", .callback = SCPI_StatusOperationDigitalInputPTransition,},
        {.pattern = "STATus:OPERation:DIGItal:INPut:PTRansition?", .callback = SCPI_StatusOperationDigitalInputPTransitionQ,},
        {.pattern = "STATus:OPERation:DIGItal:INPut:NTRansition", .callback = SCPI_StatusOperationDigitalInputNTransition,},
        {.pattern = "STATus:OPERation:DIGItal:INPut:NTRansition?", .callback = SCPI_StatusOperationDigitalInputNTransitionQ,},
    

    Test with NI Visa Interactive

    image

    output:

    # button not pressed: input 27 (bit 3) high
    1: Write Operation (STATus:OPERation:DIGItal:INPut:CONDition?\n)
    2: Read Operation
    4\r\n
    
    # button pressed: input 27 (bit 3) low
    3: Write Operation (STATus:OPERation:DIGItal:INPut:CONDition?\n)
    4: Read Operation
    0\r\n
    
    

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 1 year ago

    for git lovers: I'm working on this experimental feature outside of the "scheduled" new features. An experiment has a different pace than "normal" new functionality.
    I created a dedicated branch for the experiment, based on the (at that time) current release. You can see that as the green track on the graph below.

    image

    Meanwhile we were working on the next "normal" release, adding several incremental features. You can see that dev branch (develop-set-3) in the blue trail.
    When that develop branch was cut as a new release (version 3.0), and I merged the dev branch with the main one, my experimental branch was outdated.
    You can see the black arrow on 18th (today), where I synchronised the experimental branch with the main branch, to eat the changes done for this release.
    Now my experimental branch is up-to-date with the release 3.0. While safeguarding my experimental changes.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube