#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;
PWM_Init(5000); //5khz pwm
PWM_Change_Duty(medium); //50% duty cycle
PWM_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;
}
PWM_Change_Duty(duty); //Change duty cycle and adjust
delay_ms(100); //Wait for adjusting (Optional and may be left out)
}
}
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?