Exemple #1
0
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();
}
Exemple #2
0
void ckps_set_advance_angle(int16_t angle)
{
 int16_t aad = (HALL_ADVANCE - angle);
 _BEGIN_ATOMIC_BLOCK();
 hall.advance_angle = aad;
 _END_ATOMIC_BLOCK();
}
Exemple #3
0
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();
}
Exemple #4
0
void ckps_init_state_variables(void)
{
 _BEGIN_ATOMIC_BLOCK();

 hall.stroke_period = 0xFFFF;
 hall.advance_angle = hall.shutter_wnd_width; //=0

 CLEARBIT(flags, F_STROKE);
 CLEARBIT(flags, F_VHTPER);
 CLEARBIT(flags, F_HALLEV);
 CLEARBIT(flags, F_SPSIGN);
 SETBIT(flags, F_IGNIEN);
 SETBIT(flags2, F_SHUTTER);
 SETBIT(flags2, F_SHUTTER_S);

 TIMSK1|=_BV(TOIE1);                  //enable Timer 1 overflow interrupt. Used for correct calculation of very low RPM

 hall.t1oc = 0;                       //reset overflow counter
 hall.t1oc_s = 255;                   //RPM is very low

#ifdef STROBOSCOPE
 hall.strobe = 0;
#endif

 hall.knkwnd_mode = 0;
#ifdef DWELL_CONTROL
 hall.cr_acc_time = 0;
#endif

#ifdef FUEL_INJECT
 hall.cur_chan = 0;
#endif
 _END_ATOMIC_BLOCK();
}
Exemple #5
0
void ckps_init_state(void)
{
 _BEGIN_ATOMIC_BLOCK();

 if ((IOCFG_CB(IOP_CKPS) == (fnptr_t)iocfg_g_ckps) || (IOCFG_CB(IOP_CKPS) == (fnptr_t)iocfg_g_ckpsi))
 {
  CLEARBIT(flags2, F_SELEDGE); //falling edge
  hall.ckps_inpalt = 1; //not remapped
 }
 else
  hall.ckps_inpalt = 0; //CKPS mapped on other input

 ckps_init_state_variables();
 CLEARBIT(flags, F_ERROR);

 //Compare channels do not connected to lines of ports (normal port mode)
 //(Каналы Compare не подключены к линиям портов (нормальный режим портов))
 TCCR1A = 0;

 TCCR1B = _BV(CS11)|_BV(CS10);  //Tune timer 1 (clock = 312.5 kHz)
 TCCR0B = _BV(CS01)|_BV(CS00);  //Tune timer 0 (clock = 312.5 kHz)

 if (hall.ckps_inpalt)
  TIMSK1|=_BV(ICIE1);    //enable input capture interrupt only if CKPS is not remapped
 _END_ATOMIC_BLOCK();
}
Exemple #6
0
void ckps_set_advance_angle(int16_t angle)
{
 int16_t aad = (hall.shutter_wnd_width - angle);
 _BEGIN_ATOMIC_BLOCK();
 hall.advance_angle = aad;
 _END_ATOMIC_BLOCK();
}
Exemple #7
0
void ckps_init_state_variables(void)
{
 _BEGIN_ATOMIC_BLOCK();

 hall.stroke_period = 0xFFFF;
 hall.advance_angle = HALL_ADVANCE; //=0

 CLEARBIT(flags, F_STROKE);
 CLEARBIT(flags, F_VHTPER);
 CLEARBIT(flags, F_HALLEV);
 CLEARBIT(flags, F_SPSIGN);
 SETBIT(flags2, F_SHUTTER);
 SETBIT(flags2, F_SHUTTER_S);
 SETBIT(flags, F_IGNIEN);

 TCCR0 = 0; //timer is stopped (останавливаем таймер0)

 MCUCR|=_BV(ISC11); //falling edge for INT1
 MCUCR|=_BV(ISC10);

 TIMSK|=_BV(TOIE1);                   //enable Timer 1 overflow interrupt. Used for correct calculation of very low RPM
 hall.t1oc = 0;                       //reset overflow counter
 hall.t1oc_s = 255;                   //RPM is very low

#ifdef STROBOSCOPE
 hall.strobe = 0;
#endif

 hall.knkwnd_mode = 0;
 _END_ATOMIC_BLOCK();
}
Exemple #8
0
//Initializes SPI in master mode
static void spi_master_init(void)
{
 _BEGIN_ATOMIC_BLOCK();
 // enable SPI, master, clock = fck/16, data on falling edge of SCK
 SPCR = _BV(SPE)|_BV(MSTR)|_BV(SPR0)|_BV(CPHA);
 _END_ATOMIC_BLOCK();
}
Exemple #9
0
void ckps_set_shutter_wnd_width(int16_t width)
{
 int16_t begin_d = (width + hall.knock_wnd_begin_v); //start of window
 hall.shutter_wnd_width = width; //save it to use in other setters
 _BEGIN_ATOMIC_BLOCK();
 hall.knock_wnd_begin = begin_d;
 _END_ATOMIC_BLOCK();
}
Exemple #10
0
uint8_t ckps_is_cog_changed(void)
{
 uint8_t result;
 _BEGIN_ATOMIC_BLOCK();
 result = CHECKBIT(flags, F_HALLEV) > 0;
 CLEARBIT(flags, F_HALLEV);
 _END_ATOMIC_BLOCK();
 return result;
}
Exemple #11
0
void ckps_set_knock_window(int16_t begin, int16_t end)
{
 int16_t begin_d = (HALL_ADVANCE + begin); //start of window
 int16_t end_d = (end - begin); //width of window
 _BEGIN_ATOMIC_BLOCK();
 hall.knock_wnd_begin = begin_d;
 hall.knock_wnd_end = end_d;
 _END_ATOMIC_BLOCK();
}
Exemple #12
0
void cams_vr_set_edge_type(uint8_t edge_type)
{
 _BEGIN_ATOMIC_BLOCK();
 if (edge_type)
  MCUCR|= _BV(ISC00); //rising
 else
  MCUCR&= ~_BV(ISC00);//falling
 _END_ATOMIC_BLOCK();
}
Exemple #13
0
uint8_t ckps_is_stroke_event_r()
{
 uint8_t result;
 _BEGIN_ATOMIC_BLOCK();
 result = CHECKBIT(flags, F_STROKE) > 0;
 CLEARBIT(flags, F_STROKE);
 _END_ATOMIC_BLOCK();
 return result;
}
Exemple #14
0
uint8_t cams_is_event_r(void)
{
 uint8_t result;
 _BEGIN_ATOMIC_BLOCK();
 result = camstate.event;
 camstate.event = 0; //reset event flag
 _END_ATOMIC_BLOCK();
 return result;
}
Exemple #15
0
void ckps_set_knock_window(int16_t begin, int16_t end)
{
 int16_t begin_d = (hall.shutter_wnd_width + begin); //start of window
 int16_t end_d = (end - begin); //width of window
 hall.knock_wnd_begin_v = begin; //save begin value to use in other setters
 _BEGIN_ATOMIC_BLOCK();
 hall.knock_wnd_begin = begin_d;
 hall.knock_wnd_end = end_d;
 _END_ATOMIC_BLOCK();
}
Exemple #16
0
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();
 }
}
Exemple #17
0
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();
}
Exemple #18
0
void ckps_set_acc_time(uint16_t i_acc_time)
{
 _BEGIN_ATOMIC_BLOCK();
 hall.cr_acc_time = i_acc_time;
 _END_ATOMIC_BLOCK();
}
Exemple #19
0
void knock_set_gain(uint8_t gain)
{
 _BEGIN_ATOMIC_BLOCK();
 ksp.ksp_gain = KSP_SET_GAIN | (gain & 0x3F);
 _END_ATOMIC_BLOCK();
}
Exemple #20
0
void knock_set_int_time_constant(uint8_t inttime)
{
 _BEGIN_ATOMIC_BLOCK();
 ksp.ksp_inttime = KSP_SET_INTEGRATOR | (inttime & 0x1F);
 _END_ATOMIC_BLOCK();
}
Exemple #21
0
void knock_set_channel(uint8_t channel)
{
 _BEGIN_ATOMIC_BLOCK();
 ksp.ksp_channel = KSP_SET_CHANNEL | (channel & 0x01);
 _END_ATOMIC_BLOCK();
}
Exemple #22
0
void knock_set_band_pass(uint8_t freq)
{
 _BEGIN_ATOMIC_BLOCK();
 ksp.ksp_bpf = KSP_SET_BANDPASS | (freq & 0x3F);
 _END_ATOMIC_BLOCK();
}