pic.programmer
Advanced Member level 3
- Joined
- Aug 19, 2015
- Messages
- 773
- Helped
- 141
- Reputation
- 284
- Reaction score
- 140
- Trophy points
- 43
- Activity points
- 7,531
APFCON=0X00
Then pins functions became as follows:
CCP1►RC2
CCP2►RC1
CCP3►RC6
#include "C:\\projects\\3Phase_PWM\\3phase_PWM_Auto.h"
unsigned char P1_index, P2_index, P3_index; // pointers to sine table
unsigned char TableSize; // number of entries in the sine table
int FrequencyValue = 0;
const unsigned char Sine_Table[90] = {127,136,145,153,162,170,179,187,194,202,209,215,
221,227,232,237,241,245,248,250,252,253,254,254,253,252,250,248,245,241,237,
232,227,221,215,209,202,194,187,179,170,162,153,145,136,127,118,109,101,92,
84,75,67,60,52,45,39,33,27,22,17,13,9,6,4,2,1,0,0,1,2,4,6,9,13,17,22,27,33,
39,45,52,60,67,75,84,92,101,109,118};
//*******************************************************************************
//
void UserInterrupt()
{
#asmline SETPCLATH UserIntReturn,-1 ; SETPCLATH for interrupt routine
#asmline goto UserIntReturn ; Assembler - go back to interrupt routine
}
//*******************************************************************************
//
void UserInitialise()
{
TableSize = sizeof(Sine_Table);
P1_index = 0; // reference phase angle = 0 degrees
P2_index = TableSize / 3; // phase angle = 120 degrees
P3_index = P2_index * 2; // phase angle = 240 degrees
ADCON0 |= (1 << ADGO); // start a new conversion
}
//*******************************************************************************
//
void UserLoop()
{
}
//*******************************************************************************
// called when ADC conversion is complete
void ADC_Finished()
{
FrequencyValue = ((int)ADRESH << 8) + (int)ADRESL; // full ADC result
FrequencyValue >>= 4; // scale to 8-bits
ADCON0 |= (1 << ADGO); // start a new conversion
}
//*******************************************************************************
// called when timer 0 overflows
void T0_Overflow()
{
if(++P1_index == TableSize) P1_index = 0; // point to next sine value
if(++P2_index == TableSize) P2_index = 0;
if(++P3_index == TableSize) P3_index = 0;
SetPWM1Volts(Sine_Table[P1_index]);
SetPWM2Volts(Sine_Table[P2_index]);
SetPWM3Volts(Sine_Table[P3_index]);
TMR0 = FrequencyValue; // reload with sine stepping rate
}
Assuming you actually need to maintain constant torque, there are two methods:
1. adjust the low and high PWM values according to the speed so the resulting voltage changes,
2. keep the PWM the same and adjust the DC supply to the PWM drivers.
For method 1, you have to decide the voltages needed at lowest speed and scale the PWM figures accordingly. Then multiply the table values by a figure derived from the speed before sending them to the PWM generators. Make sure the multiplied number does not exceed the maximum to PWM can accept or you will get a 'wrap around' effect in the voltage and severe waveform distortion.
For method 2. you need a method to control the DC source to the motor drivers, this could be another PWM signal or a signal generated by any other analog means. As the frequency increases, the DC supply should be increased in proportion.
There is a good reference at **broken link removed** but the code examples are for TI DSP products. The flow charts and text will explain the principles quite well.
You also need to decide whether you are simply producing a constant V/F and hoping the motor responds or if you are going to employ a feedback mechanism to combat load variations.
Brian.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?