Melody

MELODY #

Brief #

melody plays a tune through the motor: an audio rate current added to the d-axis command makes the stator hum the notes without torque (with the commutation offset right). It also plays a ready chime after power-up and beeps on identify, to find which drive is which. F4 component, loaded by conf/template/melody.txt (link melody after link pmsm), which inserts it between the d-axis source and hv:

load melody
melody0.rt_prio = 6
melody0.in = fb_switch0.id
melody0.en = fault0.en_pid
hv0.d_cmd = melody0.out

Component Explanation #

All playing is done in rt; the commands only load notes and start or stop a tune.

  1. Output:
  • out = in + tone. out is in while nothing plays.
  • The tone is a square (wave > 0) or a quieter sine (wave = 0) of peak amp amps. Every note starts at zero current; rests and the silent part of a note add nothing.
  • The rt thread runs at 5 kHz, so notes above about 2 kHz alias, and the current loop damps the high notes.
  1. Enable:
  • Nothing plays unless en > 0: linked to fault0.en_pid that is enabled and past phasing, so the bridge is on anyway and the tone never switches it on.
  • en dropping stops the tune, and a tune asked for while off does not start later. tune and identify print “not enabled” then.
  1. Chime and identify:
  • With chime > 0 a short rising arpeggio (C4 E G C5) plays on the first enable after power-up, so the drive says it booted and runs its config.
  • identify (or a rising edge on ident) beeps three times three.
  1. Commands:
CommandAction
tune <notes>load the notes and play them
tune +<notes>add the notes to the loaded ones, do not play
tune odeplay Ode to Joy
tuneplay the loaded notes again
tunexstop
identifybeep to find this drive
  1. Notes:
  • A note is <letter>[#|b][octave][/len][.] (# sharp, b flat): C4/4 quarter middle C, F#5/8 eighth, Bb3/2. dotted half, R/4 quarter rest. Octave and length carry over from the previous note (start: 4, /4). Lengths 1 to 64.
  • A quarter note is one beat at bpm; each note sounds for gate of its length so repeated notes stay apart.
  • At most 128 notes are loaded. A terminal line holds 63 characters, so a longer tune is loaded in parts with tune +; each part starts again at octave 4, /4. A line with a bad note changes nothing.
  • With loop > 0 a loaded tune (not the chime or identify) starts over at the end until tunex.

Pins #

NameDescription
ininput, d-axis command passed through (A), fb_switch0.id
outoutput, in + tone (A), to hv0.d_cmd
eninput, tunes play only while > 0 (fault0.en_pid), default 1
ampparameter, tone peak current (A), default 6
waveparameter, 0 = sine, 1 = square, default 1
bpmparameter, quarter notes per minute, default 120
gateparameter, sounding fraction of each note, default 0.9
loopparameter, 1 = start a loaded tune over at the end, default 0
chimeparameter, 1 = chime on the first enable after power-up, default 1
identinput, rising edge = identify
freqoutput, note playing (Hz), 0 = rest or stopped
playingoutput, 1 while a tune plays
chimedoutput, 1 once the first enable after power-up has passed, with chime > 0

References #

Source: .c File