手作りEFIコンピュータ(H8開発環境の構築)2013/10/10 22:31:26

淺原宏さん著書の「電子制御エンジンの基礎・応用」を参考にAW11用のEFIコンピュータを作ってみようと思っている。
いつできるのか、作れないのではないかと思いつつも、はじめてみないことにはどうにもならないので始めることにした。
どこまで続くかわからないが、後から参考になると思うのでやったことをメモしておくことにする。
肝心のAW11が手に入らない可能性が一番大きいが、なんかの役に立つと思ってやってみる。
ちなみに、回路自体は淺原さんの著書に丁寧に記載されているので、それを参考に手に入る部品で作る予定。

で、一番メインのCPUが手に入らないので、現時点で手に入るH8/3052BFで開発することにした。
これがうまく扱えないとこの先どうにもならないので次のサイトを参考にH8の開発環境を整えることにした。
http://www.kikaiken.org/lib/junk/h8dev-doc-linux/

手作りEFIコンピュータ(H8開発環境の構築1)2013/10/10 23:24:09

注:ここに記載したことに責任は取れません。利用、使用等する場合は自己責任でお願いします。
早速一発でコンパイルできない。
ftp://ftp.gnu.org/gnu/gcc/binutils からダウンロード
cd $WORK
tar zxvf $SRC/binutils-2.23.2.tar.gz
mv binutils-2.23.2 binutils-2.23.2_h8300
cd binutils-2.23.2_h8300
mkdir BUILD
cd BUILD
../configure --target=h8300-elf --prefix=/usr/local/h8300
make
ここでerror
google検索して解決策を発見。
http://www.mail-archive.com/bug-binutils@gnu.org/msg14429.html
書いてあるとおりに修正すれば直るが、このパッチフォーマットの当て方がわからないので手直ししてパッチを作った。
------------------------
$ cat binutils-2.23.2.patch
--- ./bfd/doc/bfd.texinfo.org 2010-10-28 20:40:25.000000000 +0900
+++ ./bfd/doc/bfd.texinfo 2013-10-10 23:10:42.000000000 +0900
@@ -322,7 +322,7 @@
@printindex cp

@tex
-% I think something like @colophon should be in texinfo. In the
+% I think something like @@colophon should be in texinfo. In the
% meantime:
\long\def\colophon{\hbox to0pt{}\vfill
\centerline{The body of this manual is set in}
@@ -333,7 +333,7 @@
\centerline{{\sl\fontname\tensl\/}}
\centerline{are used for emphasis.}\vfill}
\page\colophon
-% Blame: doc@cygnus.com, 28mar91.
+% Blame: doc@@cygnus.com, 28mar91.
@end tex

@bye
--- ./binutils/doc/binutils.texi.org 2013-03-25 17:06:21.000000000 +0900
+++ ./binutils/doc/binutils.texi 2013-10-10 23:18:20.000000000 +0900
@@ -148,18 +148,18 @@
* objcopy:: Copy and translate object files
* objdump:: Display information from object files
* ranlib:: Generate index to archive contents
-* readelf:: Display the contents of ELF format files
* size:: List section sizes and total size
* strings:: List printable strings from files
* strip:: Discard symbols
-* elfedit:: Update the ELF header of ELF files
* c++filt:: Filter to demangle encoded C++ symbols
* cxxfilt: c++filt. MS-DOS name for c++filt
* addr2line:: Convert addresses to file and line
* nlmconv:: Converts object code into an NLM
-* windres:: Manipulate Windows resources
* windmc:: Generator for Windows message resources
+* windres:: Manipulate Windows resources
* dlltool:: Create files needed to build and use DLLs
+* readelf:: Display the contents of ELF format files
+* elfedit:: Update the ELF header of ELF files
* Common Options:: Command-line options for all utilities
* Selecting the Target System:: How these utilities determine the target
* Reporting Bugs:: Reporting Bugs
@@ -2936,7 +2936,7 @@
@c man end
@end ignore

-@node c++filt, addr2line, elfedit, Top
+@node c++filt, addr2line, strip, Top
@chapter c++filt

@kindex c++filt
@@ -4413,7 +4413,7 @@

@table @env

-@itemx --input-mach=@var{machine}
+@item --input-mach=@var{machine}
Set the matching input ELF machine type to @var{machine}. If
@option{--input-mach} isn't specified, it will match any ELF
machine types.
@@ -4421,21 +4421,21 @@
The supported ELF machine types are, @var{L1OM}, @var{K1OM} and @var{x86-64}.
-@itemx --output-mach=@var{machine}
+@item --output-mach=@var{machine}
Change the ELF machine type in the ELF header to @var{machine}. The
supported ELF machine types are the same as @option{--input-mach}.

-@itemx --input-type=@var{type}
+@item --input-type=@var{type}
Set the matching input ELF file type to @var{type}. If
@option{--input-type} isn't specified, it will match any ELF file types.

The supported ELF file types are, @var{rel}, @var{exec} and @var{dyn}.

-@itemx --output-type=@var{type}
+@item --output-type=@var{type}
Change the ELF file type in the ELF header to @var{type}. The
supported ELF types are the same as @option{--input-type}.

-@itemx --input-osabi=@var{osabi}
+@item --input-osabi=@var{osabi}
Set the matching input ELF file OSABI to @var{osabi}. If
@option{--input-osabi} isn't specified, it will match any ELF OSABIs.

@@ -4445,7 +4445,7 @@
@var{FreeBSD}, @var{TRU64}, @var{Modesto}, @var{OpenBSD}, @var{OpenVMS},
@var{NSK}, @var{AROS} and @var{FenixOS}.

-@itemx --output-osabi=@var{osabi}
+@item --output-osabi=@var{osabi}
Change the ELF OSABI in the ELF header to @var{osabi}. The
supported ELF OSABI are the same as @option{--input-osabi}.

--- ./ld/ld.texinfo.org 2013-03-25 17:06:23.000000000 +0900
+++ ./ld/ld.texinfo 2013-10-10 23:22:22.000000000 +0900
@@ -139,15 +139,15 @@
@ifset I960
* i960:: ld and the Intel 960 family
@end ifset
+@ifset M68HC11
+* M68HC11/68HC12:: ld and the Motorola 68HC11 and 68HC12 families
+@end ifset
@ifset ARM
* ARM:: ld and the ARM family
@end ifset
@ifset HPPA
* HPPA ELF32:: ld and HPPA 32-bit ELF
@end ifset
-@ifset M68HC11
-* M68HC11/68HC12:: ld and the Motorola 68HC11 and 68HC12 families
-@end ifset
@ifset M68K
* M68K:: ld and Motorola 68K family
@end ifset
@@ -5998,6 +5998,9 @@
@ifset I960
* i960:: @command{ld} and the Intel 960 family
@end ifset
+@ifset M68HC11
+* M68HC11/68HC12:: @code{ld} and the Motorola 68HC11 and 68HC12 families
+@end ifset
@ifset ARM
* ARM:: @command{ld} and the ARM family
@end ifset
@@ -6013,9 +6016,6 @@
@ifset MSP430
* MSP430:: @command{ld} and MSP430
@end ifset
-@ifset M68HC11
-* M68HC11/68HC12:: @code{ld} and the Motorola 68HC11 and 68HC12 families
-@end ifset
@ifset POWERPC
* PowerPC ELF32:: @command{ld} and PowerPC 32-bit ELF Support
@end ifset
@@ -7863,7 +7863,7 @@
@printindex cp

@tex
-% I think something like @colophon should be in texinfo. In the
+% I think something like @@colophon should be in texinfo. In the
% meantime:
\long\def\colophon{\hbox to0pt{}\vfill
\centerline{The body of this manual is set in}
@@ -7874,7 +7874,7 @@
\centerline{{\sl\fontname\tensl\/}}
\centerline{are used for emphasis.}\vfill}
\page\colophon
-% Blame: doc@cygnus.com, 28mar91.
+% Blame: doc@@cygnus.com, 28mar91.
@end tex

@bye
------------------------
このパッチを当ててmakeしたらコンパイルできた。
make check
make install

手作りEFIコンピュータ(H8開発環境の構築2)2013/10/11 20:27:47

注:ここに記載したことに責任は取れません。利用、使用等する場合は自己責任でお願いします。
ftp://sources.redhat.com/pub/newlib/ ことと、
ftp://ftp.gnu.org/gnu/gcc/ ここからダウンロード。
まず、gccのコンパイルでnewlibのincludeファイルを参照するのでソースの展開から。
cd $WORK
tar zxvf $SRC/newlib-2.0.0.tar.gz
mv newlib-2.0 newlib-2.0.0_h8300

gccのコンパイル
※私のPCは非力なのでgccのmakeは4時間くらいかかりました。
cd $WORK
tar zxvf $SRC/gcc-4.8.1.tar.gz
mv gcc-4.8.1 gcc-4.8.1_h8300
cd gcc-4.8.1_h8300
mkdir BUILD
cd BUILD
../configure --target=h8300-elf --enable-languages="c++" --with-newlib --with-headers=$WORK/newlib-2.0.0_h8300/newlib/libc/include --prefix=/usr/local/h8300
make LANGUAGES="c c++"
make check
make install

続いてnewlibのコンパイル。
cd $WORK
cd newlib-2.0.0_h8300
mkdir BUILD
cd BUILD
../configure --target=h8300-elf --prefix=/usr/local/h8300
make
make check
make install

コンパイルが一通り終わったらPATHに/usr/local/h8300/binが入っていないと、H8用のプログラムのコンパイル時に
make: h8300-elf-gcc: Command not found
ってでます。
#経験した本人が言っているので間違いない。
export PATH=$PATH:/usr/local/h8300/bin
このままだと一度ログアウトするとPATHが戻ってしまうので、
/etc/prifile
あたりに追加しておくのがいいかな。
共有サーバであれば
~/.bash_profile
あたりに追加したほうがいいかも。

手作りEFIコンピュータ(H8開発環境の構築3)2013/10/11 22:16:01

注:ここに記載したことに責任は取れません。利用、使用等する場合は自己責任でお願いします。
ftp://ftp.gnu.org/gnu/gdb/ ここからダウンロード。
デバッガのコンパイル。たぶん使うので。
gdbのコンパイル
cd $WORK
tar zxvf $SRC/gdb-7.6.1.tar.gz
mv gdb-7.6.1 gdb-7.6.1_h8300
cd gdb-7.6.1_h8300
mkdir BUILD
cd BUILD
../configure --target=h8300-elf --prefix=/usr/local/h8300
make
make check
runtestがないって言われてcheckがとまるが、デバッガなので無視(本当は良くないけど)。
make install

手作りEFIコンピュータ(RAM使用量の検討1)2013/10/12 19:30:01

注:ここに記載したことに責任は取れません。利用、使用等する場合は自己責任でお願いします。
エンジンをコンピュータで制御すると言っても、コンピュータがエンジンのクランク軸を直接回すわけではない。
シリンダに適切な量のガソリンを入れ、適切な時期に点火することによりエンジンの回転数を制御するのである。
つまり、コンピュータはガソリンを噴射するインジェクターと、点火を司るイグナイターを制御することになる。
参考書では、これらを制御するためデータをいくつか用意している。
さっと読む限りでは、
 点火マップ:18x8x1B=144B
 基本噴射時間:18x16x3B=864B
 スロットル開度補正:18x16x3B=864B
 燃料制御補正:18x16x3B=864B
 係数:約160x2B=320B
 合計:3,056B
のデータを管理していたらしい。
確かにこの量のデータを扱うのであればRAMの増設は必須だったのは理解できる。
H8/3052は8KBのRAMが内蔵されているので、同じ量のデータを管理する分にはRAMの増設は必要ないだろう。
でも、制御の分解度を倍にすることを想定すると4倍のメモリが必要となり、8KBでは足りなくなる。
一通り形になってからになると思うが、容量的には十分過ぎる128KBのSRAMを2個増設する計画を進めようと思う。
※128KBの理由は、ただ手に入りそうなのがこのサイズだから。

手作りEFIコンピュータ(EPROM書き換え回数1)2013/10/12 20:30:39

注:ここに記載したことに責任は取れません。利用、使用等する場合は自己責任でお願いします。
H8/3052BFのマニュアルによるとEPROMの書き換え回数は100回となっている。
データの保存期間の保障等を考慮した回数のようで、これ以上の書き換えは可能なようなのだ。
しかし、私の開発能力ではあっという間に使い切ってしまうことが容易に想像できるので、フラッシュメモリを増設してそこで開発しようと思う。
あと、参考書でも、エンジン停止後にメモリ上のデータをEPROMに保存していたと記載されていたので、やはり100回では足りない。
とりあえず、256KBのフラッシュメモリを2個増設する計画とした。
※256KBの理由は、RAM同様に手に入りそうだからということと、なぜ2個かというと、8bitチップなので16bit(word)アクセス可能な様にするため。

PIC16F88(TMR0の値)2013/10/14 15:39:34

PIC16F88でTimer0を使うとき、TMR0(8bit)カウンタにセットする値の計算メモ。
当該PICは4クロックで1命令処理される。
8MHzで動作させているときは1クロック0.125μs。
prescalerを1:256でTimer0に使うとき、10msの時間で割り込みさせるには、
256-10ms/(0.125μs*4*256)+2=179.875≒180
をセットする。
※+2は、TMR0に値を書き込んだ後、2 instruction cyclesカウンタをincrementしない仕様なので、その調整値

linux-3.11.62013/10/20 13:32:22

2013.10.18にreleaseされていた。
http://www.kernel.org/

手作りEFIコンピュータ(H8/3052BF半田付け1)2013/10/30 11:27:13

注:ここに記載したことに責任は取れません。利用、使用等する場合は自己責任でお願いします。
TQFP100とH8/3052BFを入手したので半田付けに挑戦した。
かなり細かい作業となるので虫眼鏡も用意しておいた。
下のような半田付け用の拡大鏡があれば作業しやすいと思うが、今後同じような細かい作業が頻繁にあるとは思えないので近所の100円均一に行って拡大率2倍のものを手に入れた。

手作りEFIコンピュータ(H8/3052BF半田付け2)2013/10/30 11:41:13

注:ここに記載したことに責任は取れません。利用、使用等する場合は自己責任でお願いします。
0.5mmピッチのH8/3052BFの半田付けは結構大変だった。
まず基盤側に半田ペーストを塗っておいて、その上からH8を載せて半田付けした。
はじめは1本1本足を着けていく計画だったが半田のこて先に少量のハンダがうまく乗らず結果として複数の足にまたがってハンダが付いてしまった。
まあこうなることは事前にピッチの狭い半田付けについてgoogleで検索して分かっていたので、当該部分に半田ペーストを着け半田吸い取り線で余分なハンダを吸い取らせて対応した。