Quote Originally Posted by sayzer View Post
For PICs that have onboard PWM modules, like 628, CCP DEFINEs are not required.


Reading POT value and using it to drive a motor, try the following demo code.


Code:
@ DEVICE PIC16F628, INTRC_OSC_NOCLKOUT
@ DEVICE PIC16F628, MCLR_OFF
@ DEVICE PIC16F628, WDT_OFF
@ DEVICE PIC16F628, PROTECT_OFF
@ DEVICE PIC16F628, BOD_OFF
@ DEVICE PIC16F628, CPD_OFF

TRISA = 255     'All pins are input.
TRISB = 0       'All pins are output.

'=====Timer2 settings  - 8Bit ====================
T2CON = %00000000      ' Required for accurate timing for RPM.
INTCON.7 = 0           ' Disable interrupts.

'===================PWM Part===============
CMCON     = 7          ' PortA = digital I/O
VRCON     = 0          ' Disable A/D Voltage reference.
PR2       = 255        ' PWM frequency.
CCP1CON   = %00001100  ' PWM Mode selected.
T2CON     = %00000100  ' Timer2 ON + 1:1 prescale
CCPR1L    = 0          ' Set PWM Duty-Cycle

PotPin VAR PORTB.0

Begin:

    POT PotPin , 255, CCPR1L         'Read Pot value and put on PWM Module. From 0 to 255. From zero to full speed.
    '... have your switch readings here.
    '......
    '........
    
    
    
    
    Goto Begin


END
hi Sayzer;
looking at your really cool sample code i think instead of
"PotPin VAR PORTB.0"

should be
"PotPin VAR PORTA.0"
because as PIC's datasheet says, analog inputs are only in PORTA, and also you configured PORTA as inputs and PORTB as outputs.


anyway i found that your POT & CCPR1L line is amazing !