PIC18F ADC, PWM and Interrupts

Status
Not open for further replies.

noelcharles

New Member
Hi,
I am using a PIC18F1330 as a DC servo controller, and writing the code in assembler. It requires 2 analog inputs and produce a single PWM output, and a direction output.

The AD module is functioning, although the results are erratic. With Vdd as Vref, the result won't read less than 0164h and only reads above this when the input is very close to Vdd.

The PWM output is also functioning, but I cannot change the frequency or duty cycle - it is fixed at 50%.

I can get interrupts to operate, but only at the rate dictated by the selected prescaler, not at a specific rate.

Any help with initialisation values or code snippets that work, would be greatly appreciated.

Thanks
 
Check your timing on the AD - after you select the pin, you have to give it settling time BEFORE you start the conversion. Otherwise you get bad reads that sound similar to what you're seeing.

Also the conversion itself can only go so quick. If in doubt, use that internal oscillator. It's slower, but works.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…