BASIC4MCU | 모터 | BLDC모터 | 쿼드콥터 변속기 - tgy6a 소스코드 분석시 참고하세요-6a_ppm
페이지 정보
작성자 키트 작성일2017-09-05 15:18 조회1,837회 댓글0건본문
//**** **** **** **** ****.include "m8def.inc"//// 8K Bytes of In-System Self-Programmable Flash// 512 Bytes EEPROM// 1K Byte Internal SRAM//**** **** **** **** ****//**** **** **** **** ****// fuses must be set to internal calibrated oscillator= 8 mhz//**** **** **** **** ****//**** **** **** **** ****// RANGE533MS//#define MIN_RC_PULS 1250 // 탎 (or lower)= NO_POWER#define MIN_RC_PULS 1100 // 탎 (or lower)= NO_POWER//.include "6a_ppm.inc"//***********************************************************//* TP-18A *//* Mai.2007//***********************************************************#define Typ "6a_ppm"//**** **** **** **** ****// PORT definitions//**** **** **** **** ****//*********************// PORT D//*********************//#define PIND.7#define c_comp PIND.6 // common comparator input (AIN0)#define ApFET PORTD.5#define CpFET PORTD.4#define BpFET PORTD.3#define rcp_in PIND.2 // r/c pulse input#define INIT_PD 0#define DIR_PD (1<<ApFET)+(1<<BpFET)+(1<<CpFET)#define BRAKE_PD 0#define ApFET_on PORTD.5=1#define ApFET_off PORTD.5=0#define BpFET_on PORTD.3=1#define BpFET_off PORTD.3=0#define CpFET_on PORTD.4=1#define CpFET_off PORTD.4=0//*********************// PORT C definitions *//*********************#define mux_a 5 // phase input#define mux_c 4 // phase input//#define 3 // ADC3#define mux_b 2 // phase input//#define temp_adc 1 // ADC1 temperature control input//#define accu_adc 0 // ADC0 voltage control input//*********************// ADC only//*********************//#define PINC.7 // ADC7//#define PINC.6 // ADC6#define INIT_PC 0#define DIR_PC 0#define BRAKE_PC 0//*********************// PORT B definitions *//*********************//#define 7//#define 6//#define 5 (sck stk200 interface)//#define 4 (miso stk200 interface)//#define 3 (mosi stk200 interface)//#define 2//#define 1//#define 0#define AnFET PORTB.2#define CnFET PORTB.1#define BnFET PORTB.0#define INIT_PB 0#define DIR_PB (1<<AnFET)+(1<<BnFET)+(1<<CnFET)#define BRAKE_PB (1<<AnFET)+(1<<BnFET)+(1<<CnFET)#define AnFET_on PORTB.2=1#define AnFET_off PORTB.2=0#define BnFET_on PORTB.0=1#define BnFET_off PORTB.0=0#define CnFET_on PORTB.1=1#define CnFET_off PORTB.1=0#define CHANGE_TIMEOUT_LOW 1#define POWER_RANGE 100 // full range of tcnt0 setting#define MIN_DUTY 10 // no power#define NO_POWER 256-MIN_DUTY // (POWER_OFF_FLAG)#define MAX_POWER 256-POWER_RANGE // (FULL_POWER_FLAG)#define PWR_MAX_RPM1 POWER_RANGE/4 //25%#define PWR_MAX_RPM2 POWER_RANGE/2 //50%#define PWR_STARTUP MIN_DUTY //MIN_DUTY=10%#define PWR_MAX_STARTUP MIN_DUTY+20#define timeoutSTART 48000#define timeoutMIN 36000#define T1STOP 0x00#define T1CK8 0x02#define EXT0_DIS 0x00 // disable ext0int#define EXT0_EN 0x40 // enable ext0int#define OCT1_RANGE1 16 // ( ~2400 RPM )#define OCT1_RANGE2 8 // ( ~4800 RPM )//#define PWR_RANGE1 0x40 // ( ~2400 RPM )//#define PWR_RANGE2 0x20 // ( ~4800 RPM )#define PWR_RANGE1 0x20 // ( ~2400 RPM )#define PWR_RANGE2 0x10 // ( ~4800 RPM )#define ENOUGH_GOODIES 60#define RCP_TIMEOUT 100//**** **** **** **** ****// Register DefinitionsU_C i_sreg= 0; // status register save in interruptsU_C tcnt0_power_on= 0; // timer0 counts nFETs are switched onU_C tcnt0_pwron_next= 0;U_C rcpuls_timeout=0;U_C t1_timeout=0;U_C run_control=0;U_I start_rcpuls=0;bit OCT1_PENDING_FLAG= 0; // if set, output compare interrunpt is pendingbit C_FET_FLAG=0; // if set, C-FET state is to be changedbit A_FET_FLAG=0; // if set, A-FET state is to be changedbit I_OFF_CYCLE_FLAG=0; // if set, current off cycle is activebit T1OVFL_FLAG=0; // each timer1 overflow sets this flag - used for voltage + current watchbit POWER_OFF_FLAG=0; // switch fets on disabledbit FULL_POWER_FLAG=0; // 100% on - don't switch off, but do OFF_CYCLE workingbit CALC_NEXT_OCT1_FLAG=0; // calculate OCT1 offset, when wait_OCT1_before_switch is calledbit RC_PULS_UPDATED_FLAG=0; // new rc-puls value availablebit EVAL_RC_PULS_FLAG=0; // if set, new rc puls is evaluated, while waiting for OCT1bit EVAL_SYS_STATE_FLAG=0; // if set, overcurrent and undervoltage are checkedbit RPM_RANGE1_FLAG=0; // if set RPM is lower than 1831 RPMbit RPM_RANGE2_FLAG=0; // if set RPM is between 1831 RPM and 3662 RPMbit SCAN_TIMEOUT_FLAG=0; // if set a startup timeout occurredbit POFF_CYCLE_FLAG=0; // if set one commutation cycle is performed without powerbit COMP_SAVE_FLAG=0; // if set ACO was highbit STARTUP_FLAG=0; // if set startup-phase is activebit RC_INTERVAL_OK_FLAG=0;// here the XYZ registers are placed ( r26-r31)// ZH= new_duty // PWM destination//**** **** **** **** ****U_I tcnt1_sav=0; // actual timer1 valueU_I last_tcnt1=0; // last timer1 valueU_I timing_acc=0; // holds the average time of 4 commutationsU_L timing=0; // holds time of 4 commutations//U_L rpm=0; // holds the average time of 4 commutationsU_I wt_comp_scan=0; // time from switch to comparator scanU_I com_timing=0; // time from zero-crossing to switch of the appropriate FETU_I wt_OCT1_TimeOut=0; // OCT1 waiting timeU_I zero_wt=0;U_I stop_rcpuls=0;U_I new_rcpuls=0;char goodies=0;//**** **** **** **** ****// ATmega8 interrupts//.equ INT0addr=$001 // External Interrupt0 Vector Address//.equ INT1addr=$002 // External Interrupt1 Vector Address//.equ OC2addr =$003 // Output Compare2 Interrupt Vector Address//.equ OVF2addr=$004 // Overflow2 Interrupt Vector Address//.equ ICP1addr=$005 // Input Capture1 Interrupt Vector Address//.equ OC1Aaddr=$006 // Output Compare1A Interrupt Vector Address//.equ OC1Baddr=$007 // Output Compare1B Interrupt Vector Address//.equ OVF1addr=$008 // Overflow1 Interrupt Vector Address//.equ OVF0addr=$009 // Overflow0 Interrupt Vector Address//.equ SPIaddr =$00a // SPI Interrupt Vector Address//.equ URXCaddr=$00b // USART Receive Complete Interrupt Vector Address//.equ UDREaddr=$00c // USART Data Register Empty Interrupt Vector Address//.equ UTXCaddr=$00d // USART Transmit Complete Interrupt Vector Address//.equ ADCCaddr=$00e // ADC Interrupt Vector Address//.equ ERDYaddr=$00f // EEPROM Interrupt Vector Address//.equ ACIaddr =$010 // Analog Comparator Interrupt Vector Address//.equ TWIaddr =$011 // Irq. vector address for Two-Wire Interface//.equ SPMaddr =$012 // SPM complete Interrupt Vector Address//.equ SPMRaddr=$012 // SPM complete Interrupt Vector Address//-----bko-----------------------------------------------------------------//**** **** **** **** ****.cseg.org 0//**** **** **** **** ****//-----bko-----------------------------------------------------------------// reset and interrupt jump tablegoto resetgoto ext_int0nop // ext_int1nop // t2oc_intnop // t2ovfl_intnop // icp1goto t1oca_intnop // t1ocb_intgoto t1ovfl_intgoto t0ovfl_intnop // spi_intnop // urxcnop // udrenop // utxc// not used nop // adc_int// not used nop // eep_int// not used nop // aci_int// not used nop // wire2_int// not used nop // spmc_intversion:.db 0x0d, 0x0a.db "6a_ppm410r08_500hz"version_end:.db 0x0d, 0x0a//-----bko-----------------------------------------------------------------//-----bko-----------------------------------------------------------------// external interrupt0= rc pulse inputext_int0:i_sreg=SREG;GIMSK=0; // disable extint edge may be changed// evaluate edge of this interruptif((MCUCR&ISC00)==0)goto falling_edge; // bit is clear= falling edge// should be rising edge - test rc impuls level state for possible jitterif((PIND&rcp_in)==0)goto extint1_exit; // jump, if low state// rc impuls is at high stateMCUCR=(1<<ISC01); // set next int0 to falling edge// get timer1 valuesstart_rcpuls=TCNT1;// test rcpulse intervalRC_INTERVAL_OK_FLAG=0; // preset to not okif((start_rcpuls-stop_rcpuls)>=25000)goto extint1_fail; // 25ms // through awayif((start_rcpuls-stop_rcpuls)< 100)goto extint1_fail; // 100us // through awayRC_INTERVAL_OK_FLAG=1; // set to rc impuls value is ok !goto extint1_exit//--------------------------------------------------------extint1_fail:if(rcpuls_timeout)rcpuls_timeout--;goto extint1_exit//--------------------------------------------------------// rc impuls is at low statefalling_edge:
댓글 0
조회수 1,837등록된 댓글이 없습니다.