Example #1
0
void fan_port_setup(void)
/*****************************************************************************
*   Input    : 	-
*   Output   : 	-
*   Function : 	fan GPIO setup.
******************************************************************************/

{
	INT8U	dummy;

	// PC4, DIGI A, PB1, DIGI B
	
	// Enable the GPIO port that is used for the digi switch.
  SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOD;
  
  // Do a dummy read to insert a few cycles after enabling the peripheral.
  dummy = SYSCTL_RCGC2_R;

  // Set the direction as input  
  SET_BIT_LOW(GPIO_PORTD_DIR_R, PD7);
  
  // Enable the GPIO pins for digital function (PF0 and PF1).
  SET_BIT_HIGH(GPIO_PORTD_DEN_R, PD7);
  
  // Disable open drain
  SET_BIT_LOW(GPIO_PORTD_ODR_R, PD7);
    
  // Disable alternative function
  SET_BIT_LOW(GPIO_PORTD_AFSEL_R,PD7);
  
  // Disable internal pull-up   
  SET_BIT_LOW(GPIO_PORTD_PUR_R, PD7);
}
Example #2
0
void pwm_init(void)
/*****************************************************************************
*   Input    :
*   Output   :
*   Function :
******************************************************************************/
{
	DDRB |= (1<<DDB5); // enable PB5 (led pin) as output
	DDRB |= (1<<DDB6); // enable PB6 (led pin) as output
	DDRE |= (1<<DDE3); // enable PE3 (led pin) as output
	DDRE |= (1<<DDE4); // enable PE4 (led pin) as output

	DDRA |= (1<<DDB2); // enable PA2 (led pin) as output for enable left
	DDRA |= (1<<DDB3); // enable PA3 (led pin) as output for enable right

	SET_BIT_LOW(PORTA,PA2);
	SET_BIT_LOW(PORTA,PA3);

	TCCR1A|= (1<<WGM10);	//  Phase Correct
	TCCR1A|= (1<<WGM11);	// 10 bit
//	TCCR1A|= (1<<WGM12); 	// CTC mode if only the only set
	TCCR1A|= (1<<COM1A1);	
	TCCR1A|= (1<<COM1B1);	
	TCCR1A|= (1<<COM1C1);	

/*	TCCR3A|= (1<<WGM30);	
	TCCR3A|= (1<<WGM31);
	TCCR3A|= (1<<COM3A1);	
	TCCR3A|= (1<<COM3B1);	
	TCCR3A|= (1<<COM3C1);	
*/
	
	TCCR1B |= (1<<CS10);
//	TCCR1B |= (1<<CS11);	// clock/1024 (15khz) see page 139
//	TCCR1B |= (1<<CS12);
/*
	TCCR3B |= (1<<CS30);	
//	TCCR3B |= (1<<CS31);	// clock/1024 (15khz) see page 139
	TCCR3B |= (1<<CS32);
*/
	SET_BIT_HIGH(PORTE,PE3);
	SET_BIT_HIGH(PORTE,PE4);

	OCR1AL = 255;	//PB5  // with current can only get very low pwm must changes to use HIGH regiset to OCR1AH
	OCR1AH = 3;
	OCR1BL = 255;	//PB6
	OCR1BH = 3;
	OCR1CL = 255;

	//OCR3AL = 255;	//PE3
	//OCR3BL = 255;	//PE4
	//OCR3CL = 255;
	
	set_pwm_speed_direction(100,'r');
	set_pwm_speed_direction(100,'l');
	
}
Example #3
0
void fan_int_setup(void)
{
	// Interrupt on Port PB1

	// Edge trigger
	SET_BIT_LOW(GPIO_PORTD_IS_R, PD7);
	// both edges
	SET_BIT_HIGH(GPIO_PORTD_IBE_R, PD7);

	// negative 	edge
	// SET_BIT_LOW(GPIO_PORTB_IEV_R, PB1);

	// Clear interrupt request
	SET_BIT_HIGH(GPIO_PORTD_ICR_R, PD7);

	// NVIC setup
	// program NVIC, vector number 17, Interrupt Number = 1
	// Clear pending interrupt
	NVIC_UNPEND0_R |= NVIC_UNPEND0_INT3;
	// Set Priority to 0x10, first clear then set.
	NVIC_PRI0_R &= ~(NVIC_PRI0_INT3_M);
	NVIC_PRI0_R |= (NVIC_PRI0_INT3_M & (0x10<<NVIC_PRI0_INT3_S));
	// enable NVIC interrupt
	NVIC_EN0_R |= NVIC_EN0_INT3;

	// Enable int
	ENABLE_FAN_INT;
}
Example #4
0
/*****************************************************************************
 * Function HandleGeniTestData
 * DESCRIPTION:
 *****************************************************************************/
void GeniAppTestMode::HandleGeniTestData(void)
{
  static bool firmware_update_started = false;
  static bool io_simulation_mode_enable = false;

  G_ge_io_simulation_status = mpIOSimulationStatus->GetValue();

  /* Handle G_ge_test_config */
  HandleTestConfig(G_ge_test_config);

  if (G_ge_io_simulation_mode_enable != IO_SIMULATION_ENABLED)
  {
    if (io_simulation_mode_enable == true)
    {
      mpIOSimulationDisable->SetEvent();
      HandleIOSimulation();  // To clear simulation data
      io_simulation_mode_enable = false;
    }
    // Normal test functions
    /* Handle G_ge_dig_out */
    IobComDrv::GetInstance()->SetDigitalOutputTestMode(G_ge_dig_out_ref);
    // Display
    mpDisplayContrast->SetValueAsPercent(G_ge_display_contrast/2.54f);
    mpDisplayBacklight->SetValueAsPercent(G_ge_display_backlight/2.54f);
  }
  else
  {
    // Handle IO simulation
    if (io_simulation_mode_enable == false)
    {
      mpIOSimulationEnable->SetEvent();
      io_simulation_mode_enable = true;
    }
    HandleIOSimulation();
  }


  /* Handle G_ge_error_log_control */
  if (TEST_BIT_HIGH(G_ge_error_log_control, 0)) //Reset ErrorLog
  {
    SET_BIT_LOW(G_ge_error_log_control, 0);
    ErrorLog::GetInstance()->ResetErrorLog();
  }

  /* Handle G_ge_firmware_update_state */
  if (G_ge_firmware_update_state == FIRMWARE_UPDATE_STATE_START && firmware_update_started == false)
  {
    mpFirmwareUpdateState->SetValue(FIRMWARE_UPDATE_STATE_START);
    firmware_update_started = true;
  }
  else if (G_ge_firmware_update_state == FIRMWARE_UPDATE_STATE_STARTBL && firmware_update_started == false)
  {
    mpFirmwareUpdateState->SetValue(FIRMWARE_UPDATE_STATE_STARTBL);
    firmware_update_started = true;
  }
  G_ge_firmware_update_state = mpFirmwareUpdateState->GetValue();

  if (G_ge_firmware_update_state != FIRMWARE_UPDATE_STATE_START && G_ge_firmware_update_state != FIRMWARE_UPDATE_STATE_STARTBL)
  {
    firmware_update_started = false;
  }

  /* Handle G_ge_test_loop_displays */
  if (G_ge_test_loop_displays == 1)

  {
    G_ge_test_loop_displays = 0;

    mpc::display::DisplayController::GetInstance()->TestLoopDisplays();
  }
  /* Handle G_ge_emwin_key_input */
  else if (G_ge_emwin_key_input != 255)
  {
    GUI_StoreKey(G_ge_emwin_key_input);
    G_ge_emwin_key_input = 255;
  }

  if (mpIobBoardId.IsUpdated())
  {
    G_ge_iob_board_id = mpIobBoardId->GetValue();
  }
  if (mpIobTemperature.IsUpdated())
  {
    G_ge_iob_temperature = (U16)(mpIobTemperature->GetValue() + 273.15f + 0.5f); // K
  }
  if (mpIobPressure.IsUpdated())
  {
    G_ge_iob_pressure = (U16)(mpIobPressure->GetValue()*0.01f + 0.5f); // Scale from Pa to mbar;
  }
  if (mpIobBatteryVoltage.IsUpdated())
  {
    G_ge_iob_battery_voltage = (U16)(mpIobBatteryVoltage->GetValue()*1000.0f + 0.5f); // Scale from V to mV
  }
  if (mpIobBusModulePressent.IsUpdated())
  {
    G_ge_iob_bus_module_pressent = mpIobBusModulePressent->GetValue();
  }
  if (mpIobSupplyStatus.IsUpdated())
  {
    G_ge_iob_supply_status = mpIobSupplyStatus->GetValue();
  }
  if (mpIobBatteryStatus.IsUpdated())
  {
    G_ge_iob_battery_status = mpIobBatteryStatus->GetValue();
  }
  if (mpAnalogInput0.IsUpdated())
  {
    G_ge_ana_in_raw_0 = mpAnalogInput0->GetValue();
  }
  if (mpAnalogInput1.IsUpdated())
  {
    G_ge_ana_in_raw_1 = mpAnalogInput1->GetValue();
  }
  if (mpAnalogInput2.IsUpdated())
  {
    G_ge_ana_in_raw_2 = mpAnalogInput2->GetValue();
  }
  if (mpAnalogInput3.IsUpdated())
  {
    G_ge_ana_in_raw_3 = mpAnalogInput3->GetValue();
  }
  if (mpAnalogInput4.IsUpdated())
  {
    G_ge_ana_in_raw_4 = mpAnalogInput4->GetValue();
  }
  if (mpAnalogInput5.IsUpdated())
  {
    G_ge_ana_in_raw_5 = mpAnalogInput5->GetValue();
  }
  if (mpDigitalInput.IsUpdated())
  {
    G_ge_dig_in = mpDigitalInput->GetValue();
  }
}
Example #5
0
void set_pwm_speed_direction(INT8U speed,INT8U one_char)
/*****************************************************************************
*   Input    :
*   Output   :
*   Function :
******************************************************************************/
{
	if(one_char == 'r')
	{
		current_speed_right = speed;
		if(speed <= 99)
		{
			new_speed = speed;
			if(new_speed == 0)
			{
				new_speed = 1;
			}
			SET_BIT_HIGH(PORTE,PE3);
			if(new_speed == 24 || new_speed == 49 || new_speed == 74)
			{
				OCR1AH = ((new_speed+ 1)/25);
				OCR1AL = ((((new_speed + 1) - (((new_speed + 1)/25) * 25)) * 255 ) / 25);
			}
			else{
				OCR1AH = ((new_speed)/25);
				OCR1AL = (((new_speed - ((new_speed/25) * 25)) * 255 ) / 25);
			}
		}
		else if(speed == 100)
		{
			SET_BIT_HIGH(PORTE,PE3);
			OCR1AL = 255;
			OCR1AH = 3;
		}
		else if(100 < speed && 200 >= speed)
		{
			new_speed = speed-100;
			if(new_speed == 100)
			{
				new_speed = 99;
			}
			SET_BIT_LOW(PORTE,PE3);
			if(new_speed == 24 || new_speed == 49 || new_speed == 74)
			{
				OCR1AH = ((new_speed + 1)/25);
				OCR1AL = ((((new_speed + 1) - (((new_speed + 1)/25) * 25)) * 255 ) / 25);
			}
			else{
				OCR1AH = ((new_speed)/25);
				OCR1AL = (((new_speed - ((new_speed/25) * 25)) * 255 ) / 25);
			}
		}
	}
	else if (one_char == 'l')
	{
		current_speed_left = speed;
		if(speed <= 99)
		{
			new_speed = speed;
			if(new_speed == 0)
			{
				new_speed = 1;
			}
			SET_BIT_HIGH(PORTE,PE4);
//			OCR1BL =  ((((100 - new_speed) - ((100 - new_speed)/25) * 25) * 255 ) / 25);
//			OCR1BH = new_speed/25;
			if(new_speed == 24 || new_speed == 49 || new_speed == 74)
			{
				OCR1BH = ((new_speed + 1)/25);
				OCR1BL = ((((new_speed + 1) - (((new_speed + 1)/25) * 25)) * 255 ) / 25);
			}
			else{
				OCR1BH = ((new_speed)/25);
				OCR1BL = (((new_speed - ((new_speed/25) * 25)) * 255 ) / 25);
			}
		}
		else if(speed == 100)
		{
			SET_BIT_HIGH(PORTE,PE4);
			OCR1BL = 255;
			OCR1BH = 3;
		}
		else if(100 < speed && 200 >= speed)
		{
			new_speed = speed-100;
//			if(new_speed == 100)
//			{
//				new_speed = 99;
//			}
			SET_BIT_LOW(PORTE,PE4);

//			OCR1BH = new_speed/25;
			if(new_speed == 24 || new_speed == 49 || new_speed == 74)
			{
				OCR1BH = ((new_speed + 1)/25);
				OCR1BL = ((((new_speed + 1) - (((new_speed + 1)/25) * 25)) * 255 ) / 25);
			}
			else{
				OCR1BH = ((new_speed)/25);
				OCR1BL = (((new_speed - ((new_speed/25) * 25)) * 255 ) / 25);
			}
		}
	}
}