PIC18f4331 PWM Problem

Hi Guys.

Wrote a simple program to generate some PWMs. Using MPLAB, the output are just as expected. However, after writing to a 18f4331 and observing the output from an oscillator, some pins do not produce the PWM at all.

2 sources of possible error:

  1. Code:

CLRF PORTB CLRF LATB MOVLW 0x00 MOVWF TRISB CLRF PORTA CLRF LATA MOVLW 0x00 MOVWF ANSEL0 MOVWF TRISA

movlw b'00001000' movwf PTCON0 movlw 0xC3 movwf PTPERL movlw 0x09 movwf PTPERH movlw b'01000000' movwf PWMCON0 movlw b'00001111' movwf DTCON movlw b'00000000' movwf FLTCONFIG movlw 0x00 movwf SEVTCMPL movlw 0x00 movwf SEVTCMPH

bsf PTCON1, PTEN

movlw b'00000000' movwf OVDCOND

here movlw b'00011001' movwf OVDCONS movlw b'00011010' movwf OVDCONS movlw b'00010110' movwf OVDCONS movlw b'00100110' movwf OVDCONS movlw b'00100101' movwf OVDCONS movlw b'00101001' movwf OVDCONS goto here ; Loop forever.

  1. Circuitry: I tied MCLR and all other unused pins to gnd. OSC1 & OSC2 to a 4MHz crystal.

Observations: a) Nothing will be observed if PWM4(pin38) is not shorted to ground for a brief duration. WHY??? b) Some pins (PWM1,PWM2) do not have any output. WHY??? MPLAB shows it should have. c) When I burn the prog. into a new chip, (a) is again observed but now other PWMs do not have outputs instead. WHY WHY??

Tks for your time. ywz

Reply to
ydoubleuz
Loading thread data ...

On most PIC chips, MCLR needs to be pulled high or you are holding the device in RESET. I work with 16F PICs primarily, but I think this still applies.

You only need to tie unused _inputs_ high or low, unused outputs can be left floating.

If some pins have the correct output, but others don't then the problem is usually that you have left some pins in their default analog mode (comparators or ADC inputs).

Output pins can be killed by overloading them (such as by trying to drive a pin connected to ground high), but I believe the 18F PICs have more series resistance in the output driver to help prevent death.

Reply to
Anthony Fremont

Hi Anthony, tks for responding

Yup that was a typo error on my part. I tied the MCLR to high through a resistor.

Will this affect the output if i tied all unused outputs? I will try that out later.

PWM 0-3 are latched with PortB only.PWM4-5 are latched to another register "KBI1 and KBI0". I had initialized TRISB to 0x00. Is this correct?

These pins are only connected to the oscilloscope and nothing else.

Btw, any idea why must PWM5(KBI1/RB5/PGM) be shorted to ground before anything starts? I had an output at RA1 which drives a LED at the very start of the program. If i leave PWM5 unconnected or connected to a oscilloscope, the LED will not lit up and no output will be observed on any pins. It is after shorting that pin to ground that i start getting SOME outputs and LED will be lit.

Tks again. I am losing some sleep and lotsa hair over this issue. :) ywz

Reply to
ydoubleuz

My guess: check (with an ohm-meter) from the power supply to the *chip pin* that *all* the PIC grounds are connected...

Best Regards

Steve Sousa

Reply to
Steve Sousa

Checked : Vcc and AVcc are shorted to ground.

Any other inputs?

Tks ywz

Reply to
ydoubleuz

sorry for the typo. Shld be Vss and AVss

Reply to
ydoubleuz

a écrit dans le message de news: snipped-for-privacy@i13g2000prf.googlegroups.com...

Did you check your configuration flags twice ? they are pretty much complex on this chip.

Reply to
BrunoG

Check twice? care to elaborate? tks

Reply to
ydoubleuz

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.