Alain,
One step ahead of you... I'm using a 16F828a and set up a 100K lin pot and 0.1uf capacitor, and a simple bit of code.. but can't get it to work (just slung it together in the past 5 mins)
The code compiles, but I don't get any PWM on the output (using a LED for test purposes at the moment - no FET connected.)
10k between MCLR and +5v, input from the pot to A2
Here's the code
Code:
;************ set up PIC *****************
PORTA = 0 ' declare port level BEFORE port direction = safe power-on
CMCON = 7 ' PortA Digital inputs
CCP1CON = 0 ' PWM off
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0
TRISA=%11101111 'set PORTA as all input apart from A4
TRISB=%00000000 'set PORTB as all output
@RC_OSC_NOCLKOUT
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF
;************* set up varibles ************
D var byte ;used to store the result of the pot on port A2
scale var byte ;used in the POT command
Scale = 254 ;used to set range
;************* main program ****************
Main:
Pot PORTA.2,scale,D ;used to read value from pot
pwm PORTB.4,D,1
Goto main
The main loop is self explanatory, port A2 is checked and the result is placed in the variable D, this is used to set the width of the PWM sent out on pin B4
Any ideas why I can't get it to work
Bookmarks