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.
- Output:
out = in + tone.outisinwhile nothing plays.- The tone is a square (
wave> 0) or a quieter sine (wave= 0) of peakampamps. 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.
- Enable:
- Nothing plays unless
en> 0: linked tofault0.en_pidthat is enabled and past phasing, so the bridge is on anyway and the tone never switches it on. endropping stops the tune, and a tune asked for while off does not start later.tuneandidentifyprint “not enabled” then.
- 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 onident) beeps three times three.
- Commands:
| Command | Action |
|---|---|
tune <notes> | load the notes and play them |
tune +<notes> | add the notes to the loaded ones, do not play |
tune ode | play Ode to Joy |
tune | play the loaded notes again |
tunex | stop |
identify | beep to find this drive |
- Notes:
- A note is
<letter>[#|b][octave][/len][.](#sharp,bflat):C4/4quarter middle C,F#5/8eighth,Bb3/2.dotted half,R/4quarter 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 forgateof 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 untiltunex.
Pins #
| Name | Description |
|---|---|
| in | input, d-axis command passed through (A), fb_switch0.id |
| out | output, in + tone (A), to hv0.d_cmd |
| en | input, tunes play only while > 0 (fault0.en_pid), default 1 |
| amp | parameter, tone peak current (A), default 6 |
| wave | parameter, 0 = sine, 1 = square, default 1 |
| bpm | parameter, quarter notes per minute, default 120 |
| gate | parameter, sounding fraction of each note, default 0.9 |
| loop | parameter, 1 = start a loaded tune over at the end, default 0 |
| chime | parameter, 1 = chime on the first enable after power-up, default 1 |
| ident | input, rising edge = identify |
| freq | output, note playing (Hz), 0 = rest or stopped |
| playing | output, 1 while a tune plays |
| chimed | output, 1 once the first enable after power-up has passed, with chime > 0 |
References #
Source: .c File