Yust use the hpwm instruction and put in the define part:
DEFINE CCP1_REG PORTB
DEFINE CCP1_BIT 3
nothing else more !!
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
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
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 !
yeah but CMCON=7 disable all analog feature, there's no analog-to-digital converter on this one, and POT don't even need any analog stuff to work, it just measure the RC constant or whatever else useless/inacurate method.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Thanks.
If you like to use a PIC with on board ADC and PWM modules, like 16F877 or 12F683, then you can also use a single line as below.
Code:ADCIN 0, CCPR1L 'This will read Analog channel 0 'and put on PWM register right away.
If you like to use F628 with POT command, then make sure that the pot is not connected to "input only" pins. Pin must be a bi-directional pin.
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
good morning sayzer, mister_e,
About the PWM thing, I'm clear and OK,
but... reading your last posts I don't know if understood correctly:
-> what I understood is that I can measure the value of a potentiometer into any I/O pin without any necessary A/D conversion feature? In other words, in a 16F628A: I could use 16 potentiometers?? wow!! that would be crazyly cool!
(sorry my english)
Bookmarks