Log in

View Full Version : PWM Module 18Fxx31



iphillipsca
- 16th April 2007, 19:55
Just a quick question here. Any one been dealing with the built in PWM modules in PICBasic?
I am trying to do a 3 channel dimmer that uses the 14 bit PWM.
The rundown of what I have so far is:

PWMCON0 = 0101(takes care of the odd pins for output) bits 3-0 I’m not sure on how to set. I am assuming that I want independent mode for just having a simple dimmer setup. That would be 01011111.

Next would be to setup “freerunning mode” – PTCON0 = 0000 (1:1 Postscale) 00 (1:1 Prescale) 00 (Free Running Mode) - all zeros.

Next is the PWMCON1 = 00000000. This register deals with interrupts and special events. Neither are needed.

I am not sure on the PWM Period stuff. Do I need to set PTPER? This I don’t really get. From what I can tell if I do need to set it, it would be PTPER = 0FFFH like in the datasheet.

After that it’s all down to the Duty Cycle – PDCx (L & H)

I won’t be using the dead time, override or fault registers. At least I don’t think so.

I am new to the whole onboard PWM stuff so any help is greatly appreciated.

Ian

malc-c
- 16th April 2007, 21:53
It may not be what you are looking for, but DT has produced some excellent PWM utilities which are available from

http://www.darreltaylor.com/DT_INTS-14/SPWM.html

I'm sure there is an INTS_18 version too, but can't for the life of me find where it is.

Darrel Taylor
- 16th April 2007, 22:14
Thanks Malcolm, but that probably won't help.

I've seen those chips before, but haven't had a chance to try them out yet.

All those 14-bit PWM's and capture channels look really interesting.
But they sure don't work anything like the CCP modules.

And nope, nothing special for DT-INTS either for those chips.

I know... I'm a whole bunch of No Help aren't I.
<br>

iphillipsca
- 17th April 2007, 00:41
Thanks for the reply guys.
Yah, I've used the CCP PWM stuff before and even done a simple Basic PWM but the resolution isn't good enough.
I know that probably doesn't sound right but believe me, you can see the difference, and more importantly, the folks that will be using this device will point it out to me.

Ok, I guess I just have to fight it out.
I will let you know how I make out here.
Thanks again.
Ian

Oh, and just so you know, this isn't a commercial(profit) application.

iphillipsca
- 17th April 2007, 20:01
The following works for setup:

pwm setup declarations

PTCON0 = %00000000 '1:1 postscale,1:1 prescale,Free running mode
PWMCON0 = %01111110 'all odd PWM I/O enabled,PWM pairs in Independant Mode
PWMCON1 = %00000001 '1:1 Postscale special event trigger,special event trigger occurs counting up, Updates from duty cycle and period buffer registers enabled, Output overrides via the OVDCON register are sycronized to the PWM time base.

OVDCOND = %00101010 'Output on PWM I/O is controlled by the value in the Duty Cyle register and PWM time base - for POVD1,POVD3,POVD5

PWMresolution VAR Word bankA
PWMresolutionL VAR PWMresolution.byte0
PWMresolutionH VAR PWMresolution.byte1

PTCON1 = %10000000 'PWM Time base is on
PWMresolution = 4064
PTPERH = PWMresolutionH
PTPERL = PWMresolutionL

' take your desired PWM value and put to PDCx L and H

There does seem to be an issue when using the PWM in the low values.
Just before the duty cycle is zero, it seems to flash to 100%.

Anyone else experience this?

BigWumpus
- 20th April 2007, 23:01
I'm working with the 18F2431...

Forget the PICBASIC PWM-Modules, this device has to be coded "by hand" !
I'm powering a brushless DC-Motor and I can't see your problem "around 0". Before programming new values to PDC* you have to set a bit and clear it afterwards in order to realy update the timings.

Yes, there are 3 (or 4) independent PWM-Modules inside !

hell_pk
- 11th April 2008, 08:06
Hi!
Can you give some details about your project.Also some code will be really helpfull explaining the timings,updation of PWM and use of motion feedback procedures.