0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

H8/3664ではじめるマイコン制御4 MoterRotation

Last updated at Posted at 2019-01-06

93046 - コピー.jpg

今回はPort1xを使ってモータを動かしてみたいと思います。
モータはステッピングモータを使っています。
ステッピングモータとは
電流を与える毎に一定の角度(=そのステッピングモータ固有の角度)だけ回転するモータのことです。
1回電流を与えると、正確に一定の角度だけ回転します。

実際に動作させるにはステータに一定の順序で電流を流して励磁させることでモータを回転させることができます。
image.png

MoterRotation.c
//時計回りにモータを回転させるだけのプログラム
# include <stdio.h>

# define	BRR		(*((unsigned char *)0xFFA9))
# define	TMA		(*((unsigned char *)0xFFA6))

# define	PMR1	(*((unsigned char *)0xFFE0))
# define	PMR5	(*((unsigned char *)0xFFE1))

# define	PCR1	(*((unsigned char *)0xFFE4))
# define	PCR5	(*((unsigned char *)0xFFE8))
# define	PCR7	(*((unsigned char *)0xFFEA))
# define	PCR8	(*((unsigned char *)0xFFEB))

# define	PDR1	(*((unsigned char *)0xFFD4))
# define	PDR5	(*((unsigned char *)0xFFD8))
# define	PDR7	(*((unsigned char *)0xFFDA))
void wait();

main()
   {
	int i,cnt=1;
	unsigned char Seg1,Seg10;//表示用変数
	unsigned char rot;//1の位シフト用
	unsigned char rot10;//10の位シフト用
	
	BRR=12;			//16MHZ時には12を デフォルトは7 ボーレート変更	
 	PMR1 = 0x00;			/*ポート1を汎用IOに設定*/
 	PMR5 = 0x00;			/*ポート1を汎用IOに設定*/

	TMA = 0x98 ; 

 	PCR1 = 0xff;	//アドレス FFE4
    PCR5 = 0xff;	//FFE8
    PCR7 = 0x00;	
    PCR8 = 0xff;	//FFED		//00入力  ff出力
    
    
    if(cnt==1){//初期化
	Seg1=0x01;Seg10=0x81;rot=0x01;rot10=0x81;cnt=0;
		}

    for (;;) {/* 無限ループ */
	    
			PDR1=Seg1;
			wait(5000);//回転速度調整
		if(rot==0x80){
			Seg1=rot;
			rot=0x10;  //左へ1ビットシフト
			
		}
		else{
			Seg1=rot;
			rot=rot<<1;
		}
    }
    return 0;
   }

void wait(int n)
{
	int i;
 	for(i=0;i<n;i++);
}

前回の7segRotation.cを使いまわしたので使わなくなった変数も残ってしまっています。

次へH8/3664ではじめるマイコン制御5

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?