A couple things to watch out for.
1.
Place ADCON1 = %01001110 in the init section of your code. Now only RA0
is configured as an analog input, and the rest can be used for digital I/O.
Some pins you're trying to use as digital outputs are still configired as analog
inputs. ADCON1 = 0 sets them "all" to analog inputs.
2.
You need a different A/D conversion clock if you're running at 8MHz. With
ADCON1.6 = 1 this sets the conversion clock to 16 which is what you need
for any osc over 5MHz up to 10MHz MAX. See the data sheet table Tad vs.
max device operating frequency.
3.
If you're using RA0 for the A/D input, and RA5 is input only, you're never
going to see from 0 to 255 output on your LED's on porta. You could use all
of portb for the LED's and output your pulse on one of the porta pins like RA1,
2,3,4,6 or 7.
4.
PULSOUT toggles the pin twice, so the initial state of the pin used determines
the polarity of your pulse. If you want a high-going pulse, then clear the pin
you're using first. Just above TRISB = %00000000 place PORTB = %00000000.
PULSOUT resolution at 8MHz is 5uS. Assuming your A/D reading is from 0-255,
your MAX servo pulse can only be 5uS x 255 = 1.275mS.
You could use pulsout PORTB.0, potential*2 to compensate. That increases
your pulse out to ((255*2)*5uS) = 2.55mS MAX. Your servo should move full
range in both directions. You may want to add a short delay just after your
PULSOUT to get somewhere between 50-60Hz update rates.
Bookmarks