Tahmid
Advanced Member level 6
- Joined
- Jun 17, 2008
- Messages
- 4,756
- Helped
- 1,798
- Reputation
- 3,588
- Reaction score
- 1,656
- Trophy points
- 1,413
- Location
- Berkeley, California
- Activity points
- 30,586
unsigned char sin_table[32]={0, 18, 36, 54, 72, 88, 104,
119, 132, 145, 155, 165, 173, 179, 183, 186, 187, 186,
183, 179, 173, 165, 155, 145, 132, 119, 104, 88, 72, 54, 36, 18};
Tahmid, i have seen your blog "SINE WAVE GENERATION AND IMPLEMENTATION USING DSPIC33" . there i didn't find the code to configure the oscillator.
i am using another chip DSPIC33FJ32MC202 to generate SPWM, i want to configure the oscillator of this chip using internal FRC with PLL to get a Fcy of 40MHz. i am facing the problem in configuring the oscillator,i have seen the reference manual ,there a code was given in CCS. its not compiling in mikroc, can you help me to convert this code for mikroc. below is the code that i have taken from the reference manual
Example 7-2 illustrates code for using the PLL with a 7.37 MHz Internal FRC. (See also
7.11 “Clock Switching” for clock switching example code.)
Example 7-2: Code Example for Using the PLL with 7.37 MHz Internal FRC
// Select Internal FRC at POR
_FOSCSEL(FNOSC_FRC);
// Enable Clock Switching and Configure
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF);
int main()
{
// Configure PLL prescaler, PLL postscaler, PLL divisor
PLLFBD = 41; // M = 43
CLKDIVbits.PLLPOST=0; // N2 = 2
CLKDIVbits.PLLPRE=0; // N1 = 2
// Initiate Clock Switch to Internal FRC with PLL (NOSC = 0b001)
__builtin_write_OSCCONH(0x01);
__builtin_write_OSCCONL(0x01);
// Wait for Clock switch to occur
while (OSCCONbits.COSC! = 0b001);
// Wait for PLL to lock
while(OSCCONbits.LOCK! = 1) {};
}
void InitClock(){
CLKDIV = 0; // PLLPOST -> DIV BY 2
PLLFBD = 40; // 7.37MHz/2 * 21 * 2 for VCO output
//configured for 77.385 MHz FOSC
//#define OSCCONH 0x0743
//#define OSCCONL 0x0742
asm{
//Place the New Oscillator Selection (NOSC=0b001) in W0
MOV #1, WREG
//OSCCONH (high byte) Unlock Sequence
//MOV #Lo_Addr(OSCCONH), w1
MOV #0x0743, w1
//MOV #OSCCONH, w1
MOV #0x78, w2
MOV #0x9A, w3
MOV.B w2, [w1] // Write 0x78
MOV.B w3, [w1] // Write 0x9A
//Set New Oscillator Selection
//MOV WREG, OSCCON
MOV.B WREG, [w1]
//Place 0x01 in W0 for setting clock switch enabled bit
MOV #0x01, w0
//OSCCONL (low byte) Unlock Sequence
//MOV OSCCONL, w1
MOV #0x0742, w1
MOV #0x46, w2
MOV #0x57, w3
MOV.B w2, [w1] // Write 0x46
MOV.B w3, [w1] // Write 0x57
//Enable Clock Switch
MOV.B w0, [w1]
//Request Clock Switching by Setting OSWEN bit
wait:
btsc 0x0742, #0 // OSCCONL, #0
bra wait
}
}
unsigned char sin_table[32]={0, 18, 36, 54, 72, 88, 104,
119, 132, 145, 155, 165, 173, 179, 183, 186, 187, 186,
183, 179, 173, 165, 155, 145, 132, 119, 104, 88, 72, 54, 36, 18};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
void interrupt(){
if (TMR2IF_bit == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge
}
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
TMR2IF_bit = 0;
}
}
void main() {
SET_FREQ = 410;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
PR2=187; ///for 16Khz at 12MHZ of quartz
TRISB=0x3F;// PWM output pins
CCP1CON = 0x4C;
TMR2IF_bit = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISB=0; //defined my self for PWM out
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1);
}
so what do you propose?On the board I don't have those capacitors but also it is not working;what should be the reason??
What is bootstrap driver??In the datasheet I found saying that the ICL7667 can be used to control the DC_DC Converters meanwhile those ones are made by MOSFET??And also for the first stage of my DC-AC converter the push pull circuit made up by two MOSFETs has been controlled using those ICL7667 and the MOSFET are working correctly.
Hello Tahmid may I know if the circuit as driver you provided on your blog https://tahmidmc.blogspot.com/2012/12/low-side-mosfet-drive-circuits-and_23.html can be used for driving H-bridge?I have a problem with my H-bridge which is giving 7VAC at output when I apply controlling signal and after powering the H-bridge with 440V I get the same voltage;I am using ICL7667 as MOSFET driver for IRFP460Z but I am thinking that those drivers are the ones which has to be replaced so because I can't find other drivers I am thinking to use transistors for driving my H-bridge.
Any suggestions please!!
Thanks.Please help
unsigned char sin_table[32]={0, 18, 36, 54, 72, 88, 104,
119, 132, 145, 155, 165, 173, 179, 183, 186, 187, 186,
183, 179, 173, 165, 155, 145, 132, 119, 104, 88, 72, 54, 36, 18};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
void interrupt(){
if (TMR2IF_bit == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge
}
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
TMR2IF_bit = 0;
}
}
void main() {
SET_FREQ = 410;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
PR2=187; ///for 16Khz at 12MHZ of quartz
TRISB=0x3F;// PWM output pins
CCP1CON = 0x4C;
TMR2IF_bit = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISB=0; //defined my self for PWM out
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1);
}
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?