모터 > 쿼드콥터 변속기 - tgy6a 소스코드 분석시 참고하세요-6a_ppm

TODAY801 TOTAL2,918,692
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


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
//* http://home.versanet.de/~b-konze/                       *
//*********************************************************** 

#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 Definitions
U_C i_sreg= 0;         // status register save in interrupts
U_C tcnt0_power_on= 0; // timer0 counts nFETs are switched on
U_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 pending
bit    C_FET_FLAG=0;           // if set, C-FET state is to be changed
bit    A_FET_FLAG=0;           // if set, A-FET state is to be changed
bit    I_OFF_CYCLE_FLAG=0;     // if set, current off cycle is active
bit    T1OVFL_FLAG=0;          // each timer1 overflow sets this flag - used for voltage + current watch

bit    POWER_OFF_FLAG=0;       // switch fets on disabled
bit    FULL_POWER_FLAG=0;      // 100% on - don't switch off, but do OFF_CYCLE working
bit    CALC_NEXT_OCT1_FLAG=0;  // calculate OCT1 offset, when wait_OCT1_before_switch is called
bit    RC_PULS_UPDATED_FLAG=0; // new rc-puls value available
bit    EVAL_RC_PULS_FLAG=0;    // if set, new rc puls is evaluated, while waiting for OCT1
bit    EVAL_SYS_STATE_FLAG=0;  // if set, overcurrent and undervoltage are checked

bit    RPM_RANGE1_FLAG=0;      // if set RPM is lower than 1831 RPM
bit    RPM_RANGE2_FLAG=0;      // if set RPM is between 1831 RPM and 3662 RPM
bit    SCAN_TIMEOUT_FLAG=0;    // if set a startup timeout occurred
bit    POFF_CYCLE_FLAG=0;      // if set one commutation cycle is performed without power
bit    COMP_SAVE_FLAG=0;       // if set ACO was high
bit    STARTUP_FLAG=0;         // if set startup-phase is active
bit    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 value
U_I last_tcnt1=0; // last timer1 value
U_I timing_acc=0; // holds the average time of 4 commutations 

U_L timing=0; // holds time of 4 commutations 
//U_L rpm=0;    // holds the average time of 4 commutations 



U_I wt_comp_scan=0;    // time from switch to comparator scan
U_I com_timing=0;      // time from zero-crossing to switch of the appropriate FET
U_I wt_OCT1_TimeOut=0; // OCT1 waiting time
U_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 table
        goto reset
        goto ext_int0
        nop    // ext_int1
        nop    // t2oc_int
        nop    // t2ovfl_int
        nop    // icp1
        goto t1oca_int
        nop    // t1ocb_int
        goto t1ovfl_int
        goto t0ovfl_int
        nop    // spi_int
        nop    // urxc
        nop    // udre
        nop    // 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_int


version:
    .db    0x0d, 0x0a
    .db    "6a_ppm410r08_500hz"
version_end:
    .db    0x0d, 0x0a


//-----bko-----------------------------------------------------------------

//-----bko-----------------------------------------------------------------
// external interrupt0= rc pulse input
ext_int0:
    i_sreg=SREG;
    GIMSK=0; // disable extint edge may be changed

// evaluate edge of this interrupt
    if((MCUCR&ISC00)==0)goto falling_edge; // bit is clear= falling edge

// should be rising edge - test rc impuls level state for possible jitter
    if((PIND&rcp_in)==0)goto extint1_exit; // jump, if low state

// rc impuls is at high state
    MCUCR=(1<<ISC01); // set next int0 to falling edge

// get timer1 values
        start_rcpuls=TCNT1;
// test rcpulse interval
    RC_INTERVAL_OK_FLAG=0; // preset to not ok
    if((start_rcpuls-stop_rcpuls)>=25000)goto extint1_fail; // 25ms  // through away
    if((start_rcpuls-stop_rcpuls)<   100)goto extint1_fail; // 100us // through away
    RC_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 state
falling_edge:

댓글 0

조회수 1,837

등록된 댓글이 없습니다.

모터HOME > 모터 > BLDC모터 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기