
Originally Posted by
mat janssen
Yust use the hpwm instruction and put in the define part:
DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 3
nothing else more !!
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
Bookmarks