1
00:00:00,200 --> 00:00:09,523
This tutorial goes from starting embeddyn Lab to an emulated microcontroller that drives a DC motor and measures its current through an analog circuit.

2
00:00:09,523 --> 00:00:21,706
Five steps: start the Lab, define a firmware component, make a bare-metal project with the pin configurator, add the analog electronics and the actuators, then analyse the signals.

3
00:00:21,706 --> 00:00:31,949
Start the Lab from the repository with ./run.sh. The first run makes a Python environment; later runs start at once and open the browser.

4
00:00:31,949 --> 00:00:44,253
Once per computer, record where Renode and the Arm toolchain are. devboards user-env writes them to ~/.config/embeddyn/env.sh, which run.sh loads.

5
00:00:44,253 --> 00:00:55,172
This is the Lab. On the left, the workspaces: Design, Monitor, RF, Firmware, Emulation, Catalog, Component builder, Pins and Logs.

6
00:00:55,172 --> 00:01:01,825
Design has the part library, the schematic, the inspector on the right and the instrument dock below.

7
00:01:01,825 --> 00:01:07,774
The status bar shows the tools it found: Renode, OpenOCD, gdb.

8
00:01:07,774 --> 00:01:17,794
First, a firmware component of our own, in the Component builder: a soft-start ramp that limits how fast the motor's duty cycle may change.

9
00:01:18,464 --> 00:01:25,059
New gives an empty part. Give it an ID, a name, a category and the domain firmware.

10
00:01:25,059 --> 00:01:35,827
The firmware domain makes an equation model, a software block. The note says how to run a real binary instead: a dev board with its firmware, which we do next.

11
00:01:39,397 --> 00:01:44,797
Pins: one input, the duty command, and one output, the duty.

12
00:01:44,797 --> 00:01:49,398
A parameter: rate, the largest change per second, 2.

13
00:01:49,398 --> 00:01:57,653
A state d with its derivative: follow the command, but never faster than the rate. The builder integrates it with Runge-Kutta.

14
00:01:57,653 --> 00:02:03,367
The output equation: the duty is the state, kept between 0 and 1.

15
00:02:03,367 --> 00:02:09,889
Test runs the part alone: a step of the command to 1 gives a ramp that takes half a second.

16
00:02:09,889 --> 00:02:15,955
Save part puts it in the parts folder and in the Design library, under My parts.

17
00:02:20,515 --> 00:02:27,556
Now the real firmware. Open Pins and start the pin configurator: it runs next to the Lab.

18
00:02:27,556 --> 00:02:36,448
Choose the Pin Configurator workspace and the board: MSPM0C1104, 20-pin VSSOP.

19
00:02:36,448 --> 00:02:44,693
Switch on the peripherals the firmware uses: UART 0 for the console, timer A0 for the PWM, and the ADC.

20
00:02:44,693 --> 00:02:48,802
PA22: GPIO, an output for LED 1.

21
00:02:48,802 --> 00:02:53,302
PA16: GPIO input with pull-up, the S1 button.

22
00:02:53,302 --> 00:02:59,792
PA17 and PA18: UART 0 transmit and receive, the console.

23
00:03:01,232 --> 00:03:07,293
PA2: timer A0 capture-compare 0, the PWM that drives the motor.

24
00:03:07,293 --> 00:03:12,341
PA25: ADC channel 2. It will read the motor current.

25
00:03:12,341 --> 00:03:18,651
The used-pins table lists the pinout, and the health check stays clean: no conflicts.

26
00:03:18,651 --> 00:03:25,553
Save the pinout as a project file in the firmware folder, so you can reopen and change it later.

27
00:03:25,561 --> 00:03:36,893
Generate Files, then the Files tab: next to Zephyr, Arduino and PlatformIO there is a bare-metal target, an MSPM0 SDK DriverLib project with CMake.

28
00:03:36,893 --> 00:03:49,303
Scope Full project writes main.c and the CMake files too; later, after a pinout change, Init code only rewrites just the setup. Enter the folder and Save to folder.

29
00:03:49,303 --> 00:03:57,001
Here is the generated setup code: clocks, pins, UART, timer and ADC, with the names you gave.

30
00:03:57,001 --> 00:04:08,281
On the left, Firmware project: emulation setup makes the project debuggable in Renode and runnable in the Lab. Board, folder, ELF and pinout, then Set up.

31
00:04:08,281 --> 00:04:23,470
It wrote env.sh with this computer's tool paths, build.sh, debug.sh, gdb.sh, the VS Code tasks and cortex-debug launch, and lab.yaml, the Lab project made from the pinout.

32
00:04:23,470 --> 00:04:35,269
Write the application in main.c: it sweeps the PWM duty, reads the ADC and prints the motor current in milliamps. The pin names come from the generated header.

33
00:04:35,269 --> 00:04:41,558
Build it with ./build.sh: CMake and the Arm GCC from env.sh.

34
00:04:41,558 --> 00:04:53,041
For source-level debugging, open the folder in VS Code and press F5: cortex-debug attaches to Renode's GDB server. Tutorial 13 shows that part.

35
00:04:53,041 --> 00:05:04,447
Open lab.yaml loads the board with this ELF, its LED, button and console, and the pinout's parts: a slider for the ADC input and a gauge for the PWM duty.

36
00:05:04,447 --> 00:05:11,619
Set the run to 8 seconds in the project settings, then Run. Renode starts the MCU with our firmware.

37
00:05:11,619 --> 00:05:20,527
LED 1 blinks, the gauge follows the PWM sweep. Drag the ISENSE slider: the firmware reads the voltage through the ADC.

38
00:05:20,527 --> 00:05:24,581
The Console tab shows the firmware's UART output.

39
00:05:25,399 --> 00:05:35,689
Now the hardware around the MCU: a soft-start, a DC motor on a drivetrain, a supply, and an analog current-sense circuit feeding the ADC.

40
00:05:35,689 --> 00:05:48,559
The analog part is a SPICE netlist: a 50 milliohm shunt, a gain-of-5 amplifier around mid-rail, so 0 amps is 1.65 volts, and an RC low-pass at the ADC pin.

41
00:05:48,559 --> 00:05:56,839
The bindings file says what the Lab sets each step, the motor current into the shunt, and which voltages it reads back.

42
00:05:58,189 --> 00:06:03,997
Remove the ISENSE slider: the circuit drives that ADC input from now on.

43
00:06:05,167 --> 00:06:14,106
Add the parts from the library: search, then double-click. First our soft-start ramp, then the DC motor and the drivetrain.

44
00:06:14,106 --> 00:06:18,464
A slider as the motor supply, and the SPICE circuit.

45
00:06:27,306 --> 00:06:39,146
Point the SPICE part at the netlist and its bindings: the model field, then the options. Its pins appear: the motor current in, the shunt and ADC voltages out.

46
00:06:39,146 --> 00:06:44,178
Set the supply slider to 0 to 12 volts, starting at 12.

47
00:06:44,178 --> 00:06:49,289
The drivetrain: a light rotor and load, with viscous load friction.

48
00:06:49,289 --> 00:06:58,949
Wire output pins, on the right of a part, to input pins on the left. The PWM duty goes into the soft-start, its output into the motor.

49
00:06:58,949 --> 00:07:01,644
The slider is the supply voltage.

50
00:07:01,644 --> 00:07:07,578
Motor torque drives the drivetrain; the motor speed comes back as the back-EMF input.

51
00:07:07,578 --> 00:07:15,241
The motor current flows through the shunt in the circuit, and the circuit's ADC voltage goes to the MCU's ISENSE input.

52
00:07:15,241 --> 00:07:23,479
To see the signals, add instruments: an oscilloscope with four channels, a multimeter, and a 3-D motor shaft.

53
00:07:29,331 --> 00:07:40,616
Scope channel A: the PWM duty from the firmware. B: after the soft-start. C: the motor current. D: the voltage at the ADC pin.

54
00:07:40,616 --> 00:07:46,014
The multimeter reads the motor speed; the shaft turns with the drivetrain angle.

55
00:07:46,014 --> 00:07:50,602
Check validates the project, Save writes lab.yaml.

56
00:07:52,102 --> 00:08:02,837
Run. The firmware's PWM sweeps up, the soft-start passes it on, the motor accelerates, and its current comes back through the analog circuit to the ADC.

57
00:08:02,837 --> 00:08:17,581
When the firmware's sweep wraps from 100 to 0 percent, the soft-start ramps the duty down over half a second. The motor briefly regenerates: the current goes negative, the ADC voltage dips below 1.65.

58
00:08:17,581 --> 00:08:22,509
Drag the supply down while it runs: speed and current follow.

59
00:08:25,941 --> 00:08:29,332
The 3-D view shows the shaft turning.

60
00:08:33,575 --> 00:08:42,180
After the run, the replay slider scrubs through the recorded signals; the scope, the meters and the live values on the pins follow it.

61
00:08:42,180 --> 00:08:49,699
The Console has the firmware's own measurement: the current it computed from the ADC reading, in milliamps.

62
00:08:51,619 --> 00:08:58,536
The Breadboard view lays the SPICE circuit out as a prototype, with the values of the run on its nodes.

63
00:09:01,156 --> 00:09:05,771
CSV exports every signal of the run for your own analysis tools.

64
00:09:05,771 --> 00:09:18,127
That is the whole path: a firmware component, a bare-metal project from a pinout, the real firmware in Renode, analog electronics and actuators around it, and the signals to analyse.
