- ロガー周り
- ロガーは0~5V アナログ4ch
- 増幅後のセンサー電圧をそのまま計測用マイコンとロガー接続用コネクタに分岐させるだけでおk
- 去年のログ取りはアクセル信号・バッテリー電圧・速度・電流
- ラダー抵抗で速度パルスを電圧にf/V変換する。後はそのままロガーに入れているだけ。
- サンプリング周期は2s
- それで4時間持つ。
- http://www.tandd.co.jp/product/ml7x/index.php
- チップ選考
- I2C
- http://akizukidenshi.com/catalog/items2.php?c=rom&s=popularity&p=1&r=1&page=#I-00694
- http://www.necel.com/ja/faq/mi78k/__78iic.html
- http://www.technochips.co.jp/TechTips/I2CDOC/i2c.html
- http://avrwiki.jpn.ph/wiki.cgi?page=%A5%B5%A5%F3%A5%D7%A5%EB%A5%D7%A5%ED%A5%B0%A5%E9%A5%E0
- http://www11.ocn.ne.jp/~akibow/AVR/TWI/TWI.html
- I2Cサンプルプログラム
(twi.c)
<avr/io.h>
<compat/twi.h>
"twi.h"
uint8_t TWI_wait(void)
{
{
uint8_t r; WAIT_TWINT; r=TW_STATUS; return (r);
}
char sla_set(uint8_t sla_rw)
{
/* if OK,return TW_MT_SLA_ACK. */
{
/* if OK,return TW_MT_SLA_ACK. */
char r; //printf_P(PSTR("PRESLA=%02X"),TWCR); //TWI_wait(); TWI_START; r=TWI_wait(); if (r!=TW_REP_START && r!=TW_START) goto sla_set_end; r=TWI_write(sla_rw); if (r==TW_MT_ARB_LOST) goto sla_set_end; if (r==TW_MT_SLA_ACK||r==TW_MR_SLA_ACK) goto sla_set_end; TWI_STOP; sla_set_end: return (r);
}
uint8_t TWI_write(uint8_t x)
{
{
TWDR=x; TWI_NEXT; return TWI_wait();
}
uint8_t TWI_read(char ack)
{
{
uint8_t r; if (ack) { TWI_ACK; } else { TWI_NACK; } TWI_wait(); r=TWDR; return (r);
}
void twi_init(void)
{
{
TWSR = 0; //TWIプリスケーラは0にしておく TWBR = TWBR_VALUE; TWCR = _BV(TWEN);
}
(twi.h)
<compat/twi.h>
#define
SET_TWCR(x) {TWCR=(x)|_BV(TWINT)|_BV(TWEN);}while(0)
#define
TWI_START SET_TWCR(_BV(TWSTA))
#define
TWI_ACK SET_TWCR(_BV(TWEA))
#define
TWI_NACK SET_TWCR(0)
#define
TWI_NEXT SET_TWCR(0)
#define
TWI_STOP SET_TWCR(_BV(TWSTO))
#define
TWI_END SET_TWCR(0)
#define
WAIT_TWINT loop_until_bit_is_set(TWCR,TWINT)
#define
F_SCL (100000L) /*100kHz*/
#define
TWBR_VALUE ((F_CPU/F_SCL-16)/2)
#define
MAX_ST (128)
#define
MAX_SR (2)
extern void twi_init(void);
extern uint8_t TWI_wait(void);
extern uint8_t TWI_start(void);
extern uint8_t TWI_stop(void);
extern uint8_t TWI_write(uint8_t x);
extern uint8_t TWI_read(char ack);
extern char sla_set(uint8_t sla_rw);
extern uint8_t TWI_wait(void);
extern uint8_t TWI_start(void);
extern uint8_t TWI_stop(void);
extern uint8_t TWI_write(uint8_t x);
extern uint8_t TWI_read(char ack);
extern char sla_set(uint8_t sla_rw);