PDA

View Full Version : HPWM and A to D interaction question 18F252



tcbcats
- 1st May 2006, 07:51
PIC18F252 with HPWM on C2... 20 Mhz osc.
Using A0 and A1 as analog input with internal 5 volt ref.
Fixed low Z analog input for testing.
All power is stable

HPWM 1,{0 to 255},17000

As I change the duty cycle of the HPWM my A to D results jump +/- 10 counts or so
If I delete the HPWM the A to D count is stable +/- 1 count
This holds true even when there is no load on the C2 PWM output.

What resources does the PB HPWM statement use that would affect the A to D function?

My code changes the HPWM duty cycle between each A to D read... If I do not change the HPWM duty cycle and hold it constant, The A to D result is stable.

Has anyone seen this on the 18F252?

tcbcats

mister_e
- 1st May 2006, 13:21
i suspect more a hardware problem rather than programming problem. As i understand, when you remove the load on the PWM channel, everything disapear?

Bad or poor voltage regulation (or regulator), unsufficient PSU filtering is my bet as now.

I don't hink it will solve somethng but, how about using a higher sampling time in you A/D conversion?

Can you post your schematic?

NavMicroSystems
- 1st May 2006, 18:01
tcbcats,

as Steve already mentioned, it is most likely something in hardware.

Could you post a schematic?

And hey you are not trying this on a breadboard, are you?

fanie
- 1st May 2006, 18:39
tcbcats,

Had the same problem a while back but with a 16f684. I can't remember how I solved it !!!! But it was with the setup of the HPWM I think...

mister_e
- 1st May 2006, 18:58
ARRRRRRRRRRGHHH invaders from the other camp. Hi Fanie, welcome here!

HPWM or PWM module can't interfer with a/d. BUT it could have something to do with the CCP2 trigger if there's something bad in the CCP2CON<3:0> register setting. Refer to section 17.5 of datasheet. But if it was the problem... i doubt the PWM will work anyways.

BUT as we didn't see any code line and schematic, it sounds more like a hardware problem... maybe a overloaded Psu too!

fanie
- 1st May 2006, 19:25
Eh Steve !

Thanks for the optimistic welcome, gee whiz... just thought I'd pop in to see if you guys need any help here but everything seems under control... between you and Nav anyways. Well, kind of.

As far as I remember the PWM (after defined CCP2CON) I had to do after the setup code, ie as part of the program (doesn't sound right). In my case it wouldn't run on it's own as it should and I got funny things happening. No PSU probs...

tcbcats - upload a bit of code... maybe someone would spot something.

sougata
- 4th May 2006, 06:29
Hi,

According to you when your CCP pin is floating (there is no load connected) you are experiencing the same problem. This perhaps indicates that your HPWM is not playing anything with the VDD line as this is Vref as well (I assume). A schematic post (with layout if possible) would be appreciated. By that time try playing with the sampling frequency (use the RC clock) and a bit more time for the sampling.

tcbcats
- 10th May 2006, 03:50
I did not find the problem but did get the code working.
I was setting up the A to D with the direct registers and had the setup wrong.
I just changed the code to use the ADCIN command and all is now working.

Something was messed up where I was reading the A to D justified register into a variable word using. .highbyte and. .Lowbyte

Yes this is on a breadboard but the results are now very stable as expected.
Thanks all…
tcbcats