void ckps_init_state(void) { _BEGIN_ATOMIC_BLOCK(); ckps_init_state_variables(); CLEARBIT(flags, F_ERROR); MCUCR|=_BV(ISC11); //falling edge for INT1 MCUCR|=_BV(ISC10); //set flag indicating that Hall sensor input is available WRITEBIT(flags, F_HALLSIA, IOCFG_CHECK(IOP_PS)); GICR|= CHECKBIT(flags, F_HALLSIA) ? _BV(INT1) : 0; //INT1 enabled only when Hall sensor input is available //Compare channels do not connected to lines of ports (normal port mode) //(Каналы Compare не подключены к линиям портов (нормальный режим портов)) TCCR1A = 0; //Tune timer 1 (clock = 250kHz) TCCR1B = _BV(CS11)|_BV(CS10); //enable overflow interrupt of timer 0 //(разрешаем прерывание по переполнению таймера 0) TIMSK|= _BV(TOIE0); _END_ATOMIC_BLOCK(); }
void cams_init_state(void) { _BEGIN_ATOMIC_BLOCK(); cams_init_state_variables(); camstate.cam_error = 0; //no errors //set flag indicating that cam sensor input is available WRITEBIT(flags, F_CAMSIA, IOCFG_CHECK(IOP_PS)); #ifdef SECU3T /*SECU-3T*/ //interrupt by rising edge MCUCR|= _BV(ISC11) | _BV(ISC10); MCUCR|= _BV(ISC01) | _BV(ISC00); #ifdef PHASE_SENSOR if (CHECKBIT(flags, F_CAMSIA)) GICR|= _BV(INT0) | _BV(INT1); //INT1 enabled only when cam sensor is utilized in the firmware or input is available else GICR|= _BV(INT0); #else GICR|= _BV(INT0); //это нам нужно для ДНО #endif #endif _END_ATOMIC_BLOCK(); }
/** Special function for processing falling edge, * must be called from ISR * \param tmr Timer value at the moment of falling edge */ INLINE void ProcessFallingEdge(uint16_t tmr) { //save period value if it is correct. We need to do it forst of all to have fresh stroke_period value if (CHECKBIT(flags, F_VHTPER)) { //calculate stroke period hall.stroke_period = tmr - hall.measure_start_value; WRITEBIT(flags, F_SPSIGN, tmr < hall.measure_start_value); //save sign hall.t1oc_s = hall.t1oc, hall.t1oc = 0; //save value and reset counter } SETBIT(flags, F_VHTPER); SETBIT(flags, F_STROKE); //set the stroke-synchronization event (устанавливаем событие тактовой синхронизации) hall.measure_start_value = tmr; if (!CHECKBIT(flags2, F_SHUTTER_S)) { uint16_t delay; #ifdef STROBOSCOPE hall.strobe = 1; //strobe! #endif //----------------------------------------------------- //Software PWM is very sensitive even to small delays. So, we need to allow OCF2 and TOV2 //interrupts occur during processing of this handler. #ifdef COOLINGFAN_PWM _ENABLE_INTERRUPT(); #endif //----------------------------------------------------- //start timer for counting out of advance angle (spark) delay = (((uint32_t)hall.advance_angle * hall.stroke_period) / hall.degrees_per_stroke); #ifdef COOLINGFAN_PWM _DISABLE_INTERRUPT(); #endif OCR1A = tmr + ((delay < 15) ? 15 : delay) - CALIBRATION_DELAY; //set compare channel, additionally prevent spark missing when advance angle is near to 60° TIFR1 = _BV(OCF1A); TIMSK1|= _BV(OCIE1A); //start timer for countiong out of knock window opening if (CHECKBIT(flags, F_USEKNK)) { #ifdef COOLINGFAN_PWM _ENABLE_INTERRUPT(); #endif delay = ((uint32_t)hall.knock_wnd_begin * hall.stroke_period) / hall.degrees_per_stroke; #ifdef COOLINGFAN_PWM _DISABLE_INTERRUPT(); #endif set_timer0(delay); hall.knkwnd_mode = 0; } knock_start_settings_latching();//start the process of downloading the settings into the HIP9011 (запускаем процесс загрузки настроек в HIP) adc_begin_measure(_AB(hall.stroke_period, 1) < 4);//start the process of measuring analog input values (запуск процесса измерения значений аналоговых входов) } }
void ckps_set_edge_type(uint8_t edge_type) { //Set CKPS input edge only if it is not remapped if (hall.ckps_inpalt) { WRITEBIT(flags2, F_SELEDGE, edge_type); //save selected edge type _BEGIN_ATOMIC_BLOCK(); if (edge_type) TCCR1B|= _BV(ICES1); //rising else TCCR1B&=~_BV(ICES1); //falling _END_ATOMIC_BLOCK(); } }
/**INT0 handler function (Interrupt from a Hall sensor (external)) * Called from camsens.c */ void ProcessInterrupt0(void) //see also prototype of this function in camsens.c { uint16_t tmr = TCNT1; //toggle edge if (EICRA & _BV(ISC00)) { //falling if (CHECKBIT(flags2, F_SELEDGE)) ProcessRisingEdge(); else ProcessFallingEdge(tmr); EICRA&= ~(_BV(ISC00)); //next edge will be rising } else { //rising if (CHECKBIT(flags2, F_SELEDGE)) ProcessFallingEdge(tmr); else ProcessRisingEdge(); EICRA|=_BV(ISC00); //next will be falling } WRITEBIT(flags2, F_SHUTTER_S, CHECKBIT(flags2, F_SHUTTER)); //synchronize SETBIT(flags, F_HALLEV); //set event flag }
void ckps_set_shutter_spark(uint8_t i_shutter) { _BEGIN_ATOMIC_BLOCK(); //we need this because in ATmega644 this flag is not in I/O register WRITEBIT(flags2, F_SHUTTER, i_shutter); _END_ATOMIC_BLOCK(); }
void ckps_enable_ignition(uint8_t i_cutoff) { WRITEBIT(flags, F_IGNIEN, i_cutoff); //enable/disable ignition }
void ckps_use_knock_channel(uint8_t use_knock_channel) { WRITEBIT(flags, F_USEKNK, use_knock_channel); }
void ckps_set_shutter_spark(uint8_t i_shutter) { WRITEBIT(flags2, F_SHUTTER, i_shutter); }