Skip to content

8. Embedded programming

General Info

Nueval

  • https://nueval.fabacademy.org/#/login
  • Login with fablabs.io
  • Student’s checklist
  • check all(weekly) -> local evaluation
  • 2-3 weekly completed local eval -> global eval(later)

Machine building

  • class: Mar 24: mechanical design, machine design
    • local session Sat Mar 27
  • break: Mar 31
    • local session Sat Apr 03
  • review (few minuets presentation): Apr 07

What to make

  • Group assignment -> one machine/team (per lab, between labs, collaborate with someone)
  • two weeks project

  • Mechanical Design

    • design a machine that includes mechanism+actuation+automation
    • build the mechanical parts and operate it manually
    • document the group project and your individual contribution
  • Machine Design

    • actuate and automate your machine
    • document the group project and your individual contribution
  • documentation

    • the group project -> lab site (Machine building)
      • video (1 min)
      • slide
    • your individual contribution -> your site (weekly page)
  • board and software…

    • existing commercial boards
    • existing software
  • parts

    • find and buy (amazon, monotaro, misumi)
    • 3D print
    • laser

ref. presentation last year

Assignment

Individual assignment:

Note

read a microcontroller data sheet
program your board to do something,
with as many different programming languages and programming environments as possible

Group assignment:

Note

compare the performance and development workflows for other architectures

TODO: Individual assignment

read a microcontroller data sheet

1
2
3
4
5
6
7
8
9
void setup() {
  pinMode(8, OUTPUT);
}
void loop() {
  digitalWrite(8,HIGH);
  delay(500);
  digitalWrite(8,LOW);
  delay(500);
}

AVR

1
2
3
4
5
6
7
8
9
void setup() {
  DDRB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
}
void loop() {
  PORTB |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
  delay(500);
  PORTB &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
  delay(500);
}

AVR 1-series

1
2
3
4
5
6
7
8
9
void setup() {
  PORTB.DIR |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をOUTPUT
}
void loop() {
  PORTB.OUT |= 0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をHIGH
  delay(500);
  PORTB.OUT &= ~0b00000001;//ポートBの0番ピン(Arduinoの8番ピン)をLOW
  delay(500);
}

ref. Arduinoで入出力を高速化する方法

Hint

// コメント

a = 0; //初期値 代入
b = a + 1; //代入
a = a + 1; //加算代入
a += a; //加算代入

DDRB = 0b000000; //初期値
DDRB = DDRB | 0b00000001; //OR
DDRB |= 0b00000001; //OR

OR

1
2
3
4
0  0  1  1    operand1
0  1  0  1    operand2
----------
0  1  1  1    (operand1 | operand2) - returned result
1に指定したbitは、元が0でも1でも、1になる -> 指定bitのセット

NOT

1
2
3
0  1    operand1
-----
1  0   ~operand1
1に指定したbitは、0に反転する (0は1に反転する)

AND

1
2
3
4
0  0  1  1    operand1
0  1  0  1    operand2
----------
0  0  0  1    (operand1 & operand2) - returned result
NOTで反転した0に指定したbitは、元が0でも1でも、0になる -> 指定bitのクリア

ref. Arduino Language Reference

Bitwise Operators (bit演算子)

機能 演算子 使用例
OR | 指定bitのセット
AND & 指定bitの取り出し, NOTと併用した指定bitのクリア
XOR ^ bit反転
NOT ~ bit反転, bitクリア
ビットシフト(右) >> ビットシフト
ビットシフト(左) << ビットシフト

program your board to do something,
with as many different programming languages and programming environments as possible

Software design

Arduino

  • echo.ino
    • class page
  • blink.ino
    • class page
    • ArduinoIDE File -> example
  • button
    • ArduinoIDE File -> example

C language

programming environments

TODO: Group assignment

compare the performance and development workflows for other architectures

Commercial board

Assessment

Embedded Programming

  • Is it enough for the group assignment if we compare different microcontrollers in theory?
    • Answer: No, You need to program at least two different family MCU’s.
  • How do I prove I’ve read the Datasheet?
    • Answer: Point out things in your code and board design that you learnt from the Datasheet. Also point to other weeks when you used information from the Datasheet.

Last update: March 21, 2021