本日セコセコと作り上げました。
iPhone 003

針はアルミパイプをまげてとりあえず作ったもの。

今回のタコメータはステッピングモーターを使った利点でもありますが、自由度の高いスケールデザインで、今回はかずさんに無理を言ってTZタコの様な不等長のスケールになってますんで、角度を計算してモーターを回すステップ数を割り出してます。
名称未設定 2
0rpm
〜1,000rpm
〜6,000rpm
〜12,000rpm
と正確に言えば4段階のスケールですが、1〜1,000rpmは1,000rpmに切り上げてます。
細かくはソース見てね。

早速車体に取り付けて試走。
iPhone 002

まぁ色々と手直し部分もあったけど、とりあえず動いたからええかなと。

後は乗せた後かな〜。


横浜のかずさん
完成基板送りますがチョイと確認です。
メーターと基板を挟むT字型の土台はありますよね。
針を支持する部品ってこの間渡してましたっけ? そこが良く覚えてませんです。
もし持ってなければアクリル製のやつ一緒に送りますよ。 


あーやっとCDIの方に着手できる。
3連休が後一回あるから11月中にはソコソコ進めたい。 

ちなみにソースは毎度のBSDライセンスです。

[コードを表示する]
/* ------------------------------------------------------------------
              PIC12F1822 Pinout
              +--------+
          Vdd |1      8| GND
 Captre>- RA5 |2      7| RA0 -> OUT_B
  LED  <- RA4 |3      6| RA1 -> OUT_A
  MCLR -> RA3 |4      5| RA2 -> Suspend
              +--------+
-------------------------------------------------------------------*/

#include  // include standard header file

// set Config bits
#pragma config FOSC=INTOSC	// Oscillator Selection bits
#pragma config PLLEN=OFF	// PLL Enable bit
#pragma config WDTE=OFF		// Watch dog timer enable bit
#pragma config MCLRE=OFF	// MCLEAR enable bit
#pragma config CLKOUTEN=OFF	// Clock Out Enable bit
#pragma config IESO=OFF		// Internal External Switchover bit
#pragma config FCMEN=OFF	// Fail-Safe Clock Monitor Enable bit
#pragma config CP=OFF		// Code Protection bit
#pragma config CPD=OFF		// Data Code Protection bit
#pragma config BOREN=ON		// Brown-out Reset Enable bits
#pragma config WRT=OFF		// Flash Memory Self-Write Protection bits
#pragma config STVREN=ON	// Stack Overflow/Underflow Reset Enable bit
#pragma config BORV=LO		// Brown-out Reset Voltage Selection bit
#pragma config LVP=OFF		// Low-Voltage Programming Enable bit

// Definitions
#define _XTAL_FREQ  8000000        // this is used by the __delay_ms(xx) and __delay_us(xx) functions

#define OUTA			LATA0
#define OUTB			LATA1
#define SMD_STANDBY	LATA2
#define SM_SENS		RA3
#define LED			LATA4
#define INPULSE		RA5

#define HH()	{OUTA=1;OUTB=1;}
#define LH()	{OUTA=0;OUTB=1;}
#define LL()	{OUTA=0;OUTB=0;}
#define HL()	{OUTA=1;OUTB=0;}

#define TURN_L 1
#define TURN_R 0
#define SM_PULSE_INTERVAL	5	// pulse width with stepping motor
#define RPM_MAX			234	// 15,000rpm
#define RPM_RED			145	// 10,000rpm
#define SMD_STANDBY_ON		0
#define SMD_STANDBY_OFF		1

#define CNT_1000	60000
#define CNT_6000	10000
#define ADJ_1000	768000UL
#define ADJ_6000	1080000UL		// 0x107AC0

// Global
unsigned int gSMTarget = 0;
unsigned int gPos = 0;

/* ------------------------------------------------------------------
PIC Interrupt
-------------------------------------------------------------------*/
void interrupt Interrupt()
{
	if(CCP1IF)
	{
		unsigned int ccpr1;

		SMD_STANDBY = SMD_STANDBY_OFF;

		// Reset Timer1
		TMR1H=0;
		TMR1L=0;
		
		ccpr1 = ((CCPR1H * 0x100)|CCPR1L) + 1;
		
		if(ccpr1>CNT_1000) {
			gSMTarget = 3;
		} else if(ccpr1>CNT_6000) {
			gSMTarget = (unsigned int)(ADJ_1000/ccpr1) -3;  // 3 adjustment
		} else {
			gSMTarget = (unsigned int)(ADJ_6000/ccpr1) -36; // 36 adjustment
		}
		
		if(gSMTarget>RPM_MAX) gSMTarget = RPM_MAX;
		CCP1IF = 0;
	}
	
	// Timer1: Timeout means engine stop
	if(TMR1IF) {
		gSMTarget = 0;
		if(0 == gPos) {
			SMD_STANDBY = SMD_STANDBY_ON;
		}
		TMR1IF = 0;
		LED = 0;
	}
}

/* ------------------------------------------------------------------
Rotate stepping motor
-------------------------------------------------------------------*/
void rotate(int dir)
{
	static signed char phase = 0;
	
	if( dir ) {
		phase++;
		phase %= 4;
	}	
	else
	{
		phase--;
		if( phase < 0 ) phase = 3;
	}	

	switch( phase ) {
		case 0: HH(); break;
		case 1: LH(); break;
		case 2: LL(); break;
		case 3: HL(); break;
		default: break;
	}	
	__delay_ms(SM_PULSE_INTERVAL);
}

/* ------------------------------------------------------------------
initialize stepping motor and startup demo
-------------------------------------------------------------------*/
void startupdemo()
{
	int ii;
	
	// delay 3sec. for battery less.
	__delay_ms(3000);
	
	// make adjustment
	for(ii=0;ii<14;ii++)  {rotate(TURN_R);}
	// serch sensor
	while( 0 != SM_SENS ) {rotate(TURN_L);}
	while( 0 == SM_SENS ) {rotate(TURN_R);}
	rotate(TURN_R); // for sensor precision, forward one step.
	
	// fix 
	gPos == 0;
	for(ii=0;ii<10;ii++) {
		LED = !LED;
		__delay_ms(200);
	}	
	
	// demo
	for( ii = 0; ii < RPM_MAX; ii++ ) {
		rotate( TURN_R );
	}
	for( ii = 0; ii < RPM_MAX; ii++ ) {
		rotate( TURN_L );
	}
}	

/* ------------------------------------------------------------------
main
-------------------------------------------------------------------*/
void main ( ) 
{
	int ii, jj;

	OPTION_REG =	0b00000000;	// 
	WPUA =		0b00000000;	// pull-up pins
	
	// set up oscillator control register
	OSCCON=		0b01110010;	// 8Mhz

	// Set up I/O pins
	// PORT A Assignments
	APFCON=		0b00000001;	// CCP1 function is on RA5
	TRISA=		0b00101000;	// 
	PORTA=		0b00000000;	// Reset port
	ANSELA=		0b00000000;	// Disable analog input
	LED = 1;

	// Timer1 Clock Source Select bits
	T1CONbits.TMR1CS=0;		// 00 = Timer1 clock source is instruction clock (FOSC/4)
	T1CONbits.T1CKPS=0x01;		// Timer1 Input Clock Prescale Select bits 1:2 Prescale value
	T1CONbits.T1OSCEN=0;		// Dedicated Timer1 oscillator circuit disabled
	T1CONbits.nT1SYNC=1;		// 1 = Do not synchronize external clock input
	T1CONbits.TMR1ON=0;		// Timer1 On bit

	// Set up Capture input
	CCP1CON=	0b00000100;	// Capture mode: every falling edge
	// CCP1CON=		0b00000101;	// Capture mode: every rizing edge

	// Reset CCP1/Timer interrupt flag
	CCP1IF=0;
	TMR1IF=0;

	// Initialize Stepping motor postion
	SMD_STANDBY = SMD_STANDBY_OFF;
	
	startupdemo();

	// Enable Interrupt
	PEIE=1;			// Enable peripheral interrupt
	GIE=1;			// enable global interrupt
	CCP1IE=1;			// enable the CCP1 interrupt   
	TMR1IE=1;			// enable Timer1 intterupt on
	TMR1ON=1;			// Timer1 On

	while(1) {
		
		if( gSMTarget > gPos ) {
			rotate( TURN_R );
			gPos++;
			continue;
		} else if( gSMTarget < gPos ) {
			rotate( TURN_L );
			gPos--;
			continue;
		} else {
		}
		
		if( gSMTarget > RPM_RED ) {
			LED = 1;
		} else {
			LED = 0;
		}
	}
}
/*---------------------------------------------------------------------------------
Copyright 2012-2014 Rilassaru All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice, this list
   of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this
   list of conditions and the following disclaimer in the documentation and/or
   other materials provided with the distribution.
 * Neither the name of the Rilassaru nor the names of its contributors may be used
   to endorse or promote products derived from this software without specific prior
   written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/