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

1.04 ns PWM Resolution

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Roberto da Rivoli



Joined: 09 Feb 2004
Posts: 37
Location: TURIN -Italy-

View user's profile Send private message Send e-mail

1.04 ns PWM Resolution
PostPosted: Tue Jun 28, 2016 2:44 am     Reply with quote

I'm thinking of using a DSPIC33ep32GS to generate a PWM at 20KHz 16bit, but I can not find documentation on how to set the CCS compiler to test the PWM
Ttelmah



Joined: 11 Mar 2010
Posts: 19494

View user's profile Send private message

PostPosted: Tue Jun 28, 2016 3:17 am     Reply with quote

For the standard PWM, look at the examples. ex_pwm_pcd.c

For the HS PWM, look in the include file for the processor, and download the latest PDF manual (the internal manual has not yet been fully updated - for instance if you start typing 'setup_hspwm', it doesn't link to the main setup function....). However if you select the 'setup_hspwn_unit' function, then the link from the bottom of this page works!.
Code:

////////////////////////////////////////////////////////////////// High-Speed PWM
//
// High-Speed PWM Functions: setup_hspwm(), setup_hspwm_unit(), set_hwpwm_phase(),
//                           set_hspwm_duty(), set_hspwm_event(), setup_hspwm_blanking(),
//                           setup_hspwm_trigger(), set_hspwm_override(),
//                           setup_hspwm_chop_clock(), setup_hspwm_unit_chop_clock(),   
//                           setup_hspwm_secondary(), set_hspwm_event_sedondary(),
//                           get_hspwm_capture(), 
// High-Speed PWM Prototypes:
_bif void setup_hspwm(unsigned int32 settings, unsigned int16 period);
_bif void setup_hspwm_secondary(unsigned int32 settings, unsigned int16 period); 
_bif void setup_hspwm_unit(unsigned int8 unit, unsigned int32 settings);
_bif void setup_hspwm_unit(unsigned int8 unit, unsigned int32 settings, unsigned int16 dead_time);
_bif void setup_hspwm_unit(unsigned int8 unit, unsigned int32 settings, unsigned int16 dead_time, unsigned int16 alt_dead_time);
_bif void set_hspwm_phase(unsigned int8 unit, unsigned int16 phase);
_bif void set_hspwm_phase(unsigned int8 unit, unsigned int16 phase, unsigned int16 sphase);
_bif void set_hspwm_duty(unsigned int16 duty);
_bif void set_hspwm_duty(unsigned int8 unit, unsigned int16 duty);
_bif void set_hspwm_duty(unsigned int8 unit, unsigned int16 duty, unsigned int16 sduty);
_bif void set_hspwm_event(unsigned int16 settings, unsigned int16 compare_time);
_bif void set_hspwm_event_secondary(unsigned int16 settings, unsigned int16 compare_time);
_bif void setup_hspwm_blanking(unsigned int8 unit, unsigned int32 settings, unsigned int16 delay);
_bif void setup_hspwm_trigger(unsigned int8 unit);
_bif void setup_hspwm_trigger(unsigned int8 unit, unsigned int8 start_delay);
_bif void setup_hspwm_trigger(unsigned int8 unit, unsigned int8 start_delay, unsigned int8 divider);
_bif void setup_hspwm_trigger(unsigned int8 unit, unsigned int8 start_delay, unsigned int8 divider, unsigned int16 trigger_value);
_bif unsigned int16 get_hspwm_capture(unsigned int8 unit); 
_bif void setup_hspwm_chop_clock(unsigned int16 settings);   
_bif void setup_hspwm_unit_chop_clock(unsigned int8 unit, unsigned int8 settings);   
_bif void set_hspwm_override(unsigned int8 unit, unsigned int16 setting);
// Constants used in SETUP_HSPWM() first parameter are:
// Constants used in SETUP_HSPWM_SECONDARY() first parameter are:
#define HSPWM_DISABLED                                         0
#define HSPWM_ENABLED                                     0x8000
#define HSPWM_HALT_IDLE                                   0x2000
#define HSPWM_UPDATED_IMMEDIATELY                         0x0400
#define HSPWM_INVERTED                                    0x0200
#define HSPWM_SYNCO_ENABLED                               0x0100
#define HSPWM_EXT_SYNC                                    0x0080
// One of the following may be OR'ed in with the above
#define HSPWM_SYNC_SOURCE_SYNCI1                               0
#define HSPWM_SYNC_SOURCE_SYNCI2                          0x0010     
// One of the following may be OR'ed in with the above
#define HSPWM_CLOCK_DIV_BY_1                                   0
#define HSPWM_CLOCK_DIV_BY_2                             0x10000
#define HSPWM_CLOCK_DIV_BY_4                             0x20000
#define HSPWM_CLOCK_DIV_BY_8                             0x30000
#define HSPWM_CLOCK_DIV_BY_16                            0x40000
#define HSPWM_CLOCK_DIV_BY_32                            0x50000
#define HSPWM_CLOCK_DIV_BY_64                            0x60000

// Constants used in SETUP_HSPWM_UNIT() second parameter are (first parameter is unit number 1,2,...):
#define HSPWM_ENABLE                                      0xC000
#define HSPWM_ENABLE_H                                    0x8000
#define HSPWM_ENABLE_L                                    0x4000
// One of the following may be OR'ed in with the above
#define HSPWM_H_POLARITY_LOW                              0x2000
#define HSPWM_H_POLAIRTY_HIGH                                  0
// One of the following may be OR'ed in with the above
#define HSPWM_L_POLARITY_LOW                              0x1000
#define HSPWM_L_POLARITY_HIGH                                  0
// One of the following may be OR'ed in with the above
#define HSPWM_INDEPENDENT                                 0x0C00 
#define HSPWM_PUSH_PULL                                   0x0800
#define HSPWM_REDUNDANT                                   0x0400
#define HSPWM_COMPLEMENTARY                                    0
// One of the following my be OR'ed in with the above
#define HSPWM_FAULT_L1_H1                                 0x0030
#define HSPWM_FAULT_L0_H1                                 0x0020
#define HSPWM_FAULT_L1_H0                                 0x0010
#define HSPWM_FAULT_L0_H0                                      0
// One of the following may be OR'ed in with the above
#define HSPWM_CURRENT_LIMIT_L1_H1                         0x000C
#define HSPWM_CURRENT_LIMIT_L0_H1                         0x0008
#define HSPWM_CURRENT_LIMIT_L1_H0                         0x0004
#define HSPWM_CURRENT_LIMIT_L0_H0                              0
// The following may be OR'ed in with the above
#define HSPWM_SWAP_H_AND_L                                0x0002
#define HSPWM_SYNC_OVERRIDE                               0x0001

// The following may be OR'ed in with the above
#define HSPWM_FAULT_INT_ENABLED                       0x10000000
#define HSPWM_CURRENT_LIMIT_INT_ENABLED               0x08000000
#define HSPWM_TRIGGER_INT_ENABLED                     0x04000000
#define HSPWM_TIME_BASE_FROM_PHASE_REGS               0x02000000
#define HSPWM_DUTY_CYCLE_FROM_MDC_REG                 0x01000000
// One of the following may be OR'ed in with the above
#define HSPWM_DT_FUCNTION_DISABLED                    0x00800000
#define HSPWM_DT_NEGATIVE                             0x00400000
#define HSPWM_DT_POSITIVE                                      0
// The following may be OR'ed in with the above
#define HSPWM_USES_SECONDARY_TIME_BASE                0x00080000
#define HSPWM_CURRENT_LIMIT_RESETS_TIME_BASE          0x00020000
#define HSPWM_UPDATE_ARE_IMMEDIATE                    0x00010000
// One of the following may be OR'ed in with the above
#define HSPWM_CENTER_ALIGN_MODE                       0x00040000
#define HSPWM_EDGE_ALIGN_MODE                                  0

// One of the following may be OR'ed in with the above
#define HSPWM_INDEPENDENT_FAULT_MODE              0x800000000000
#define HSPWM_NORMAL_FAULT_MODE                                0
// One of the following may be OR'ed in with the above
#define HSPWM_CURRENT_LIMIT_SOURCE_COMP4          0x400000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_COMP3          0x3C0000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_COMP2          0x380000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_COMP1          0x340000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT12          0x300000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT11          0x2C0000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT10          0x280000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT9           0x240000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT8           0x200000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT7           0x1C0000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT6           0x180000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT5           0x140000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT4           0x100000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT3           0x0C0000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT2           0x080000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT1           0x040000000000   
// One of the following may be OR'ed in with the above
#define HSPWM_CURRENT_LIMIT_ACTIVE_LOW            0x020000000000
#define HSPWM_CURRENT_LIMIT_ACTIVE_HIGH                        0
// One of the following may be OR'ed in with the above
#define HSPWM_CURRENT_LIMIT_MODE_ENABLED          0x010000000000
#define HSPWM_CURRENT_LIMIT_MODE_DISABLED                      0
// One of the following may be OR'ed in with the above
#define HSPWM_FAULT_SOURCE_COMP4                  0x008000000000   
#define HSPWM_FAULT_SOURCE_COMP3                  0x007800000000   
#define HSPWM_FAULT_SOURCE_COMP2                  0x007000000000   
#define HSPWM_FAULT_SOURCE_COMP1                  0x006800000000   
#define HSPWM_FAULT_SOURCE_FLT12                  0x006000000000   
#define HSPWM_FAULT_SOURCE_FLT11                  0x005800000000   
#define HSPWM_FAULT_SOURCE_FLT10                  0x005000000000   
#define HSPWM_FAULT_SOURCE_FLT9                   0x004800000000   
#define HSPWM_FAULT_SOURCE_FLT8                   0x004000000000   
#define HSPWM_FAULT_SOURCE_FLT7                   0x003800000000   
#define HSPWM_FAULT_SOURCE_FLT6                   0x003000000000   
#define HSPWM_FAULT_SOURCE_FLT5                   0x002800000000   
#define HSPWM_FAULT_SOURCE_FLT4                   0x002000000000   
#define HSPWM_FAULT_SOURCE_FLT3                   0x001800000000   
#define HSPWM_FAULT_SOURCE_FLT2                   0x001000000000   
#define HSPWM_FAULT_SOURCE_FLT1                   0x000800000000   
// One of the following may be OR'ed in with the above
#define HSPWM_FAULT_ACTIVE_LOW                    0x000400000000
#define HSPWM_FAULT_ACTIVE_HIGH                                0
// One of the following may be OR'ed in with the above
#define HSPWM_FAULT_MODE_DISABLED                 0x000300000000
#define HSPWM_FAULT_MODE_ENABLED_CYCLE            0x000100000000
#define HSPWM_FAULT_MODE_ENABLED_LATCHED                       0

// Constants used in SETUP_HSPWM_EVENT() first parameter are:
// Constants used in SETUP_HSPWM_EVENT_SECONDARY() first parameter are:
#define HSPWM_SPECIAL_EVENT_INT_ENABLED                   0x0800
#define HSPWM_SPECIAL_EVENT_INT_DISABLED                       0
// Or (with |) the above with a number 1-16 to set special event postscaler

// Constants used in SETUP_HSPWM_BLANKING() second parameter are (first parameter is unit number 1,2,...):
#define HSPWM_RE_PWMH_TRIGGERS_LE_BLANKING                0x8000
#define HSPWM_FE_PWMH_TRIGGERS_LE_BLANKING                0x4000
#define HSPWM_RE_PWML_TRIGGERS_LE_BLANKING                0x2000
#define HSPWM_FE_PWML_TRIGGERS_LE_BLANKING                0x1000
#define HSPWM_LE_BLANKING_APPLIED_TO_FAULT_INPUT          0x0800
#define HSPWM_LE_BLANKING_APPLIED_TO_CURRENT_LIMIT_INPUT  0x0400
#define HSPWM_STATE_BLANKING_WHEN_BLANKING_SIGNAL_HIGH    0x0020   
#define HSPWM_STATE_BLANKING_WHEN_BLANKING_SIGNAL_LOW     0x0010   
#define HSPWM_STATE_BLANKING_WHEN_PWMH_HIGH               0x0008   
#define HSPWM_STATE_BLANKING_WHEN_PWMH_LOW                0x0004   
#define HSPWM_STATE_BLANKING_WHEN_PWML_HIGH               0x0002   
#define HSPWM_STATE_BLANKING_WHEN_PWML_LOW                0x0001   
// One of the following may be OR'ed in with the above   
#define HSPWM_STATE_BLANKING_SOURCE_PWM1H             0x00010000 
#define HSPWM_STATE_BLANKING_SOURCE_PWM2H             0x00020000 
#define HSPWM_STATE_BLANKING_SOURCE_PWM3H             0x00030000 
#define HSPWM_STATE_BLANKING_SOURCE_PWM4H             0x00040000   
#define HSPWM_STATE_BLANKING_SOURCE_PWM5H             0x00050000   
#define HSPWM_HIGH_RESOLUTION_PWM_PERIOD_DISABLED     0x00800000   
#define HSPWM_HIGH_RESOLUTION_PWM_DUTY_DISABLED       0x00400000   

// Constants used in SET_HSPWM_OVERRIDE() second parameter are (first parameter is unit number 1,2,...):
#define HSPWM_FORCE_H_1                                   0x0280
#define HSPWM_FORCE_H_0                                   0x0200
#define HSPWM_FORCE_L_1                                   0x0140
#define HSPWM_FORCE_L_0                                   0x0100

// Constants used in SETUP_HSPWM_CHOP_CLOCK() first parameter are: 
#define HSPWM_CHOP_CLK_GENERATOR_ENABLED                  0x8000 
#define HSPWM_CHOP_CLK_GENERATOR_DISABLED                      0 
// Or (with |) the above with a number 1-1024 to set the chop clock divider 

// Constants used in SETUP_HSPWM_UNIT_CHOP_CLOCK() second parameter are (first parameter is unit number 1,2,...): 
#define HSPWM_PWMH_CHOPPING_ENABLED                       0x0002 
#define HSPWM_PWML_CHOPPING_ENABLED                       0x0001 
#define HSPWM_CHOPPING_DISABLED                                0 
// One of the following may be OR'ed in with the above
#define HSPWM_CLOP_CLK_SOURCE_PWM5H                       0x0014     
#define HSPWM_CLOP_CLK_SOURCE_PWM4H                       0x0010   
#define HSPWM_CLOP_CLK_SOURCE_PWM3H                       0x000C   
#define HSPWM_CLOP_CLK_SOURCE_PWM2H                       0x0008 
#define HSPWM_CLOP_CLK_SOURCE_PWM1H                       0x0004 
#define HSPWM_CHOP_CLK_SOURCE_CHOP_CLK_GENERATOR               0 

// Constants used in SETUP_HSPWM_TRIGGER() second parameter are (first parameter is unit number 1,2,...): 
#define HSPWM_COMBINE_PRIMARY_AND_SECONDARY_TRIGGER       0x0080 
#define HSPWM_SEPERATE_PRIMARY_AND_SECONDARY_TRIGGER           0 
// Or (with |) the above with a number 0-63 to set trigger event start delay 


However 1.04nSec. I'm not sure you will get this at 20KHz. The actual resolution you can get will depend on what divisor is needed from the master clock you are running. 1.04nSec, is a 'best' outcome, running with the fastest auxiliary clock, and /1 divisor.

The syntax for the functions are:
Code:

SETUP_HSPWM(1,HSPWM_ENABLED|HSPWM_SYNC_SOURCE_SYNCI1|HSPWM_CLOCK_DIV_BY_1 );
 
setup_hspwm_unit(1,HSPWM_ENABLE|HSPWM_H_POLAIRTY_HIGH |HSPWM_L_POLARITY_LOW |HSPWM_COMPLEMENTARY, 100,100);

set_hspwm_duty(1,50);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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