CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

DSPIC30F2020 PWM problem
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed Feb 05, 2014 2:25 pm     Reply with quote

The abilities of getenv, are like the assembler. Poorly documented!. They appeared in the V4 compilers, and are really so much nicer to work with. Unfortunately, because a lot of the examples predate this, they don't get illustrated enough. You'll find several of the 'old hands', who have learnt about them trying to encourage people to use this ability, when you have to deal with the hardware.... Smile

Glad you are moving forwards.

Best Wishes
Diode



Joined: 27 Jul 2012
Posts: 35

View user's profile Send private message

PostPosted: Thu Feb 06, 2014 5:58 am     Reply with quote

You are right, with the help of those functions it is much easier to understand what is happening.
But it was good to have tried it directly by writing registers as Mike described. It has learned me how to read that particular piece of the datasheet and how to use it.

Well, I spent most of my morning trying to get the second PWM channel working but this still doesn't function. I have read the register section multiple times but I don't see what I'm doing wrong.

Here is my code:
Code:
 //#include "B:\Ozon voeding\Software\dspic test 2.h"

#include<30F2020.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES FRC_PLL                  //Internal Fast RC oscillator with PLL
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES FRANGE_HIGH              //Frequency Range for FRC 14.55MHz
#FUSES NOOSCIO                  //OSC2 is clock output
#FUSES NOPR                     //Primary oscillaotr disabled
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES PUT128                   //Power On Reset Timer value 128ms
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES ICSP1                    //ICD uses PGC1/PGD1 pins
#use delay(clock=58200000)      // =14.55MHZ *4 (interne rc oscillator)

#word PTCON = getenv("SFR:PTCON")     
#word PTPER = getenv("SFR:PTPER")
#word MDC = getenv("SFR:MDC")
#word IOCON1 = getenv("SFR:IOCON1")
#word IOCON2 = getenv("SFR:IOCON2")
#word DTR1 = getenv("SFR:DTR1")
#word DTR2 = getenv("SFR:DTR2")
#word PWMCON1 = getenv("SFR:PWMCON1")
#word PWMCON2 = getenv("SFR:PWMCON2")
#word PDC1 = getenv("SFR:PDC1")
#word PDC2 = getenv("SFR:PDC2")
#word ALTDTR1 = getenv("SFR:ALTDTR1")
#word ALTDTR2 = getenv("SFR:ALTDTR2")
#word Phase1 = getenv("SFR:PHASE1")     
#word Phase2 = getenv("SFR:PHASE2")     
#bit PTEN = getenv("BIT:PTEN")

void main()
{

   PTCON = 0x0400;      // Enable immideate period updates     
   PTPER = 0x8894;      // Period timed (Desired period / 1.05ns)
   MDC = 0x444B;        // Master duty cycle (50%) in this case
   Phase1 = 0x2225;     // Phase shift pwm channel 1
   Phase2 = 0x2225;     // Phase shift pwm channel 2
   PWMCON1 = 0x0180;    // Use Master duty cycle, Enable phase1 function
   PWMCON2 = 0x0180;    // Use Master duty cycle, Enable phase1 function
   IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module
   IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module
   DTR1 = 0x0040;       // Set dead time to 4*64*1.05ns ??
   DTR2 = 0x0040;       // Set dead time to 4*64*1.05ns ??
   //ALTDTR1 = 0x0040; 
   //ALTDTR2 = 0x0040; 
   PTEN = 1;            // Enable PWM module
   
   while (true)
   {

   }

}


PWM1 does work and has a frequency of 26.5 kHz and I'm able to change this frequency and the duty cylce in the while loop.
But PWM2 doesn't seem to do much. I see a PWM signal on the pins but with a voltage of 50mV. I guess this is due to crosstalk because it is a copy of PWM1 but then with a very small amplitude.
Does anyone see irregularities is the configuration of the PWM module in my code?

I also have a questions about the dead time, how do I calculate the actual dead time? I assume that the value written in the DTR register will be multiplied by 1.05ns (period time) and also multiplied by 4? According the datasheet the minimum dead time is 4.16ns which implies that the period time is multiplied by 4?
Diode



Joined: 27 Jul 2012
Posts: 35

View user's profile Send private message

PostPosted: Thu Feb 06, 2014 8:46 am     Reply with quote

Sometimes a break is all you need....

Code:
 
 IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module
 IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module


Of course this need to be IOCON1 and IOCON2

It seems to work now, let's see if I can change the phase during my program.

Edit; and it works!
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Feb 06, 2014 10:07 am     Reply with quote

There's a 2 missing:

Code:

   IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module
   IOCON1 = 0xC400;     // PENH and PENL controlled by PWM module


Same register....

I see you spotted it while I was typing!....

On your timings, the phase shift, and dead time counters run off the 'non PLL' clock. The duty register runs off the PLL output. So 4:1 difference.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group