PDA

View Full Version : 2 PWM in 16F690 problems



ciendavila
- 8th April 2008, 03:29
I am working in a 2 DC motor control project. I'am making tests with the HPWM in a 16F690, but i'm having problems to generate 2 diferent signals... I generate without problems a PWM signal in the channel 1, but i can't drive a signal in the channel 2..

I need to know if its possible to drive 2 diferrent dutty cycles in the channel 1 and 2, and how to do this.. I'am using Microcode studio and picbasic pro..

mister_e
- 8th April 2008, 04:49
This PIC have only 1 CCP channel, which mean you can't use HPWM for more tha 1 channel. If you need another channel, there's serveral way to do it: Change your PIC for one having 2 CCP module, or keep the existing one but create a Timer interrupt based PWM, or do the same in a tight loop... but you will be limited to do anything else, or Darrel Taylor's Multi_SPWM routine ( http://www.pbpgroup.com/modules/wfsection/article.php?articleid=12 ).

Depending your DC moto spec.. the Timer based or else low frequency PWM may work... or not. HPWM will produce higher frequency and run in background.

ciendavila
- 8th April 2008, 05:02
Thankyou for your fast answer.. can you recommend me a mid range micro that can be used on this application?, dont you know if any dip 20 pin have 2 ccp modules? These will be a critical application so I need to do it with HPWM.. not with software..

mister_e
- 8th April 2008, 05:14
As far as i remember, the smallest one with 2 CCP have 28 pins.

paul borgmeier
- 8th April 2008, 06:46
Thankyou for your fast answer.. can you recommend me a mid range micro that can be used on this application?, dont you know if any dip 20 pin have 2 ccp modules? These will be a critical application so I need to do it with HPWM.. not with software..

If you are willing to step up to the 18F family, I believe there are a couple of 18 pin options (e.g., 18F1230 and 18F1330).

mister_e
- 8th April 2008, 15:29
problem with most single ECCP module is that you're restricted with only 1 duty cycle... but many output type, half-bridge, full-bridge etc etc.

But yeah, Microchip have tons of PIC model, i just didn't found one Flash type with 2 CCP under 28 pins. Sure there's chance that i missed a couple of models.

ciendavila
- 9th April 2008, 02:05
I already find a solution, as you say 18F1330 looks like the best model for PWM aplications. It have 18 pins and ADC, perfect for my project, but the microcode doesnt works with it as well as the other micros, when you try to use the HPWM, many errors occur..

I have been working on the project today, and finally it works, working directly with the registers, you can drive 3 different PWM at the time.

Lets see how the ADC works and if i can finish my project without any other problem.

Thankyou for all..

Peaps
- 25th April 2008, 20:00
Hi.

Did you get anywhere with the PWM code for the 18F1330?

I don't think that you can use HPWM with this device as it's PWM module is completely different to the normal PWM module found in 16F chips. It requires many registers to be set manually.

Am currently working on this, but experiencing problems...

Andy

ciendavila
- 26th April 2008, 22:23
You have to acces direct to the registers, and configure the internal OSC to work with it..
The pwm duty cycle works with 14 bits, so you have to write directly the value on the PDC0L register for the less significant bits and the PDC0H for the more significant bits of the PWM 0 channel..

I hope these can help you, if you download the datasheet you will understand more the code that I wrote.. These is part of the code of my program:

OSCCON.6 = 1 'configure the internal oscilator to work at 4 MHz
OSCCON.5 = 1
OSCCON.4 = 0
OSCCON.1 = 1

PTCON0 = $00 ' configure frequency and the PWM sets
PTCON1 = $C0
PWMCON0 = $37
PWMCON1 = 0
PTPERL = $AA
PTPERH = $01

PDC0L = $FF ' Set the duty cycle for PWM 0
PDC0H = $00
PDC1L = $FF ' Set the duty cycle for PWM 1
PDC1H = $01

Peaps
- 27th April 2008, 10:03
Hi, thanks for the reply.. I got it working in the end.

The thing that I was doing wrong was having a larger duty cycle value in PDC0L and PDC0H than the value in PTPERL and PTPERH. Since the PWM module counts upwards until it reaches the duty cycle value, and then continues to count upwards to the end of the frequency cycle as determined by the values in PTPERx registers, PDCxx must be lower than PTPERx.

Thanks again,

Andy