element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • 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
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs Create a Programmable Instrument with SCPI - Part 5: First Hardware Commands
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 25 Sep 2016 5:32 PM Date Created
  • Views 622 views
  • Likes 1 like
  • Comments 2 comments
  • smart_instrument
  • pwm
  • gpib
  • programmable_instrument
  • labview
  • scpi
  • hercules
  • instrument
Related
Recommended

Create a Programmable Instrument with SCPI - Part 5: First Hardware Commands

Jan Cumps
Jan Cumps
25 Sep 2016
For a hardware evaluation project I'm working on, I want to create a device that can be controlled via LabVIEW.
LabVIEW can talk to instruments using serial out of the box, and it knows how to talk Standard Commands for Programmable Instruments (SCPI).

 

image

 

In this blog I build the first hardware command to turn PWM signals on and off.

 

 

One Function Handles 7 PWM Modules

The first command isn't the easiest one. We'll build a function that can talk to any of 7 available PWM modules of the Hercules controller.

SCPI has a construct that allows you to provide a wildcard in the command. That wildcard can be replaced by a number when calling the command from LabVIEW.

 

    {.pattern = "PWM#:STATe", .callback = SCPI_HerculesPwmState,},

 

When you shoot a command where the # is substituded by a number  (i.e.: PWM1:STATe ON), the SCPI_HerculesPwmState() function gets called.

The substituted number is available in that function by calling the API SCPI_CommandNumbers().

With that number, I retrieve the correct PWM hardware register and switch the signal on or off.

 

image

 

These are the SCPI test calls:

PWM1:STATe ON
PWM1:STATe OFF

 

This is the function that gets called. Don't worry about the magical numbers that are assigned to the PWM register. I'll improve the code while I design the firmware.

param1 holds true if you pass ON or 1 in SCPI command. false if you give OFF or 0.

 

// array of the 7 PWM registers of the Hercules RM46 controller
etpwmBASE_t *pwmRegs[7] ={etpwmREG1, etpwmREG2, etpwmREG3, etpwmREG4, etpwmREG5, etpwmREG6, etpwmREG7} ;

static scpi_result_t SCPI_HerculesPwmState(scpi_t * context) {

    int32_t numbers[1];
    scpi_bool_t param1;
    etpwmBASE_t *pwmReg = NULL;

    // retrieve the PWM channel. Can be 1 - 7
    SCPI_CommandNumbers(context, numbers, 1, 1);

    // todo error if the PWM CHANNEL not between 0 and 7.
    // code below will fail because we'll read invalid memory locations
    pwmReg = pwmRegs[numbers[0]-1];

     /* read first parameter if present */
     if (!SCPI_ParamBool(context, &param1, TRUE)) {
         return SCPI_RES_ERR;
     }
     if (param1) { // switch PWM on
         pwmReg -> TBCTL = ETPWM1_TBCTL_CONFIGVALUE;
     } else { // switch PWM off
         pwmReg -> TBCTL = 131;
     }

    return SCPI_RES_OK;
}

 

That substitution is a powerful construct. With little effort I can control multiple similar modules.

The SCPI library has all the logic that's needed to support this. I just have to use it properly.

Once more it didn't take a lot of code to build flexible functionality.

 

I've attached the CCS project to this blog.

Compile, load to your RM46 LaunchPad and connect with a serial terminal program using 9600, 8, 2, N

 

Put an oscilloscope probe on J11 16 and 18. You'll find two complementary 1MHz PWM signals.

Submit these commands in putty to switch them off and back on:

 

 

 

PWM1:STATe OFF
PWM1:STATe ON

 

In the next blog I'll attach a LabVIEW example that switches the signals.

 

Related Blog

Create a Programmable Instrument with SCPI - Part 1: Parser Library
Create a Programmable Instrument with SCPI - Part 2: Serial over USB
Create a Programmable Instrument with SCPI - Part 3: First Conversation *IDN?
Create a Programmable Instrument with SCPI - Part 4: Error Handling by Default
Create a Programmable Instrument with SCPI - Part 5: First Hardware Commands
Create a Programmable Instrument with SCPI - Part 6: LabVIEW Integration
Create a Programmable Instrument with SCPI - Part 7: Talk to Hardware Registers
Attachments:
RM46_SCPI_FREERTOS_PWM.zip
  • Sign in to reply

Top Comments

  • DAB
    DAB over 6 years ago +1
    Another great update Jan. DAB
  • Jan Cumps
    Jan Cumps over 6 years ago

    Two updates:

    I've attached the CCS firmware project to this blog, and

    I have my first LabVIEW custom program working that switches the PWM of the LaunchPad on and off.

     

     

    LabVIEW and Hercules

    image

    LabVIEW On: Send PWM State ON command to Hercules LaunchPad

    image

    LabVIEW Off: Send PWM State OFF command to Hercules LaunchPad

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 6 years ago

    Another great update Jan.

     

    DAB

    • Cancel
    • Vote Up +1 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 © 2023 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube