An 8051 Based Temperature Controlled Fan project
Thu Aug 23 2007, 11:37 pm
well this function can be implemented later on.. because this is the final interface. First you need to write drivers for your peripherals like ADC, keys, Fan and its speed control and 7-segment LED. After you finish the basic building blocks of your project.. you can easily make the final interface.. I hope you got my point. So you can first start with the simplest.. "Fan switching and speed control".
where is your schematic?
where is your schematic?
tienduhieu like this.
Fri Aug 24 2007, 06:22 pm
i maybe want add something to my circuit so i remove it first.So can u teach me how to write the code for control the fan speed in manual mode?i need write the code to control fan speed for manual and auto separately or just write 1 can d?
[ Edited Fri Aug 24 2007, 06:24 pm ]
tienduhieu like this.
Fri Aug 24 2007, 07:14 pm
ok.. i tell you something.. controlling via manual or auto is the later part of your project it will be according to the keys user press.. that is the interface part. But basically you need to write for controlling and switching of FAN first.
And yes i will help you writing it..
So as i told you about PWM, you need a timer (either Timer 0 or Timer 1). and we need to load the timer for 2 different values, One for ON timer and one for OFF time (as explained for PWM square wave).
The value of ON, OFF depends on the mode selected by the user. i.e. If manual then you can have 5 preset values for user to select from and load them according to the selected value.
In automatic mode, i don't know how it suppose to work in auto mode..
So I hope you understood the basic idea.. can you make a simple code to generate a square wave? I will help you to modify it, according to your project waiting for your INPUT
And yes i will help you writing it..
So as i told you about PWM, you need a timer (either Timer 0 or Timer 1). and we need to load the timer for 2 different values, One for ON timer and one for OFF time (as explained for PWM square wave).
The value of ON, OFF depends on the mode selected by the user. i.e. If manual then you can have 5 preset values for user to select from and load them according to the selected value.
In automatic mode, i don't know how it suppose to work in auto mode..
So I hope you understood the basic idea.. can you make a simple code to generate a square wave? I will help you to modify it, according to your project waiting for your INPUT
tienduhieu, lifeflowers86 like this.
Thu Aug 30 2007, 06:07 pm
sorry for taking so long time to reply u.Do u know what software that can use to draw the circuit schematic?This is the simple code u ask me to do which can get square wave,this program is use to generate 1hz square wave by using timer 1 with duty circle 50%,deration for high low portion of square wave are 0.5 s,T=1s.
[ Edited Thu Aug 30 2007, 06:10 pm ]
tienduhieu like this.
Thu Aug 30 2007, 06:13 pm
this is my code,why i cannot attch file?i wan attach the file that contain my code but cannot so i have to type it here
ORG 0000
MOV TMOD,#10H ;TIMER 1 IN MODE 1
MAIN: MOV R0,#10 ;COUNTER FOR 10 LOOPING
REPEAT: MOV TH1,#3CH ;MOVE 3CH INTO TH0
MOV TL1,#0B0H ;MOVE B0H INTO TL0
SETB TR1 ;START THE TIMER 1
LOOP: JNB TF1,LOOP ;WAIT FOR TIMER1 OVERFLOW
CLR TR1 ;STOP TIMER 1
CLR TF1 ;CLEAR TIMER 1 OVERFLOW FLAG
DJNZ R0,REPEAT ;IF R0 NOT ZERO GO TO REPEAT
CPL P1.0 ;COMPLEMENT P1.0 TO GET HIGH OR LOW
SJMP MAIN ;RELOAD TH1&TL1
END
ORG 0000
MOV TMOD,#10H ;TIMER 1 IN MODE 1
MAIN: MOV R0,#10 ;COUNTER FOR 10 LOOPING
REPEAT: MOV TH1,#3CH ;MOVE 3CH INTO TH0
MOV TL1,#0B0H ;MOVE B0H INTO TL0
SETB TR1 ;START THE TIMER 1
LOOP: JNB TF1,LOOP ;WAIT FOR TIMER1 OVERFLOW
CLR TR1 ;STOP TIMER 1
CLR TF1 ;CLEAR TIMER 1 OVERFLOW FLAG
DJNZ R0,REPEAT ;IF R0 NOT ZERO GO TO REPEAT
CPL P1.0 ;COMPLEMENT P1.0 TO GET HIGH OR LOW
SJMP MAIN ;RELOAD TH1&TL1
END
[ Edited Thu Aug 30 2007, 06:34 pm ]
tienduhieu, lifeflowers86 like this.
Thu Aug 30 2007, 06:34 pm
ok.. but.. i wanted you to make it with timer.. for PWM, the delay should be less otherwise your motor will not run smooth.. you can try connecting an LED to the port to see that.. it will flicker a lot..
where as if you use keep delay smaller like timer in a 13-bit mode.. then you will see a variation in voltage instead of flickering..
I am attaching a sample PWM code for you.. take a look.
The above part of the code will determine the output voltage level. you can test this code.. by changing the value of R7.
where as if you use keep delay smaller like timer in a 13-bit mode.. then you will see a variation in voltage instead of flickering..
I am attaching a sample PWM code for you.. take a look.
MOV R7, #160 ; set pulse width control to dim
The above part of the code will determine the output voltage level. you can test this code.. by changing the value of R7.
tienduhieu like this.
Thu Aug 30 2007, 06:35 pm
I think there is some problem with the attachment of file.. i need to check that..
By the time.. please try to paste the code..
here is a sample PWM code.. check it..
By the time.. please try to paste the code..
here is a sample PWM code.. check it..
org 0H sjmp start org 0BH TIMER_0_INTERRUPT: JB F0, HIGH_DONE ; If F0 is set then we just finished the high section of the LOW_DONE: ; cycle so Jump to HIGH_DONE SETB F0 ; Make F0=1 to indicate start of high section SETB P1.0 ; Turn off LED MOV TH0, R7 ; Load high byte of timer with R7 (pulse width control value) CLR TF0 ; Clear the Timer 0 interrupt flag RETI ; Return from Interrupt to where the program came from HIGH_DONE: CLR F0 ; Make F0=0 to indicate start of low section CLR P1.0 ; Turn on LED MOV A, #0FFH ; Move FFH (255) to A CLR C ; Clear C (the carry bit) so it does not affect the subtraction SUBB A, R7 ; Subtract R7 from A. A = 255 - R7. MOV TH0, A ; so the value loaded into TH0 + R7 = 255 CLR TF0 ; Clear the Timer 0 interrupt flag RETI ; Return from Interrupt to where the program came from start: MOV TMOD,#00H SETB TR0 ; turn on timer 0 SETB EA ; Enable Interrupts SETB ET0 ; Enable Timer 0 Interrupt MOV R7, #160 ; set pulse width control to dim LOOP: SJMP LOOP ;go to LOOP END
[ Edited Thu Aug 30 2007, 06:38 pm ]
tienduhieu, lifeflowers86 like this.
Tags PWMpulse width modulation8051 PWM codePWM sample code
Thu Aug 30 2007, 06:38 pm
ok,thanks,but how u see the delay in my code?actually i found this code from book and modify it so i no very understand,and do u know what software that can use to draw the circuit schematic?
tienduhieu like this.
Thu Aug 30 2007, 06:43 pm
you can use orcad for making schematic.. but is not a free software... the schematic u showed me is made in protel. you can use the same software. or try some free software on internet like eagle.
tienduhieu like this.
Thu Aug 30 2007, 07:24 pm
Can u explain the function of this PWM code?why we need control output voltage level?The output voltage will affect which part of function of hardware?i not very understand,i am sorry that i only know ask question but i try to learn all this thing through doing this assignment,so i do it all by my own.
tienduhieu, lifeflowers86 like this.
Powered by e107 Forum System