HiHi,yaya, thanks u againOriginally Posted by markedwards
i got few problem here:
for the code above, I cannot compile this part: The code:
IF SPEED > SPD THEN SPD = SPD + 1 'accelerate
IF SPEED < SPD THEN SPD = SPD - 1 'de-accelerate
the error message is mismatching if loop..then...endif. Thus, i dunno how to fixed it. Thus, here is my code, hopefully you can help me a bit, thanks ya
INCLUDE "modedefs.bas"
DEFINE OSC 4
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 10 ' Set sampling time in microseconds
AD1 var byte
SPEED var byte
SPD var byte
TRISB = %10000000 ' set output for led portb.0
TRISC = %11111000 ' set output for pwm portc.2
TRISA = %111111 ' Set PORTA to all input
ADCON1 = 0 ' for 10-bit ADC and Set all PORTA is analog
ADCON0 =%10000101 'SET A/D Fosc/32, [4MHz], CHANNEL-0 = ON
main:
ADCIN 0,AD1 'read chanel 1...AN1
AD1 = AD1 >> 6 'justify data
gosub ADJUSTFAN
hpwm 2,SPD,300 ' PWM 20,000 Hz
IF SPEED > SPD THEN goto acce
endif
if speed <= SPD then goto deacce
endif
ADJUSTFAN:
IF AD1 < 2 then
SPEED = 153
endif '60% min speed
IF AD1 >= 3 then
SPEED = 178
endif '70%
IF AD1 >= 5 then
SPEED = 204
endif '80%
IF AD1 >= 7 then
SPEED = 229
endif '90%
IF AD1 >= 9 then
SPEED = 255
endif '100%
return
acce: SPD = SPD + 1 'accelerate
hpwm 2,SPD,300
return
deacce: SPD = SPD - 1 'de-accelerate
hpwm 2,SPD,300
return
P/s : The code above is Pic Basic Pro code...
Another problem is how do I get the ADC scaling. Actually, what is ADC scaling mean?? If I wanna do the ADC scaling from 1-32, so how to write in pic basic code? Is it neccessary to iniatiate first, the 1-32 values?
Thanks u,cheers
Regards
Mengckid






Bookmarks