Tahmid
Advanced Member level 6
- Joined
- Jun 17, 2008
- Messages
- 4,764
- Helped
- 1,799
- Reputation
- 3,590
- Reaction score
- 1,663
- Trophy points
- 1,413
- Location
- Berkeley, California
- Activity points
- 30,734
#define slow 32 //Duty cycle set for slow
#define medium 96 //Duty cycle set for medium
#define fast 230 //Duty cycle for fast
#define cel20 41 //20'C
#define cel50 102 //50'C
//I set range as:
//Less than 20'C : speed is slow
//From 20'C to 50'C : speed is medium
//Greater than 50'C : speed is fast
int ADVal; //Variable to store ADC result
unsigned char duty;
void main(void){
TRISC = 0;
PORTC = 0;
PWM1_Init(5000); //5khz pwm
PWM1_Set_Duty(medium); //50% duty cycle
PWM1_Start(); //Start PWM
while (1){
ADVal = ADC_Read(0);
if (ADVal < cel20){
duty = slow;
}
if ( (ADVal > cel20) & (ADVal < cel50) ){
duty = medium;
}
if (ADVal > cel50){
duty = fast;
}
PWM1_Set_Duty(duty); //Change duty cycle and adjust
delay_ms(100); //Wait for adjusting (Optional and may be left out)
}
}
program TempFanControl
'I set range as:
'Less than 20'C : speed is slow
'From 20'C to 50'C : speed is medium
'Greater than 50'C : speed is fast
dim ADVal as word 'Variable to store ADC result
dim duty as byte
const slow = 32 'Duty cycle set for slow
const medium = 96 'Duty cycle set for medium
const fast = 230 'Duty cycle for fast
const cel20 = 41 '20'C
const cel50 = 102 '50'C
main:
TRISC = 0
PORTC = 0
PWM1_Init(5000) '5khz pwm
PWM1_Set_Duty(medium) '50% duty cycle
PWM1_Start() 'Start PWM
while true
ADVal = ADC_Read(0)
if ADVal < cel20 then
duty = slow
end if
if (ADVal > cel20) and (ADVal < cel50) then
duty = medium
end if
if ADVal > cel50 then
duty = fast
end if
PWM1_Set_Duty(duty) 'Change duty cycle and adjust
delay_ms(100) 'Wait for adjusting (Optional and may be left out)
wend
end.
what to do in the code to set vref to 1v.?
- - - Updated - - -
please tell me about a good book to learn pic16877a programming, i am good in programming of 8051 but dont know about pic16f877a
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?