Ok I got nowhere with that POT command, so jump in the deep end and try using ADC.
I've used a 12F675 with the following code. As I've never used ADC before and still find datasheets confusing I just cut and pasted examples from the PBP manual for ADC.
Code:
@ __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON
TRISIO.2 = 0 'Set GPIO.2 to output.
ANSEL.2 = 0 'Set GPIO.2 to digital
GPIO.0 = 1 'gpio.0 set to input
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
led var GPIO.2
i var byte
D var byte
main:
ADCIN 0, D
Pwm GPIO.2,D,1
goto main
To my suprise, the code compiled and works, well sort off !
using a 10K pot connected between +5v and GND with the wiper connected to GPIO 0, my DVM reads between +0.14v and +5 on GPIO 2 when the pot is turned through its range - connecting an LED to GPIO 2 confirms that something is working as its brightness can be controlled via the POT... so far so good
I then tested the FET by connecting a 10K pot between gnd and +5v with the wiper going to the gate, the track between +12v and FET and the FET to GND. Adjusting the pot produced some degree of control over a loco... so I moved the link from the pots wiper and connected it to GPIO 2. However the DVM reads the same vdd of the 12v rail regardless of the setting of the POT.
I can only assume that its something to do with the PWM output from the PIC that is turning on the FET continiously ?? anyone have any suggestions ?? Can a PIC have DAC so I could convert the resulting digital value to a voltage that would be used to drive the FET (or whatever output stage I use).
I want to stick with a PIC for the control as it would be easier to use simple for next loops / or counters for programmable stops, acceleration, etc
Comments welcome as always
Bookmarks