Vermes
Advanced Member level 4
- Joined
- Aug 2, 2011
- Messages
- 1,163
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,316
- Activity points
- 22,318
This simple circuit based on Atmega8 can be useful as a generator of PWM signal for example of a radiator fan driver. Potentiometer is used for smooth regulation of the fulfillment from 0 to 100%. The current setting is displayed in steps every 10% on the LED bargraph. The additional LED is connected to the signal output and it is a protection against inverse connection.
Program was written in Bascom.
Atmega works on 1MHz, with 8 bit hardware PWM with a frequency of 3,9KHz. The LED bargraph can be controlled by the case function.
The PCB was made on CNC milling machine. It was protected with solution of rosin in isopropanol. The whole was closed in housing Z67.
Pictures:
The source code:
Code:
$regfile = "m8def.dat"
$crystal = 1000000
*
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Config Timer1 = Pwm , Prescale = 1 , Pwm = 8 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Down
*
Config Portc.5 = Output : Set Portc.5 : Led0 Alias Portc.5
Config Portc.4 = Output : Set Portc.4 : Led1 Alias Portc.4
Config Portd.0 = Output : Set Portd.0 : Led2 Alias Portd.0
Config Portd.1 = Output : Set Portd.1 : Led3 Alias Portd.1
Config Portd.2 = Output : Set Portd.2 : Led4 Alias Portd.2
Config Portd.3 = Output : Set Portd.3 : Led5 Alias Portd.3
Config Portd.4 = Output : Set Portd.4 : Led6 Alias Portd.4
Config Portd.5 = Output : Set Portd.5 : Led7 Alias Portd.5
Config Portd.6 = Output : Set Portd.6 : Led8 Alias Portd.6
Config Portd.7 = Output : Set Portd.7 : Led9 Alias Portd.7
*
*
Config Portc.0 = Input
Config Portb.1 = Output
*
Dim W As Word
*
Do
*
W = Getadc(0)
W = W / 4
*
Pwm1a = W
*
Select Case W
*
Case 0:
Set Led0
Set Led1
Set Led2
Set Led3
Set Led4
Set Led5
Set Led6
Set Led7
Set Led8
Set Led9
*
Case 1 To 25:
Reset Led0
Set Led1
Set Led2
Set Led3
Set Led4
Set Led5
Set Led6
Set Led7
Set Led8
Set Led9
*
Case 26 To 50:
Reset Led0
Reset Led1
Set Led2
Set Led3
Set Led4
Set Led5
Set Led6
Set Led7
Set Led8
Set Led9
*
Case 51 To 75:
Reset Led0
Reset Led1
Reset Led2
Set Led3
Set Led4
Set Led5
Set Led6
Set Led7
Set Led8
Set Led9
*
Case 76 To 100:
Reset Led0
Reset Led1
Reset Led2
Reset Led3
Set Led4
Set Led5
Set Led6
Set Led7
Set Led8
Set Led9
*
Case 101 To 125:
Reset Led0
Reset Led1
Reset Led2
Reset Led3
Reset Led4
Set Led5
Set Led6
Set Led7
Set Led8
Set Led9
*
Case 126 To 150:
Reset Led0
Reset Led1
Reset Led2
Reset Led3
Reset Led4
Reset Led5
Set Led6
Set Led7
Set Led8
Set Led9
*
Case 151 To 175:
Reset Led0
Reset Led1
Reset Led2
Reset Led3
Reset Led4
Reset Led5
Reset Led6
Set Led7
Set Led8
Set Led9
*
Case 176 To 200:
Reset Led0
Reset Led1
Reset Led2
Reset Led3
Reset Led4
Reset Led5
Reset Led6
Reset Led7
Set Led8
Set Led9
*
Case 201 To 225:
Reset Led0
Reset Led1
Reset Led2
Reset Led3
Reset Led4
Reset Led5
Reset Led6
Reset Led7
Reset Led8
Set Led9
*
Case 226 To 256:
Reset Led0
Reset Led1
Reset Led2
Reset Led3
Reset Led4
Reset Led5
Reset Led6
Reset Led7
Reset Led8
Reset Led9
*
*
End Select
*
Waitms 20
Loop
*
End
*
And a video of milling the PCB and operation of the device:
Link to original thread (useful attachment) - Generator PWM na Atmega8 z linijką LED