thunaivendan
Member level 3
- Joined
- Apr 19, 2013
- Messages
- 61
- Helped
- 0
- Reputation
- 0
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Chennai, Tamil Nadu, India
- Activity points
- 1,723
/* Main.c file generated by New Project wizard
*
* Created: Tue Jun 4 2024
* Processor: PIC16F877A
* Compiler: HI-TECH C for PIC10/12/16
*/
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#define QA1 RA0
#define QA2 RA1
#define QA3 RA2
#define QA4 RA3
#define SW RE0
#define SW1 RE1
#define _XTAL_FREQ 20000000
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_ON & CPD_OFF & WRT_OFF & CP_OFF);
__CONFIG(0x3F72);
//void forwarddirection();
//void reversedirection();
void main()
{
TRISA = 0x00;
TRISE = 0x00;
// TRISE = 0x00;
while(1)
{
if (SW == 1)
{
QA1 = 1;
__delay_ms(1);
QA2 = 0;
__delay_ms(1);
QA1 = 1;
__delay_ms(1);
QA2 = 0;
__delay_ms(1);
}
if (SW1 == 1)
{
QA2 = 1;
__delay_ms(1);
QA1 = 0;
__delay_ms(1);
QA2 = 1;
__delay_ms(1);
QA1 = 0;
__delay_ms(1);
}
}
}
I gave the D.C voltage 15 v to VC pinIt isn't at all clear what you are trying to do. Your "while" loop just makes RA1 high and RA2 low, regardless of SW1. The bootstrap configuration of the IR2112 relies on it being driven at frequency high enough that C3/C5 can maintain enough voltage to fully turn on the top MOSFETS on but you drive it with DC and there seems to be no supply to the IR2112s anyway.
Brian.
My intention if switch pressed dc motor should forward,if second switch dc motor reverse biased,please tell me is this correct.what are all motor should connect to this circuitI gave the D.C voltage 15 v to VC pin
Hi Brian,There are several problems in your electrical design and your software.
Hardware first:
The IR2112 is designed to be driven from an alternating logic level, usually a PWM signal. The VB pin has the supply to the top gate driver on it. They way it turns the top MOSFET on is to generate the VB voltage by charging C5 through D1 when the negative end of C5 is near ground voltage (bottom MOSFET turned on) then when the bottom MOSFET turns off, VS rises and 'pushes' the charge on C5 to the VB pin. Note that when this happens, D1 is reverse biased so it doesn't conduct back to the supply line. If you don't drive the IR2112 with a high frequency, C5 will never charge enough to produce VB.
I would also suggest increasing R5 and R6 to at least 10K, otherwise you waste 5mA through them when the switches are closed. Also add a pull-up resistor and a capacitor to ground on the MCLR pin (as shown in the data sheet) so the reset is delays slightly after the supply is switched on. It also lets you reset the PIC by pulling MCLR low without shorting out the supply.
Software:
Your while{} loop tests SW1 twice for being high (switch not pressed), I think you intended to test the other switch (SW) instead. Even then, you should not toggle both QA1 and QA2 twice, just set them to the required state once. It would be wise to add code to check both switches though, think what happens if both are pressed at the same time.
Brian.
#define released 0
#define pressed 1
#define SW_Fwd RE0
#define SW_Rev RE1
if (SW == 1)
{
...
}
if (SW1 == 1)
{
...
}
if (SW_Fwd == pressed)
{
...
}
if (SW_Rev == pressed)
{
...
}
Hi,
when posting code....
* please use the [Insert Code] button marked with [ </> ]
* please document your code (if you are too lazy to write what the code is supposed to do ... why should we spend time to find out the same?)
* use meaningful directives ...
like:
Code:#define released 0 #define pressed 1 #define SW_Fwd RE0 #define SW_Rev RE1
then the lines:
***
Code:if (SW == 1) { ... } if (SW1 == 1) { ... }
become meaningful:
Code:if (SW_Fwd == pressed) { ... } if (SW_Rev == pressed) { ... }
Please explain line:
"SW=0;SW1=0;"
BTW:
The generation of the bridge control signal in a while loop is the worst yo can do. There should be PWM, or at least timer interrupts in your PIC)
It changes behaviour (timing) with every line of code you add. It seems you don´t know how it works (otherwise you should give a timing diagram of how you expect the signals to look like ... so we can validate it)
Do you uderstand the meaning of slow_decay and fast_decay ... and how it influences RPM, torque and braking (current). If not: read about it.
Klaus
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
#define release 0
#define pressed 1
#define QA1 RA0
#define QA2 RA1
//#define QA3 RA2
//#define QA4 RA3
#define SW_Fwd RE0
#define SW_Rev RE1
#define _XTAL_FREQ 20000000
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_ON & CPD_OFF & WRT_OFF & CP_OFF);
__CONFIG(0x3F72);
//void forwarddirection();
//void reversedirection();
void main()
{
TRISA = 0x00;
TRISE = 0x00;
// TRISE = 0x00;
// SW=0;SW1=0;
while(1)
{
if (SW_Fwd== pressed)
{
QA1 = 1;
__delay_ms(1);
QA2= 0;
__delay_ms(1);
QA1= 1;
__delay_ms(1);
QA2 = 0;
__delay_ms(1);
}
if (SW_Rev == pressed)
{
QA2 = 1;
__delay_ms(1);
QA1 = 0;
__delay_ms(1);
QA2= 1;
__delay_ms(1);
QA1 = 0;
__delay_ms(1);
}
}
}
PR2= 0xFF;
CCP1CON=0x3F;
CCP2CON=0x3F;
T2CON = 0x7F;
based these values i can able to generate the PWM but its included in the code with in IF condition as CCP1CON = 0x3f;its switiching will happen but motor is not running.
void main()
{
TRISA = 0x00;
TRISE = 0xFF;
TRISC = 0x00;
PR2= 0xFF;
// CCP1CON=0x3F;
// CCP2CON=0x3F;
T2CON = 0x7F;
// TRISE = 0x00;
// SW=0;SW1=0;
while(1)
{
if (SW_Fwd== pressed)
{
CCP1CON=0x3F;
// QA1 = 1;
// __delay_ms(1);
// QA2= 0;
// __delay_ms(1);
//QA1= 1;
//__delay_ms(1);
// QA2 = 0;
// __delay_ms(1);
}
if (SW_Rev == pressed)
{
CCP2CON=0x3F;
// QA2 = 1;
// __delay_ms(1);
// QA1 = 0;
//__delay_ms(1);
// QA2= 1;
// __delay_ms(1);
// QA1 = 0;
// __delay_ms(1);
}
}
}
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
//#define release 0
//#define pressed 1
#define QA1 RA0
#define QA2 RA1
//#define QA3 RA2
//#define QA4 RA3
//#define SW_Fwd RE0
//#define SW_Rev RE1
#define _XTAL_FREQ 20000000
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_ON & CPD_OFF & WRT_OFF & CP_OFF);
__CONFIG(0x3F72);
//void forwarddirection();
//void reversedirection();
void main()
{
TRISA = 0x00;
TRISE = 0xFF;
TRISC = 0x00;
PR2= 0xFF;
CCP1CON=0x3F;
// CCP2CON=0x3F;
T2CON = 0x7F;
// TRISE = 0x00;
// SW=0;SW1=0;
while(1)
{
CCPR1L =5;//CCPR2L = 50;
// if (SW_Fwd== pressed)
// {
/// CCP1CON=0x3F;
// QA1 = 1;
// __delay_ms(1);
// QA2= 0;
// __delay_ms(1);
//QA1= 1;
//__delay_ms(1);
// QA2 = 0;
// __delay_ms(1);
// }
// if (SW_Rev == pressed)
// {
// CCP2CON=0x3F;
// QA2 = 1;
// __delay_ms(1);
// QA1 = 0;
//__delay_ms(1);
// QA2= 1;
// __delay_ms(1);
// QA1 = 0;
// __delay_ms(1);
// }
}
}
void main()
{
TRISA = 0x00;
TRISE = 0xFF;
TRISC = 0x00;
PR2= 0xFF;
// CCP1CON=0x3F;
// CCP2CON=0x3F;
T2CON = 0x7F;
// TRISE = 0x00;
// SW=0;SW1=0;
while(1)
{
if (SW_Fwd== pressed)
{
CCP1CON=0x3F;
// QA1 = 1;
// __delay_ms(1);
// QA2= 0;
// __delay_ms(1);
//QA1= 1;
//__delay_ms(1);
// QA2 = 0;
// __delay_ms(1);
}
if (SW_Rev == pressed)
{
CCP2CON=0x3F;
// QA2 = 1;
// __delay_ms(1);
// QA1 = 0;
//__delay_ms(1);
// QA2= 1;
// __delay_ms(1);
// QA1 = 0;
// __delay_ms(1);
}
}
}
#include <htc.h>
#include <stdio.h>
#include <stdlib.h>
//#define release 0
//#define pressed 1
#define QA1 RA0
#define QA2 RA1
//#define QA3 RA2
//#define QA4 RA3
//#define SW_Fwd RE0
//#define SW_Rev RE1
#define _XTAL_FREQ 20000000
//__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & BOREN_OFF & LVP_ON & CPD_OFF & WRT_OFF & CP_OFF);
__CONFIG(0x3F72);
//void forwarddirection();
//void reversedirection();
void main()
{
TRISA = 0x00;
TRISE = 0xFF;
TRISC = 0x00;
PR2= 0xFF;
CCP1CON=0x3F;
// CCP2CON=0x3F;
T2CON = 0x7F;
// TRISE = 0x00;
// SW=0;SW1=0;
while(1)
{
CCPR1L =5;//CCPR2L = 50;
// if (SW_Fwd== pressed)
// {
/// CCP1CON=0x3F;
// QA1 = 1;
// __delay_ms(1);
// QA2= 0;
// __delay_ms(1);
//QA1= 1;
//__delay_ms(1);
// QA2 = 0;
// __delay_ms(1);
// }
// if (SW_Rev == pressed)
// {
// CCP2CON=0x3F;
// QA2 = 1;
// __delay_ms(1);
// QA1 = 0;
//__delay_ms(1);
// QA2= 1;
// __delay_ms(1);
// QA1 = 0;
// __delay_ms(1);
// }
}
}
yes, unfortunately...I am not using any timer to generate the PWM
I will agree your commentsyes, unfortunately...
and
* you don´t press the [ CODE ] button
* and you don´t explain why you repeat the port setting
* and you don´t comment your code
* and you don´t change the 100% duty cycle on HIN
* and you don´t change the FWD/REV problem
* and so on..
So we tell you what to do .. but you ignore it. I call our effort as a waste of time.
We say: you have to turn right .. next post you write: I did not turn right.
I have to leave...
Klaus
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?