Dspic33EP HSPWM Nasıl ayarlanır

Başlatan rree, 28 Ocak 2016, 22:09:31

rree

   PWM Generator 1  İstediğim Pwm1H Çıkışı Ve PWM1L çıkışı  komlementer biçimde çalışsın. pwm Oranı % 50
Frekansı 4Mhz   ölü zamanı istemiyorum. İşlemci DSPIC33EP128MC502 20 mips hızına ayarlı olduğu varsayalım.
  Neler yapmam gerekli?
Main(){
 SETUP_HSPWM(1,HSPWM_ENABLED|HSPWM_SYNC_SOURCE_SYNCI1|HSPWM_CLOCK_DIV_BY_2 );
 
setup_hspwm_unit(1,HSPWM_ENABLE|HSPWM_H_POLAIRTY_HIGH |HSPWM_L_POLARITY_LOW |HSPWM_COMPLEMENTARY, 100,100);

 set_hspwm_duty(1,50);
}

  CSS h dosyasında uzun bir paremetreler var
////////////////////////////////////////////////////////////////// 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(),   
// High-Speed PWM Prototypes:
_bif void setup_hspwm(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 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 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:
#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_PTGO16                          0x0020   
#define HSPWM_SYNC_SOURCE_PTGO17                          0x0030   
// 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_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_COMPENSATION_MODE                    0x00C00000  
#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_DT_POLARITY_INVERTED                    0x00200000  
#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          0x2C0000000000    
#define HSPWM_CURRENT_LIMIT_SOURCE_COMP3          0x280000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_COMP2          0x240000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_COMP1          0x200000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT4           0x0C0000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT3           0x080000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT2           0x040000000000   
#define HSPWM_CURRENT_LIMIT_SOURCE_FLT1                        0   
// 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_FLT32                  0x00F800000000      
#define HSPWM_FAULT_SOURCE_COMP4                  0x005800000000      
#define HSPWM_FAULT_SOURCE_COMP3                  0x005000000000  
#define HSPWM_FAULT_SOURCE_COMP2                  0x004800000000  
#define HSPWM_FAULT_SOURCE_COMP1                  0x004000000000  
#define HSPWM_FAULT_SOURCE_FLT7                   0x003000000000   
#define HSPWM_FAULT_SOURCE_FLT6                   0x002800000000   
#define HSPWM_FAULT_SOURCE_FLT5                   0x002000000000   
#define HSPWM_FAULT_SOURCE_FLT4                   0x001800000000   
#define HSPWM_FAULT_SOURCE_FLT3                   0x001000000000   
#define HSPWM_FAULT_SOURCE_FLT2                   0x000800000000   
#define HSPWM_FAULT_SOURCE_FLT1                   0x000000000000   
// 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:
#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_STATE_BLANKING_SOURCE_PWM6H             0x00060000    
#define HSPWM_STATE_BLANKING_SOURCE_PWM7H             0x00070000    

// 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_CHOP_CLK_SOURCE_PWM7H                       0x001C   
#define HSPWM_CHOP_CLK_SOURCE_PWM6H                       0x0018   
#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