Browse Source

Initial commit

master
Lukas 3 years ago
commit
1d63b3a478
5 changed files with 1342 additions and 0 deletions
  1. +157
    -0
      fancontroller.ioc
  2. BIN
      fancontroller.pdf
  3. +631
    -0
      fancontroller.sch
  4. +467
    -0
      main.c
  5. +87
    -0
      main.h

+ 157
- 0
fancontroller.ioc View File

@@ -0,0 +1,157 @@
#MicroXplorer Configuration settings - do not modify
File.Version=6
GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false
Mcu.Family=STM32G0
Mcu.IP0=NVIC
Mcu.IP1=RCC
Mcu.IP2=SYS
Mcu.IP3=TIM2
Mcu.IP4=USART2
Mcu.IPNb=5
Mcu.Name=STM32G031F(4-6-8)Px
Mcu.Package=TSSOP20
Mcu.Pin0=PA0
Mcu.Pin1=PA1
Mcu.Pin10=PB6
Mcu.Pin11=VP_SYS_VS_Systick
Mcu.Pin12=VP_TIM2_VS_ClockSourceINT
Mcu.Pin2=PA2
Mcu.Pin3=PA3
Mcu.Pin4=PA4
Mcu.Pin5=PA5
Mcu.Pin6=PA6
Mcu.Pin7=PA7
Mcu.Pin8=PA13
Mcu.Pin9=PA14-BOOT0
Mcu.PinsNb=13
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32G031F8Px
MxCube.Version=6.1.1
MxDb.Version=DB.6.0.10
NVIC.EXTI4_15_IRQn=true\:0\:0\:false\:false\:true\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.SVC_IRQn=true\:0\:0\:false\:false\:true\:false\:false
NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
PA0.Locked=true
PA0.Signal=S_TIM2_CH1
PA1.Signal=S_TIM2_CH2
PA13.Mode=Serial_Wire
PA13.Signal=SYS_SWDIO
PA14-BOOT0.Mode=Serial_Wire
PA14-BOOT0.Signal=SYS_SWCLK
PA2.Mode=Asynchronous
PA2.Signal=USART2_TX
PA3.Mode=Asynchronous
PA3.Signal=USART2_RX
PA4.GPIOParameters=GPIO_Label
PA4.GPIO_Label=Case1
PA4.Locked=true
PA4.Signal=GPXTI4
PA5.GPIOParameters=GPIO_Label
PA5.GPIO_Label=Case2
PA5.Locked=true
PA5.Signal=GPXTI5
PA6.GPIOParameters=GPIO_Label
PA6.GPIO_Label=CPU
PA6.Locked=true
PA6.Signal=GPXTI6
PA7.GPIOParameters=GPIO_Label
PA7.GPIO_Label=GPU
PA7.Locked=true
PA7.Signal=GPXTI7
PB6.GPIOParameters=GPIO_PuPd,GPIO_Label
PB6.GPIO_Label=Switch
PB6.GPIO_PuPd=GPIO_PULLDOWN
PB6.Locked=true
PB6.Signal=GPIO_Input
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=true
ProjectManager.BackupPrevious=false
ProjectManager.CompilerOptimize=6
ProjectManager.ComputerToolchain=false
ProjectManager.CoupleFile=false
ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32G031F8Px
ProjectManager.FirmwarePackage=STM32Cube FW_G0 V1.4.1
ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=1
ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=fans.ioc
ProjectManager.ProjectName=fans
ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_TIM2_Init-TIM2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true
RCC.ADCFreq_Value=16000000
RCC.AHBFreq_Value=16000000
RCC.APBFreq_Value=16000000
RCC.APBTimFreq_Value=16000000
RCC.CortexFreq_Value=16000000
RCC.EXTERNAL_CLOCK_VALUE=12288000
RCC.FCLKCortexFreq_Value=16000000
RCC.FamilyName=M
RCC.HCLKFreq_Value=16000000
RCC.HSE_VALUE=8000000
RCC.HSI_VALUE=16000000
RCC.I2C1Freq_Value=16000000
RCC.I2S1Freq_Value=16000000
RCC.IPParameters=ADCFreq_Value,AHBFreq_Value,APBFreq_Value,APBTimFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2S1Freq_Value,LPTIM1Freq_Value,LPTIM2Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,SYSCLKFreq_VALUE,TIM1Freq_Value,USART1Freq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
RCC.LPTIM1Freq_Value=16000000
RCC.LPTIM2Freq_Value=16000000
RCC.LPUART1Freq_Value=16000000
RCC.LSCOPinFreq_Value=32000
RCC.LSE_VALUE=32768
RCC.LSI_VALUE=32000
RCC.MCO1PinFreq_Value=16000000
RCC.PLLPoutputFreq_Value=64000000
RCC.PLLQoutputFreq_Value=64000000
RCC.PLLRCLKFreq_Value=64000000
RCC.PWRFreq_Value=16000000
RCC.SYSCLKFreq_VALUE=16000000
RCC.TIM1Freq_Value=16000000
RCC.USART1Freq_Value=16000000
RCC.VCOInputFreq_Value=16000000
RCC.VCOOutputFreq_Value=128000000
SH.GPXTI4.0=GPIO_EXTI4
SH.GPXTI4.ConfNb=1
SH.GPXTI5.0=GPIO_EXTI5
SH.GPXTI5.ConfNb=1
SH.GPXTI6.0=GPIO_EXTI6
SH.GPXTI6.ConfNb=1
SH.GPXTI7.0=GPIO_EXTI7
SH.GPXTI7.ConfNb=1
SH.S_TIM2_CH1.0=TIM2_CH1,PWM Generation1 CH1
SH.S_TIM2_CH1.ConfNb=1
SH.S_TIM2_CH2.0=TIM2_CH2,PWM Generation2 CH2
SH.S_TIM2_CH2.ConfNb=1
TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM2.Channel-PWM\ Generation1\ CH1=TIM_CHANNEL_1
TIM2.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
TIM2.ClockDivision=TIM_CLOCKDIVISION_DIV1
TIM2.IPParameters=Channel-PWM Generation1 CH1,Period,AutoReloadPreload,ClockDivision,Channel-PWM Generation2 CH2
TIM2.Period=640
USART2.IPParameters=VirtualMode-Asynchronous,Mode
USART2.Mode=MODE_TX
USART2.VirtualMode-Asynchronous=VM_ASYNC
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_TIM2_VS_ClockSourceINT.Mode=Internal
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
board=custom
isbadioc=false

BIN
fancontroller.pdf View File


+ 631
- 0
fancontroller.sch View File

@@ -0,0 +1,631 @@
EESchema Schematic File Version 4
EELAYER 30 0
EELAYER END
$Descr A4 11693 8268
encoding utf-8
Sheet 1 1
Title "A PC fan controller that doesn't (completely) suck"
Date "2021-04-25"
Rev ""
Comp ""
Comment1 ""
Comment2 ""
Comment3 ""
Comment4 ""
$EndDescr
$Comp
L stm32g031f8-mcu_st_stm32g0:STM32G031F8-MCU_ST_STM32G0 U1
U 1 1 60DA6FFF
P 3400 4150
F 0 "U1" H 4450 4800 50 0000 C CNN
F 1 "STM32G031F8" H 4450 4700 50 0000 C CNN
F 2 "Package_SO:TSSOP-20_4.4x6.5mm_P0.65mm" H 3400 4150 50 0001 C CNN
F 3 "" H 3400 4150 50 0001 C CNN
1 3400 4150
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR03
U 1 1 60DA8EE8
P 3900 3500
F 0 "#PWR03" H 3900 3350 50 0001 C CNN
F 1 "+3V3" H 3915 3673 50 0000 C CNN
F 2 "" H 3900 3500 50 0001 C CNN
F 3 "" H 3900 3500 50 0001 C CNN
1 3900 3500
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR04
U 1 1 60DA975A
P 3900 5100
F 0 "#PWR04" H 3900 4850 50 0001 C CNN
F 1 "GND" H 3905 4927 50 0000 C CNN
F 2 "" H 3900 5100 50 0001 C CNN
F 3 "" H 3900 5100 50 0001 C CNN
1 3900 5100
1 0 0 -1
$EndComp
$Comp
L Device:C_Small C2
U 1 1 60DAAAE6
P 2250 4250
F 0 "C2" H 2342 4296 50 0000 L CNN
F 1 "4.7µF" H 2342 4205 50 0000 L CNN
F 2 "" H 2250 4250 50 0001 C CNN
F 3 "~" H 2250 4250 50 0001 C CNN
1 2250 4250
1 0 0 -1
$EndComp
Text GLabel 4900 3950 2 50 Input ~ 0
SWCLK
Text GLabel 4900 4050 2 50 BiDi ~ 0
SWDIO
Text GLabel 2900 4750 0 50 Input ~ 0
Rx
Text GLabel 2900 4650 0 50 Output ~ 0
Tx
Text GLabel 2900 4550 0 50 Output ~ 0
Control_Case2
Text GLabel 2900 4450 0 50 Output ~ 0
Control_Case1
$Comp
L Device:C_Small C1
U 1 1 60DAAEA6
P 2050 4250
F 0 "C1" H 1850 4300 50 0000 L CNN
F 1 "100nF" H 1700 4200 50 0000 L CNN
F 2 "" H 2050 4250 50 0001 C CNN
F 3 "~" H 2050 4250 50 0001 C CNN
1 2050 4250
1 0 0 -1
$EndComp
Wire Wire Line
3900 3500 2250 3500
Wire Wire Line
2050 3500 2050 4150
Connection ~ 3900 3500
Wire Wire Line
2050 4350 2050 5050
Wire Wire Line
2050 5050 2250 5050
Connection ~ 3900 5050
Wire Wire Line
2250 4350 2250 5050
Connection ~ 2250 5050
Wire Wire Line
2250 5050 3900 5050
Wire Wire Line
2250 4150 2250 3500
Connection ~ 2250 3500
Wire Wire Line
2250 3500 2050 3500
$Comp
L Connector_Generic:Conn_02x03_Odd_Even J1
U 1 1 60DBB72D
P 2750 3050
F 0 "J1" H 2800 3367 50 0000 C CNN
F 1 "Dbg Header" H 2800 3276 50 0000 C CNN
F 2 "" H 2750 3050 50 0001 C CNN
F 3 "~" H 2750 3050 50 0001 C CNN
1 2750 3050
1 0 0 -1
$EndComp
$Comp
L Regulator_Linear:MCP1700-3302E_TO92 U2
U 1 1 60DCAC22
P 8950 2050
F 0 "U2" H 8950 1808 50 0000 C CNN
F 1 "MCP1700-3302E" H 8950 1899 50 0000 C CNN
F 2 "Package_TO_SOT_THT:TO-92_Inline" H 8950 1850 50 0001 C CIN
F 3 "http://ww1.microchip.com/downloads/en/DeviceDoc/20001826D.pdf" H 8950 2050 50 0001 C CNN
1 8950 2050
-1 0 0 1
$EndComp
$Comp
L power:+5V #PWR022
U 1 1 60DCF9FC
P 9450 2050
F 0 "#PWR022" H 9450 1900 50 0001 C CNN
F 1 "+5V" H 9465 2223 50 0000 C CNN
F 2 "" H 9450 2050 50 0001 C CNN
F 3 "" H 9450 2050 50 0001 C CNN
1 9450 2050
1 0 0 -1
$EndComp
Wire Wire Line
9450 2050 9250 2050
$Comp
L power:+3V3 #PWR018
U 1 1 60DD0622
P 8450 2050
F 0 "#PWR018" H 8450 1900 50 0001 C CNN
F 1 "+3V3" H 8465 2223 50 0000 C CNN
F 2 "" H 8450 2050 50 0001 C CNN
F 3 "" H 8450 2050 50 0001 C CNN
1 8450 2050
1 0 0 -1
$EndComp
Wire Wire Line
8650 2050 8450 2050
$Comp
L power:GND #PWR021
U 1 1 60DD390D
P 8950 2350
F 0 "#PWR021" H 8950 2100 50 0001 C CNN
F 1 "GND" H 8955 2177 50 0000 C CNN
F 2 "" H 8950 2350 50 0001 C CNN
F 3 "" H 8950 2350 50 0001 C CNN
1 8950 2350
1 0 0 -1
$EndComp
NoConn ~ 2900 3850
NoConn ~ 2900 3950
NoConn ~ 2900 4050
NoConn ~ 2900 4350
NoConn ~ 4900 4150
NoConn ~ 4900 4250
NoConn ~ 4900 4350
Text GLabel 3050 3050 2 50 BiDi ~ 0
SWDIO
Text GLabel 2550 3050 0 50 Input ~ 0
SWCLK
$Comp
L power:+3V3 #PWR01
U 1 1 60E6284A
P 2400 2950
F 0 "#PWR01" H 2400 2800 50 0001 C CNN
F 1 "+3V3" H 2415 3123 50 0000 C CNN
F 2 "" H 2400 2950 50 0001 C CNN
F 3 "" H 2400 2950 50 0001 C CNN
1 2400 2950
1 0 0 -1
$EndComp
Text GLabel 3050 3150 2 50 Input ~ 0
Rx
Text GLabel 2550 3150 0 50 Output ~ 0
Tx
Wire Wire Line
2400 2950 2550 2950
$Comp
L power:GND #PWR02
U 1 1 60E7DBF6
P 3550 2950
F 0 "#PWR02" H 3550 2700 50 0001 C CNN
F 1 "GND" H 3555 2777 50 0000 C CNN
F 2 "" H 3550 2950 50 0001 C CNN
F 3 "" H 3550 2950 50 0001 C CNN
1 3550 2950
1 0 0 -1
$EndComp
Wire Wire Line
3050 2950 3550 2950
Text GLabel 4900 4450 2 50 Input ~ 0
Tach_GPU
Text GLabel 4900 4550 2 50 Input ~ 0
Tach_CPU
Text GLabel 4900 4650 2 50 Input ~ 0
Tach_Case2
Text GLabel 4900 4750 2 50 Input ~ 0
Tach_Case1
$Comp
L Device:R_Small R1
U 1 1 60EE221B
P 5400 4000
F 0 "R1" H 5459 4046 50 0000 L CNN
F 1 "internal" H 5459 3955 50 0000 L CNN
F 2 "" H 5400 4000 50 0001 C CNN
F 3 "~" H 5400 4000 50 0001 C CNN
1 5400 4000
1 0 0 -1
$EndComp
Wire Wire Line
4900 3850 5400 3850
$Comp
L power:GND #PWR05
U 1 1 60EE38A0
P 5400 4100
F 0 "#PWR05" H 5400 3850 50 0001 C CNN
F 1 "GND" H 5405 3927 50 0000 C CNN
F 2 "" H 5400 4100 50 0001 C CNN
F 3 "" H 5400 4100 50 0001 C CNN
1 5400 4100
1 0 0 -1
$EndComp
Connection ~ 5400 3850
$Comp
L Jumper:Jumper_2_Bridged JP1
U 1 1 60EF0FB5
P 5400 3550
F 0 "JP1" H 5400 3745 50 0000 C CNN
F 1 "Jumper" H 5400 3654 50 0000 C CNN
F 2 "" H 5400 3550 50 0001 C CNN
F 3 "~" H 5400 3550 50 0001 C CNN
1 5400 3550
0 -1 -1 0
$EndComp
$Comp
L power:+3V3 #PWR06
U 1 1 60EF4753
P 5400 3250
F 0 "#PWR06" H 5400 3100 50 0001 C CNN
F 1 "+3V3" H 5415 3423 50 0000 C CNN
F 2 "" H 5400 3250 50 0001 C CNN
F 3 "" H 5400 3250 50 0001 C CNN
1 5400 3250
1 0 0 -1
$EndComp
Wire Wire Line
5400 3850 5400 3900
$Comp
L Connector_Generic:Conn_01x04 J6
U 1 1 60D8ABE0
P 7900 4850
F 0 "J6" H 7850 4400 50 0000 L CNN
F 1 "Case Fan 1" H 7700 4500 50 0000 L CNN
F 2 "" H 7900 4850 50 0001 C CNN
F 3 "~" H 7900 4850 50 0001 C CNN
1 7900 4850
-1 0 0 1
$EndComp
$Comp
L Connector_Generic:Conn_01x02 J2
U 1 1 60D8ABF5
P 6300 3850
F 0 "J2" H 6300 3500 50 0000 C CNN
F 1 "GPU In" H 6300 3600 50 0000 C CNN
F 2 "" H 6300 3850 50 0001 C CNN
F 3 "~" H 6300 3850 50 0001 C CNN
1 6300 3850
-1 0 0 1
$EndComp
Text GLabel 8100 4650 2 50 Input ~ 0
Control_Case1
$Comp
L Device:R_Small R5
U 1 1 60DA6930
P 9000 4550
F 0 "R5" H 9059 4596 50 0000 L CNN
F 1 "10k" H 9059 4505 50 0000 L CNN
F 2 "" H 9000 4550 50 0001 C CNN
F 3 "~" H 9000 4550 50 0001 C CNN
1 9000 4550
1 0 0 -1
$EndComp
Wire Wire Line
8100 4750 9000 4750
$Comp
L power:+3V3 #PWR020
U 1 1 60DA9398
P 9000 4450
F 0 "#PWR020" H 9000 4300 50 0001 C CNN
F 1 "+3V3" H 9015 4623 50 0000 C CNN
F 2 "" H 9000 4450 50 0001 C CNN
F 3 "" H 9000 4450 50 0001 C CNN
1 9000 4450
1 0 0 -1
$EndComp
$Comp
L Device:C_Small C3
U 1 1 60DAB1BE
P 6850 4950
F 0 "C3" H 6758 4904 50 0000 R CNN
F 1 "15nF" H 6758 4995 50 0000 R CNN
F 2 "" H 6850 4950 50 0001 C CNN
F 3 "~" H 6850 4950 50 0001 C CNN
1 6850 4950
-1 0 0 1
$EndComp
Wire Wire Line
9000 4650 9000 4750
Connection ~ 9000 4750
Text GLabel 9300 4750 2 50 Output ~ 0
Tach_Case1
$Comp
L Device:D_Small D2
U 1 1 60DBBBC9
P 8200 4950
F 0 "D2" H 8200 5157 50 0000 C CNN
F 1 "1N4148" H 8200 5066 50 0000 C CNN
F 2 "" V 8200 4950 50 0001 C CNN
F 3 "~" V 8200 4950 50 0001 C CNN
1 8200 4950
-1 0 0 1
$EndComp
$Comp
L power:GND #PWR015
U 1 1 60DBCEF7
P 8500 5000
F 0 "#PWR015" H 8500 4750 50 0001 C CNN
F 1 "GND" H 8505 4827 50 0000 C CNN
F 2 "" H 8500 5000 50 0001 C CNN
F 3 "" H 8500 5000 50 0001 C CNN
1 8500 5000
1 0 0 -1
$EndComp
$Comp
L power:+12V #PWR017
U 1 1 60DC51B1
P 8750 4450
F 0 "#PWR017" H 8750 4300 50 0001 C CNN
F 1 "+12V" H 8765 4623 50 0000 C CNN
F 2 "" H 8750 4450 50 0001 C CNN
F 3 "" H 8750 4450 50 0001 C CNN
1 8750 4450
1 0 0 -1
$EndComp
Wire Wire Line
8100 4850 8750 4850
Wire Wire Line
8750 4850 8750 4450
Wire Wire Line
8300 4950 8500 4950
Wire Wire Line
9000 4750 9300 4750
$Comp
L Connector_Generic:Conn_01x04 J5
U 1 1 60DE61A0
P 7900 3750
F 0 "J5" H 7850 3300 50 0000 L CNN
F 1 "Case Fan 2" H 7700 3400 50 0000 L CNN
F 2 "" H 7900 3750 50 0001 C CNN
F 3 "~" H 7900 3750 50 0001 C CNN
1 7900 3750
-1 0 0 1
$EndComp
Text GLabel 8100 3550 2 50 Input ~ 0
Control_Case2
$Comp
L Device:R_Small R4
U 1 1 60DE61A7
P 9000 3450
F 0 "R4" H 9059 3496 50 0000 L CNN
F 1 "10k" H 9059 3405 50 0000 L CNN
F 2 "" H 9000 3450 50 0001 C CNN
F 3 "~" H 9000 3450 50 0001 C CNN
1 9000 3450
1 0 0 -1
$EndComp
Wire Wire Line
8100 3650 9000 3650
$Comp
L power:+3V3 #PWR019
U 1 1 60DE61AE
P 9000 3350
F 0 "#PWR019" H 9000 3200 50 0001 C CNN
F 1 "+3V3" H 9015 3523 50 0000 C CNN
F 2 "" H 9000 3350 50 0001 C CNN
F 3 "" H 9000 3350 50 0001 C CNN
1 9000 3350
1 0 0 -1
$EndComp
$Comp
L Device:C_Small C4
U 1 1 60DE61B4
P 9000 3750
F 0 "C4" H 8908 3704 50 0000 R CNN
F 1 "15nF" H 8908 3795 50 0000 R CNN
F 2 "" H 9000 3750 50 0001 C CNN
F 3 "~" H 9000 3750 50 0001 C CNN
1 9000 3750
-1 0 0 1
$EndComp
Wire Wire Line
9000 3550 9000 3650
Connection ~ 9000 3650
Text GLabel 9300 3650 2 50 Output ~ 0
Tach_Case2
$Comp
L Device:D_Small D1
U 1 1 60DE61BD
P 8200 3850
F 0 "D1" H 8200 4057 50 0000 C CNN
F 1 "1N4148" H 8200 3966 50 0000 C CNN
F 2 "" V 8200 3850 50 0001 C CNN
F 3 "~" V 8200 3850 50 0001 C CNN
1 8200 3850
-1 0 0 1
$EndComp
$Comp
L power:GND #PWR014
U 1 1 60DE61C3
P 8500 3900
F 0 "#PWR014" H 8500 3650 50 0001 C CNN
F 1 "GND" H 8505 3727 50 0000 C CNN
F 2 "" H 8500 3900 50 0001 C CNN
F 3 "" H 8500 3900 50 0001 C CNN
1 8500 3900
1 0 0 -1
$EndComp
$Comp
L power:+12V #PWR016
U 1 1 60DE61C9
P 8750 3350
F 0 "#PWR016" H 8750 3200 50 0001 C CNN
F 1 "+12V" H 8765 3523 50 0000 C CNN
F 2 "" H 8750 3350 50 0001 C CNN
F 3 "" H 8750 3350 50 0001 C CNN
1 8750 3350
1 0 0 -1
$EndComp
Wire Wire Line
8100 3750 8750 3750
Wire Wire Line
8750 3750 8750 3350
Wire Wire Line
8300 3850 8500 3850
Wire Wire Line
8500 3850 9000 3850
Connection ~ 8500 3850
Wire Wire Line
9000 3650 9300 3650
Wire Wire Line
8500 4950 8500 5000
Wire Wire Line
8500 3850 8500 3900
$Comp
L Device:R_Small R2
U 1 1 60E31FC0
P 6850 3550
F 0 "R2" H 6909 3596 50 0000 L CNN
F 1 "10k" H 6909 3505 50 0000 L CNN
F 2 "" H 6850 3550 50 0001 C CNN
F 3 "~" H 6850 3550 50 0001 C CNN
1 6850 3550
1 0 0 -1
$EndComp
$Comp
L power:+3V3 #PWR09
U 1 1 60E34A71
P 6850 3450
F 0 "#PWR09" H 6850 3300 50 0001 C CNN
F 1 "+3V3" H 6865 3623 50 0000 C CNN
F 2 "" H 6850 3450 50 0001 C CNN
F 3 "" H 6850 3450 50 0001 C CNN
1 6850 3450
1 0 0 -1
$EndComp
Text GLabel 7100 3750 2 50 Output ~ 0
Tach_GPU
$Comp
L Device:R_Small R3
U 1 1 60E4EEDF
P 6850 4650
F 0 "R3" H 6909 4696 50 0000 L CNN
F 1 "10k" H 6909 4605 50 0000 L CNN
F 2 "" H 6850 4650 50 0001 C CNN
F 3 "~" H 6850 4650 50 0001 C CNN
1 6850 4650
1 0 0 -1
$EndComp
Wire Wire Line
6500 4850 6850 4850
$Comp
L power:+3V3 #PWR010
U 1 1 60E4EEE6
P 6850 4550
F 0 "#PWR010" H 6850 4400 50 0001 C CNN
F 1 "+3V3" H 6865 4723 50 0000 C CNN
F 2 "" H 6850 4550 50 0001 C CNN
F 3 "" H 6850 4550 50 0001 C CNN
1 6850 4550
1 0 0 -1
$EndComp
Text GLabel 7100 4850 2 50 Output ~ 0
Tach_CPU
Wire Wire Line
6850 4850 7100 4850
Connection ~ 6850 4850
$Comp
L Connector_Generic:Conn_01x02 J3
U 1 1 60E4EED9
P 6300 4950
F 0 "J3" H 6300 4600 50 0000 C CNN
F 1 "CPU In" H 6300 4700 50 0000 C CNN
F 2 "" H 6300 4950 50 0001 C CNN
F 3 "~" H 6300 4950 50 0001 C CNN
1 6300 4950
-1 0 0 1
$EndComp
$Comp
L power:GND #PWR08
U 1 1 60E4EEEF
P 6500 5050
F 0 "#PWR08" H 6500 4800 50 0001 C CNN
F 1 "GND" H 6505 4877 50 0000 C CNN
F 2 "" H 6500 5050 50 0001 C CNN
F 3 "" H 6500 5050 50 0001 C CNN
1 6500 5050
1 0 0 -1
$EndComp
Wire Wire Line
6500 3850 6500 3900
$Comp
L power:GND #PWR07
U 1 1 60E42A45
P 6500 3900
F 0 "#PWR07" H 6500 3650 50 0001 C CNN
F 1 "GND" H 6505 3727 50 0000 C CNN
F 2 "" H 6500 3900 50 0001 C CNN
F 3 "" H 6500 3900 50 0001 C CNN
1 6500 3900
1 0 0 -1
$EndComp
Wire Wire Line
6850 5050 6500 5050
Wire Wire Line
6850 4750 6850 4850
Wire Wire Line
6500 3750 6850 3750
Wire Wire Line
6850 3650 6850 3750
Connection ~ 6850 3750
Wire Wire Line
6850 3750 7100 3750
$Comp
L Connector_Generic:Conn_01x04 J4
U 1 1 60DB3615
P 7450 2200
F 0 "J4" H 7700 2100 50 0000 C CNN
F 1 "Power In" H 7550 2200 50 0000 L CNN
F 2 "" H 7450 2200 50 0001 C CNN
F 3 "~" H 7450 2200 50 0001 C CNN
1 7450 2200
-1 0 0 1
$EndComp
$Comp
L power:+12V #PWR013
U 1 1 60DB43E7
P 8000 2300
F 0 "#PWR013" H 8000 2150 50 0001 C CNN
F 1 "+12V" H 8015 2473 50 0000 C CNN
F 2 "" H 8000 2300 50 0001 C CNN
F 3 "" H 8000 2300 50 0001 C CNN
1 8000 2300
1 0 0 -1
$EndComp
Wire Wire Line
7650 2300 8000 2300
$Comp
L power:+5V #PWR012
U 1 1 60DB5C23
P 8000 2000
F 0 "#PWR012" H 8000 1850 50 0001 C CNN
F 1 "+5V" H 8015 2173 50 0000 C CNN
F 2 "" H 8000 2000 50 0001 C CNN
F 3 "" H 8000 2000 50 0001 C CNN
1 8000 2000
1 0 0 -1
$EndComp
Wire Wire Line
7650 2000 8000 2000
$Comp
L power:GND #PWR011
U 1 1 60DB744F
P 7700 2400
F 0 "#PWR011" H 7700 2150 50 0001 C CNN
F 1 "GND" H 7705 2227 50 0000 C CNN
F 2 "" H 7700 2400 50 0001 C CNN
F 3 "" H 7700 2400 50 0001 C CNN
1 7700 2400
1 0 0 -1
$EndComp
Wire Wire Line
7650 2100 7700 2100
Wire Wire Line
7700 2100 7700 2200
Wire Wire Line
7650 2200 7700 2200
Connection ~ 7700 2200
Wire Wire Line
7700 2200 7700 2400
Wire Wire Line
6500 4950 6500 5050
Connection ~ 6500 5050
Wire Wire Line
5400 3750 5400 3850
Wire Wire Line
5400 3250 5400 3350
Wire Wire Line
3900 5050 3900 5100
$EndSCHEMATC

+ 467
- 0
main.c View File

@@ -0,0 +1,467 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "string.h"
#include "stdio.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define TIMEBASE 1000
#define PWM_MINIMUM 20
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
TIM_HandleTypeDef htim2;
UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
const uint16_t GPU_STAGES[] = {900, 1400, 1800, 2200};
const uint16_t CPU_STAGES[] = {850, 900, 1000, 1200};
uint32_t freq_count_gpu;
uint32_t freq_count_cpu;
uint32_t freq_count_case1;
uint32_t freq_count_case2;
uint32_t last_gpu;
uint32_t last_cpu;
uint32_t last_case1;
uint32_t last_case2;
uint16_t rpm_gpu;
uint16_t rpm_cpu;
uint16_t rpm_case1;
uint16_t rpm_case2;
uint32_t pwm_fan1;
uint32_t pwm_fan2;
uint8_t gpu_stage;
uint8_t cpu_stage;
uint8_t current_stage;
char msg[256];
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_TIM2_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
int max(uint8_t a, uint8_t b) {
if (a > b) {
return a;
}
return b;
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM2_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if (HAL_GPIO_ReadPin(Switch_GPIO_Port, Switch_Pin) == GPIO_PIN_SET) {
// do stuff
}
if (rpm_gpu < GPU_STAGES[0]) {
gpu_stage = 1;
} else if (rpm_gpu < GPU_STAGES[1]) {
gpu_stage = 2;
} else if (rpm_gpu < GPU_STAGES[2]) {
gpu_stage = 3;
} else if (rpm_gpu < GPU_STAGES[3]) {
gpu_stage = 4;
} else {
gpu_stage = 5;
}
if (rpm_cpu < CPU_STAGES[0]) {
cpu_stage = 1;
} else if (rpm_cpu < CPU_STAGES[1]) {
cpu_stage = 2;
} else if (rpm_cpu < CPU_STAGES[2]) {
cpu_stage = 3;
} else if (rpm_cpu < CPU_STAGES[3]) {
cpu_stage = 4;
} else {
cpu_stage = 5;
}
current_stage = max(gpu_stage, cpu_stage);
if (current_stage == 1) {
pwm_fan1 = PWM_MINIMUM;
} else if (current_stage == 2) {
pwm_fan1 = 35;
} else if (current_stage == 3) {
pwm_fan1 = 50;
} else if (current_stage == 4) {
pwm_fan1 = 80;
} else {
pwm_fan1 = 100;
}
// For now
pwm_fan2 = pwm_fan1;
// Write the value after converting from duty cycle to raw value.
TIM2->CCR1 = htim2.Init.Period * pwm_fan1 / 100;
TIM2->CCR2 = htim2.Init.Period * pwm_fan2 / 100;
// If the fans don't spin, the rpm won't be updated as no
// interrupts are called. This resets those values every two seconds.
if (HAL_GetTick() - last_gpu >= TIMEBASE * 2) {
rpm_gpu = 0;
freq_count_gpu = 0;
}
if (HAL_GetTick() - last_cpu >= TIMEBASE * 2) {
rpm_cpu = 0;
freq_count_cpu = 0;
}
if (HAL_GetTick() - last_case1 >= TIMEBASE * 2) {
rpm_case1 = 0;
freq_count_case1 = 0;
}
if (HAL_GetTick() - last_case2 >= TIMEBASE * 2) {
rpm_case2 = 0;
freq_count_case2 = 0;
}
sprintf(msg, "GPU: %u RPM\nCPU: %u RPM\nCase 1: %u RPM\nCase2: %u RPM\n", rpm_gpu, rpm_cpu, rpm_case1, rpm_case2);
HAL_UART_Transmit(&huart2, (uint8_t *) msg, strlen(msg), 100);
sprintf(msg, "PWM Case 1: %lu %%\nPWM Case 2: %lu %%\n\n", pwm_fan1, pwm_fan2);
HAL_UART_Transmit(&huart2, (uint8_t *) msg, strlen(msg), 100);
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
{
Error_Handler();
}
}
/**
* @brief TIM2 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM2_Init(void)
{
/* USER CODE BEGIN TIM2_Init 0 */
/* USER CODE END TIM2_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2;
htim2.Init.Prescaler = 0;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 640;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 0;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
HAL_TIM_MspPostInit(&htim2);
}
/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
static void MX_USART2_UART_Init(void)
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pins : Case1_Pin Case2_Pin CPU_Pin GPU_Pin */
GPIO_InitStruct.Pin = Case1_Pin|Case2_Pin|CPU_Pin|GPU_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : Switch_Pin */
GPIO_InitStruct.Pin = Switch_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
HAL_GPIO_Init(Switch_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
}
/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == GPU_Pin) {
if ((HAL_GetTick() - last_gpu) <= TIMEBASE) {
freq_count_gpu++;
} else {
rpm_gpu = freq_count_gpu * 60 / 2;
last_gpu = HAL_GetTick();
freq_count_gpu = 0;
}
}
if (GPIO_Pin == CPU_Pin) {
if ((HAL_GetTick() - last_cpu) <= TIMEBASE) {
freq_count_cpu++;
} else {
rpm_cpu = freq_count_cpu * 60 / 2;
last_cpu = HAL_GetTick();
freq_count_cpu = 0;
}
}
if (GPIO_Pin == Case1_Pin) {
if ((HAL_GetTick() - last_case1) <= TIMEBASE) {
freq_count_case1++;
} else {
rpm_case1 = freq_count_case1 * 60 / 2;
last_case1 = HAL_GetTick();
freq_count_case1 = 0;
}
}
if (GPIO_Pin == Case2_Pin) {
if ((HAL_GetTick() - last_case2) <= TIMEBASE) {
freq_count_case2++;
} else {
rpm_case2 = freq_count_case2 * 60 / 2;
last_case2 = HAL_GetTick();
freq_count_case2 = 0;
}
}
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

+ 87
- 0
main.h View File

@@ -0,0 +1,87 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32g0xx_hal.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define Case1_Pin GPIO_PIN_4
#define Case1_GPIO_Port GPIOA
#define Case1_EXTI_IRQn EXTI4_15_IRQn
#define Case2_Pin GPIO_PIN_5
#define Case2_GPIO_Port GPIOA
#define Case2_EXTI_IRQn EXTI4_15_IRQn
#define CPU_Pin GPIO_PIN_6
#define CPU_GPIO_Port GPIOA
#define CPU_EXTI_IRQn EXTI4_15_IRQn
#define GPU_Pin GPIO_PIN_7
#define GPU_GPIO_Port GPIOA
#define GPU_EXTI_IRQn EXTI4_15_IRQn
#define Switch_Pin GPIO_PIN_6
#define Switch_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Loading…
Cancel
Save