PDA

View Full Version : 18f4431 pwm4 and pwm 5 issues



lothar
- 8th April 2009, 16:27
Hello All,

I have a brushless DC motor and want to build my own drive control for the unit. I can get the device to throw out PWM's on ports 0,1,2,3 but nothing on 4 or 5. I am getting something from portb.4 and portb.5 but it is not the pwm's i have on the lower ports.

My code is a mish mash of others to get something working to build upon but hopefully someone can spot my error.

Device 18F4431
XTAL = 20

Dim Duty As Word
Duty = 800
PORTB = 0 ' clear port latch

TRISB = %11000000

PTCON0=$00 timebase
PTPERL=$A0 ' $01A0 = 12kHz
PTPERH=$01

PWMCON0=%01010111
PWMCON1=%00000001
DTCON=$00
OVDCOND = %00000000
OVDCONS = %00000000 PORT PINS

SEVTCMPL=$00
SEVTCMPH=$00

PDC0L=$00
PDC0H=$00
PDC1L=$00
PDC1H=$00
PDC2L=$00
PDC2H=$00

PDC0L = Duty.LowByte
PDC0H = Duty.HighByte

PDC1L = Duty.LowByte
PDC1H = Duty.HighByte

PDC2L = Duty.LowByte
PDC2L = Duty.HighByte


PTCON1=%10000000

MAIN:

OVDCOND = %00111111
DelayMS 500
OVDCOND = %00000000
DelayMS 500

GoTo MAIN

Many thanks

Lothar

mister_e
- 8th April 2009, 17:16
Have a look at this one
http://www.picbasic.co.uk/forum/showpost.php?p=43820&postcount=4

PS: It's Melabs PICBasic forum here, Proton PDS is at the following
http://www.picbasic.org/forum/

mister_e
- 8th April 2009, 17:20
And check your config fuse setting. Seems you can move PWM4 on RB5 or on RD5. Possible that you have LVP enabled, if so it will screw up the signal on RB5 indeed!

lothar
- 8th April 2009, 20:06
Hi Steve,

Apologies for posting on the wrong forum. To be honest I stumbled across this picbasic forum through good old google. I also noticed that members like Bruce have had good results from this particular PIC and thought this the best location to post. I am not looking to upset anyone and if by posting on this forum I have done this then please accept my apologies. In the future I will post on the proton forum only.

Thanks for the heads up on the LVP I will check on this and be on my merry way.

Thanks again

Lothar

mister_e
- 8th April 2009, 20:10
Don't worry about that, we are here to help each other!

I think Bruce's post can help you. Easy to convert to PDS later anyways ;)

lothar
- 8th April 2009, 21:03
Steve you will be happy to know that i am currently checking the config settings within the datasheet as we speak/ type.

I have Bruce's PWM scaling code working but needed to make the full step to using the override function for the PWM Brushless sequence output.

I must add when I do crack it I will post on this forum to hopefully assist others who may be trying to get this pretty interesting PIC working.

Anyway back to the datasheet....what joy

lothar
- 9th April 2009, 10:58
As promised I have found the resolution to my problem (the PWM issue not the posting on the wrong forum issue) after much soul searching and datasheet reading I tracked it down to be a typo.

the line:


PDC2L = Duty.LowByte
PDC2L = Duty.HighByte

should have been:


PDC2L = Duty.LowByte
PDC2H = Duty.HighByte

the code works fine now and I can now move through the commutation pattern of the brushless motor drive. I cant believe it came to this damn you cut-copy-paste.

Once again I apologies for posting here :o

mister_e
- 9th April 2009, 16:48
Glad to hear you have it working now!

No need for apologies, your post will be useful for some.