Hi...I need some helps here...once again,i will post my Pic Basic Pro Code below,hopefully somebody will help me fixed my code, bcoz i just cant get the result that i want...

The Code:

include "modedefs.bas"
DEFINE OSC 4

' Define ADCIN parameters
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

B0 var BYTE ' Create B0 to store result

TRISB = %10000000 ' set output for led portb.0
TRISC = %11111000 ' set output for pwm portc.2
TRISA = %111111 ' Set PORTA to all input

CCP1CON = %00001100 ' Set CCP1 to PWM
ADCON1 = 0 ' for 10-bit ADC and Set all PORTA is analog

HIGH PORTB.0

GOSUB GETMBAT 'read voltage variable
main:

ADCIN 0,B0 ' Read channel 0 to B0
B0 = B0 >> 3 'justify data

if (B0>0) and (B0<5) THEN
PWM PORTC.1,10,100
endif
if (B0>5) and (B0<10) THEN
PWM PORTC.1,30,100
endif
if (B0>10) and (B0<15) THEN
PWM PORTC.1,60,100
endif
IF (B0>15) AND (B0<20) THEN
PWM PORTC.1,100,100
endif
IF (B0>20) AND (B0<25) THEN
PWM PORTC.1,127,100
endif
IF (B0>25) AND (B0<28) THEN
PWM PORTC.1,160,100
endif
IF (B0>28) AND (B0<30) THEN
PWM PORTC.1,200,100
endif
if (B0>30) and (B0<32) then
PWM PORTC.1,254,100
endif

GOTO main

GETRESULT:
PAUSEUS 50 'WAIT FOR ADC SETUP
ADCON0.2 = 1 'START CONVERSION BY SETING GO/DONE BIT HIGH

LOOP: ' WAIT FOR GO/DONE BIT TO CLEAR
IF ADCON0.2 = 1 THEN
GOTO loop
ENdif
goto main


GETMBAT:
ADCON0 =%00000101 'SET A/D Fosc/32, [4MHz], CHANNEL-0 = ON
GOSUB GETRESULT 'START CONVERSION
B0 = ADRES 'STORE THE A/D CONVERSION VALUE IN RESULT
RETURN


The PIC that I am using is PIC 16F874A, and i am trying use a 10k potentiometer to control the motor speed (increase or decrease the speed). Thus, I try the HPWM before, just cant get the result also.

Hopefully, somebody will help me...thanks u