MelexisIO SCPI Commands
Loading...
Searching...
No Matches
PWM SCPI Commands

This document describes the SCPI command interface implemented in commands_pwm.c for PWM (Pulse Width Modulation) and frequency measurement/control on the Melexis IO STM32 platform.

Overview

The commands_pwm.c file provides SCPI-like commands for initializing, deinitializing, reading, and setting PWM and frequency on various pins. It also supports DMA and IRQ-based PWM input, as well as clock configuration for advanced timing features.

Supported Commands

DMA/IRQ/Clock/Deinit

Command Pattern Description
:A0:PWM:DMA:INIT Init A0 for PWM DMA Input
:A0:PWM:DMA? Get A0 PWM DMA Data
:A0:PWM:IRQ:INIT Init A0 for PWM IRQ Input
:A0:PWM:IRQ? Get A0 PWM IRQ Data
:A0:CLK:INIT Clock at A0 Init
:A0:CLK:FREQ Set clock frequency at A0
:A0:DEINIT Deinit A0 pin

PWM/Frequency/Output (A0-A3, SDA, SCL)

Command Pattern Description
:A0:PWM:INIT Init A0 as PWM input
:A0:PWM? Read A0 PWM
:A0:FREQ:INIT Init A0 as Frequency measure
:A0:FREQ? Read A0 Frequency in Hz
:A0:OUT:INIT Init A0 as PWM output
:A0:OUT:SET Set A0 PWM output in Hz
:A0:OUT:SET:FREQ Set A0 Frequency output
:A0:PWM:DEINIT DeInit A0 PWM Out/In
... ... (same for A1, A2, A3, SDA, SCL)

Example for Other Pins

  • Replace A0 with A1, A2, A3, SDA, or SCL for similar commands on those pins.

Connector/Other Pins (Commented/Planned)

  • The file contains commented-out patterns for connector pins (e.g., :CON:SCLK:INIT) and other SPI/UART-related pins, which can be enabled or extended as needed.

Command Details

  • DMA/IRQ/Clock/Deinit: Initialize or read PWM using DMA or IRQ, configure clock, or deinitialize.
  • PWM:INIT/FREQ:INIT/OUT:INIT: Initialize pin for PWM input, frequency measurement, or PWM output.
  • PWM?/FREQ?: Read PWM or frequency value from the pin.
  • OUT:SET/OUT:SET:FREQ: Set PWM output duty or frequency.
  • PWM:DEINIT: Deinitialize PWM on the pin.

Handler Functions

  • CMD_Pwm_Init: Handles initialization and deinitialization for PWM/frequency modes.
  • CMD_Pwm_Read: Reads frequency or PWM values.
  • CMD_Pwm_Set: Sets PWM duty or frequency.
  • CMD_PwmDmaInit, CMD_PwmDmaData: DMA-based PWM input.
  • CMD_PwmIrqInit, CMD_PwmIrqData: IRQ-based PWM input.
  • CMD_Clk, CMD_ClkFreq: Clock configuration.
  • CMD_DeInit: Deinitialization of all PWM/clock/DMA resources.

Example Usage

  • Init A0 as PWM input: :A0:PWM:INIT
  • Read A0 frequency: :A0:FREQ?
  • Set A1 PWM output: :A1:OUT:SET 50 (sets duty cycle)
  • Set SCL frequency output: :SCL:OUT:SET:FREQ 1000 (sets frequency)
  • Init A0 for PWM DMA: :A0:PWM:DMA:INIT
  • Get A0 PWM DMA data: :A0:PWM:DMA? 10 (reads 10 samples)

Examples

Initialize PWM Input

Command sent:

:A0:PWM:INIT\n

Response:

(OK)>

Read PWM Value

Command sent:

:A0:PWM?\n

Response:

A0:PWM=1234
(OK)>

Set PWM Output Frequency

Command sent:

:A0:OUT:SET:FREQ 1000\n

Response:

(OK)>

Read Frequency

Command sent:

:A0:FREQ?\n

Response:

A0:FREQ=1000
(OK)>

Deinitialize PWM

Command sent:

:A0:PWM:DEINIT\n

Response:

(OK)>

Error Example (Invalid Pin)

Command sent:

:Z9:PWM:INIT\n

Response:

ERR: unknown pin
(Some error)>

Notes

  • Commands are case-insensitive.
  • The command interface is extensible; new pins or features can be added by updating the command table and implementing the corresponding handler logic.
  • Some advanced or connector pin commands are present as comments and can be enabled as needed.