View previous topic :: View next topic |
Author |
Message |
georgefe
Joined: 20 Apr 2006 Posts: 4
|
Power Control PWM Module |
Posted: Thu Apr 20, 2006 8:51 pm |
|
|
I am having a really hard time programming the Power Control PWM Module. I think I have a problem with the registers I am setting up. Can anyone help me?
Here is the code I am running.
Code: |
TRISB=0; //make output
PTCON0=0b00001000;/*
;||||||||+>PTMOD0 MODE SELECT
;|||||||+->PTMOD1
;||||||+-->PTCKPS0 PRE-SCALER
;|||||+--->PTCKPS1
;||||+---->PTOPS0 POST-SCALEER
;|||+----->PTOPS1
;||+------>PTOPS2
;|+------->PTOPS3
*/
//This sets postscale to 1:1, prescale to 1:16, and free running mode
PWMCON0=0b01000000;/*
;||||||||+>PMOD0 OUTPUT PAIR MODE BITS
;|||||||+->PMOD1
;||||||+-->PMOD2
;|||||+--->PMOD3
;||||+---->PWMEN0 PWM MODULE ENABLE BITS
;|||+----->PWMEN1
;||+------>PWMEN2
;|+------->N/A
*/
//This sets PWM0 and PWM1, PWM2 and PWM3, PWM4 and PWM5 as linked. PWM6 and 7 are not on this chip
// for PMOD, this is all PWM signals enabled
PWMCON1=0b00000001;/*
;||||||||+>OSYNC PWM OUTPUT OVERRIDE SYNCH BIT
;|||||||+->UDIS PWM UPDATE DISABLE BIT
;||||||+-->N/A
;|||||+--->SEVDIR PWM SPECIAL EVENT TRIGGER OUTPUT POSTSCALE SELECT BITS
;||||+---->SEVOPS0
;|||+----->SEVOPS1
;||+------>SEVOPS2
;|+------->SEVOPS3
*/
OVDCOND=0b00111111;/*
;||||||||+>POVD0 Set for no override
;|||||||+->POVD1
;||||||+-->POVD2
;|||||+--->POVD3
;||||+---->POVD4
;|||+----->POVD5
;||+------>POVD6
;|+------->POVD7
*/
OVDCONS=0b00000000;
/* ;||||||||+>POUT0 Set for no override
;|||||||+->POUT1
;||||||+-->POUT2
;|||||+--->POUT3
;||||+---->POUT4
;|||+----->POUT5
;||+------>POUT6
;|+------->POUT7
*/
FLTCONFIG=0b00101010;
/* ;||||||||+>FLTAEN
;|||||||+->FLTAMOD
;||||||+-->FLTAS
;|||||+--->FLTCON
;||||+---->FLTBEN
;|||+----->FLTBMOD
;||+------>FLBTS
;|+------->BRFEN
*/
DTCON=0; //no dead band timer
PTMRH = 0x00;
PTMRL =0xff;
PTPERL = 0xe1; //set the period to 1249 which with the prescaler equals 100hz
PTPERH = 0x04;
PDC0L=0xFF;
PDC0H=0x04;
PDC1L=0xFF;
PDC1H=0x04;
PDC2L=0xFF;
PDC2H=0x04;
PTCON1=0b10000000;
/* ;||||||||+>N/A
;|||||||+->N/A
;||||||+-->N/A
;|||||+--->N/A
;||||+---->N/A
;|||+----->N/A
;||+------>PTDIR PWM TIME BASE COUNT DIRECTION STATUS BIT
;|+------->PTEN PWM TIME BASE TIMER ENABLE BIT
*/
while(1)
{}
|
Any suggestions?
Thanks for any help!
George |
|
|
georgefe
Joined: 20 Apr 2006 Posts: 4
|
|
Posted: Thu Apr 20, 2006 9:44 pm |
|
|
Oh, I forgot to mention. I am using a PIC18F2331. I am trying to control 2 h-bridge type circuits that take complimentary PWM signals in. So basically I want to control two of the three PWM pairs on the board. I want the third one going out as well so I can see that it is working on my O-scope. I am looking for a frequency of about 100 Mhz and a duty rate of 0-99% but that is really not relevant right now. If I could just get some sort of PWM signal to show up on the scope, I would be really really happy! I am running the internal clock speed of 8 Mhz. |
|
|
georgefe
Joined: 20 Apr 2006 Posts: 4
|
|
Posted: Mon Apr 24, 2006 11:15 am |
|
|
I gave a few more stabs at it and then after I upgraded my PCHW I noticed that their is now a library for it. However, I still cannot get it to output. Here is the code I am running:
Code: | long int period = 2048;
setup_oscillator(OSC_8MHZ|OSC_INTRC);
setup_power_pwm_pins(PWM_BOTH_ON,PWM_BOTH_ON,PWM_BOTH_ON,PWM_BOTH_ON);
//PPWM channels 0 and 1 are both on and always opposite values
setup_power_pwm(PWM_CLOCK_DIV_4|PWM_FREE_RUN,1,0,period,0,1,0);
//add dead time for reactive loads
while(true)
{
//set_power_pwm0_duty(adc_val * ((period>>8)+1)); //max ADC value is 1023
set_power_pwm0_duty(4000);
set_power_pwm2_duty(4000);
set_power_pwm4_duty(4000);
}
|
Any ideas? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 24, 2006 11:49 am |
|
|
Look at the CCS example file: EX_POWER_PWM.C
It's in this folder:
c:\Program Files\PICC\Examples |
|
|
georgefe
Joined: 20 Apr 2006 Posts: 4
|
|
Posted: Mon Apr 24, 2006 12:43 pm |
|
|
Yeah I copied that exact program and just simplified it a little bit to just output a set PWM signal. However I am still getting nothing :( I am beginning to wonder whether my pic might be damaged. It passes a verification test from the compiler and I can set I/O pins in and out. |
|
|
Storic
Joined: 03 Dec 2005 Posts: 182 Location: Australia SA
|
|
Posted: Mon Apr 24, 2006 8:07 pm |
|
|
Hav you check your Fuses, I had simular problems (on another code) where nothing was working. I thought it was the micro, it turned out to be my Fuses,
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
my internal OSC was not set so nothing was working
ANdrew _________________ What has been learnt if you make the same mistake? |
|
|
Fro_Guy Guest
|
|
Posted: Tue Apr 25, 2006 7:43 am |
|
|
Also make sure that you are setting your control lines right on the H-bridge. Good luck! |
|
|
|