final code mai 22.
This commit is contained in:
		
							
								
								
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							@ -3,5 +3,6 @@
 | 
			
		||||
    "cortex-debug.openocdPath": "C:\\USERS\\NIVED\\APPDATA\\ROAMING\\CODE\\USER\\GLOBALSTORAGE\\BMD.STM32-FOR-VSCODE\\@XPACK-DEV-TOOLS\\OPENOCD\\0.12.0-2.1\\.CONTENT\\BIN\\OPENOCD.EXE",
 | 
			
		||||
    "files.associations": {
 | 
			
		||||
        "current_monitoring.h": "c"
 | 
			
		||||
    }
 | 
			
		||||
    },
 | 
			
		||||
    "cortex-debug.variableUseNaturalFormat": false
 | 
			
		||||
}
 | 
			
		||||
@ -50,7 +50,7 @@ typedef union {
 | 
			
		||||
void ChannelControl_init(I2C_HandleTypeDef* hi2c, TIM_HandleTypeDef* timer3,
 | 
			
		||||
                         TIM_HandleTypeDef* timer2);
 | 
			
		||||
void ChannelControl_UpdateGPIOs(PortExtenderGPIO);
 | 
			
		||||
void ChannelControl_UpdatePWMs(uint8_t radiatorfans,uint8_t tsacfans ,  uint8_t pwmaggregat,
 | 
			
		||||
void ChannelControl_UpdatePWMs(uint8_t radiatorfans, uint8_t pwmaggregat,
 | 
			
		||||
                               uint8_t pwmpumps);
 | 
			
		||||
 | 
			
		||||
#endif /* INC_CHANNEL_CONTROL_H_ */
 | 
			
		||||
 | 
			
		||||
@ -23,39 +23,32 @@ void ChannelControl_init(I2C_HandleTypeDef* hi2c, TIM_HandleTypeDef* timer3,
 | 
			
		||||
  PCA9535_init(hi2c, 0);
 | 
			
		||||
  PCA9535_setGPIOPortOutput(PC9535_PORTA, 0x00);
 | 
			
		||||
  PCA9535_setGPIOPortOutput(PC9535_PORTB, 0x00);
 | 
			
		||||
  PCA9535_setGPIOPortDirection(PC9535_PORTA, 0x00);
 | 
			
		||||
  PCA9535_setGPIOPortDirection(PC9535_PORTB, 0x00);
 | 
			
		||||
  PCA9535_setGPIOPortDirection(PC9535_PORTA, GPIO_DIR_OUTPUT);
 | 
			
		||||
  PCA9535_setGPIOPortDirection(PC9535_PORTB, GPIO_DIR_OUTPUT);
 | 
			
		||||
 | 
			
		||||
  EN_Ports.porta.porta = 0;
 | 
			
		||||
  EN_Ports.portb.portb = 0;
 | 
			
		||||
  EN_Ports.porta.alwayson = 1;
 | 
			
		||||
  ChannelControl_UpdateGPIOs(EN_Ports);
 | 
			
		||||
  ChannelControl_UpdatePWMs(0, 0, 0, 0);
 | 
			
		||||
  ChannelControl_UpdatePWMs(0, 0, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChannelControl_UpdateGPIOs(PortExtenderGPIO UpdatePorts) { // ctrl + left click auf portextender 
 | 
			
		||||
  EN_Ports = UpdatePorts;
 | 
			
		||||
  UpdatePorts.porta.alwayson = 1;// Always on stays always on
 | 
			
		||||
 PCA9535_setGPIOPortOutput(PC9535_PORTA, UpdatePorts.porta.porta);
 | 
			
		||||
 PCA9535_setGPIOPortOutput(PC9535_PORTB, UpdatePorts.portb.portb);
 | 
			
		||||
  UpdatePorts.porta.alwayson = 1;
 | 
			
		||||
 gpio_port_b testb={}; //(testing code)
 | 
			
		||||
 testb.en16=1; //(testing code)
 | 
			
		||||
 PCA9535_setGPIOPortOutput(PC9535_PORTB, testb.portb); //(testing code)
 | 
			
		||||
  gpio_port_a testa={}; //(testing code)
 | 
			
		||||
  testa.en1=1; //(testing code)
 | 
			
		||||
  testa.en13=1; // (testing code)
 | 
			
		||||
 | 
			
		||||
  PCA9535_setGPIOPortOutput(PC9535_PORTA, testa.porta); //(testing code)
 | 
			
		||||
  UpdatePorts.porta.alwayson = 1; // Always on stays always on
 | 
			
		||||
  PCA9535_setGPIOPortOutput(PC9535_PORTA, UpdatePorts.porta.porta);
 | 
			
		||||
  PCA9535_setGPIOPortOutput(PC9535_PORTB, UpdatePorts.portb.portb);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChannelControl_UpdatePWMs(uint8_t radiatorfans,uint8_t tsacfans ,  uint8_t pwmaggregat,
 | 
			
		||||
                               uint8_t pwmpumps){
 | 
			
		||||
                
 | 
			
		||||
void ChannelControl_UpdatePWMs(
 | 
			
		||||
  uint8_t radiatorfans,
 | 
			
		||||
  uint8_t pwmaggregat,
 | 
			
		||||
  uint8_t pwmpumps
 | 
			
		||||
){
 | 
			
		||||
 | 
			
		||||
  pwmtimer3->Instance->CCR4 = pwmpumps << 8;
 | 
			
		||||
  pwmtimer3->Instance->CCR1 = radiatorfans << 8;
 | 
			
		||||
  pwmtimer2->Instance->CCR2 = tsacfans << 8;
 | 
			
		||||
  //pwmtimer2->Instance->CCR2 = tsacfans << 8;
 | 
			
		||||
 | 
			
		||||
  if (timer3_running) {
 | 
			
		||||
    if ((pwmpumps == 0) && (radiatorfans == 0)) {
 | 
			
		||||
@ -71,7 +64,7 @@ void ChannelControl_UpdatePWMs(uint8_t radiatorfans,uint8_t tsacfans ,  uint8_t
 | 
			
		||||
}
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (timer2_running) {
 | 
			
		||||
  /*if (timer2_running) {
 | 
			
		||||
    if (tsacfans == 0) {
 | 
			
		||||
      timer2_running = 0;
 | 
			
		||||
      HAL_TIM_PWM_Stop(pwmtimer2, TIM_CHANNEL_2);
 | 
			
		||||
@ -81,7 +74,7 @@ void ChannelControl_UpdatePWMs(uint8_t radiatorfans,uint8_t tsacfans ,  uint8_t
 | 
			
		||||
      timer2_running = 1;
 | 
			
		||||
      HAL_TIM_PWM_Start(pwmtimer2, TIM_CHANNEL_2);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  }*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -125,17 +125,19 @@ int main(void)
 | 
			
		||||
  MX_TIM6_Init();
 | 
			
		||||
  /* USER CODE BEGIN 2 */
 | 
			
		||||
  
 | 
			
		||||
  // HAL_GPIO_WritePin(STATUS_LED2_GPIO_Port, STATUS_LED2_Pin, GPIO_PIN_SET); // status led wird an gemacht , das leuchtet 
 | 
			
		||||
    HAL_GPIO_WritePin(STATUS_LED1_GPIO_Port , STATUS_LED1_Pin , GPIO_PIN_SET);
 | 
			
		||||
    HAL_GPIO_WritePin( GSS_GPIO_GPIO_Port, GSS_GPIO_Pin , GPIO_PIN_SET);
 | 
			
		||||
    ChannelControl_init(&hi2c1, &htim3, &htim2);
 | 
			
		||||
    // handler struktur ( handler adc1 .... usw )
 | 
			
		||||
   can_init(&hcan); // can bus initilisiert , kommunikation zum hauptsteuergeraet ( autobox )
 | 
			
		||||
   currentMonitor_init(&hadc1, &hadc2, &htim6); 
 | 
			
		||||
  HAL_GPIO_WritePin(STATUS_LED1_GPIO_Port , STATUS_LED1_Pin , GPIO_PIN_SET);
 | 
			
		||||
  HAL_GPIO_WritePin(GSS_GPIO_GPIO_Port, GSS_GPIO_Pin, GPIO_PIN_SET);
 | 
			
		||||
 | 
			
		||||
  ChannelControl_init(&hi2c1, &htim3, &htim2);
 | 
			
		||||
  // handler struktur ( handler adc1 .... usw )
 | 
			
		||||
  can_init(&hcan); // can bus initilisiert , kommunikation zum hauptsteuergeraet ( autobox )
 | 
			
		||||
 | 
			
		||||
  currentMonitor_init(&hadc1, &hadc2, &htim6);
 | 
			
		||||
 | 
			
		||||
  uint32_t lasttick = HAL_GetTick(); // gibt dir zuruck die milisekunden seit start. ( es fangt an und dann milisekunden + 1 usw....)
 | 
			
		||||
  HAL_TIM_Base_Start(&htim2);
 | 
			
		||||
  HAL_TIM_Base_Start(&htim3);
 | 
			
		||||
  // ChannelControl_UpdatePWMs(20 , 50 , 0 ,  50 ); ( testing code )
 | 
			
		||||
  // ChannelControl_UpdatePWMs(20 , 0 ,  50 ); ( testing code )
 | 
			
		||||
  /* USER CODE END 2 */
 | 
			
		||||
 | 
			
		||||
  /* Infinite loop */
 | 
			
		||||
@ -148,8 +150,11 @@ while(1)
 | 
			
		||||
    if (canmsg_received) { // USB zu CAN wandler , und dann CAN testen , validieren ob der code macht was es soll , red mit oskar/jasper 
 | 
			
		||||
      canmsg_received = 0;
 | 
			
		||||
      ChannelControl_UpdateGPIOs(rxstate.iostatus);
 | 
			
		||||
      ChannelControl_UpdatePWMs(rxstate.radiatorfans, rxstate.tsacfans, rxstate.pwmaggregat,
 | 
			
		||||
                                rxstate.cooling_pump); // gotta change , to see whats left of it and whats not
 | 
			
		||||
      ChannelControl_UpdatePWMs(
 | 
			
		||||
        rxstate.radiatorfans,
 | 
			
		||||
        rxstate.pwmaggregat,
 | 
			
		||||
        rxstate.cooling_pump
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ((HAL_GetTick() - lasttick) > 100U) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user