The single-chip microcomputer P IC l6F72 is the mainstream control chip of the current battery vehicle controller. It is combined with two 74HC27 (3-input NOR gate circuit ); one 74HC04D ( inverter ); one 74HC08D (dual-input AND gate) and one LM358 (dual op amp) to form a relatively typical brushless battery vehicle controller with the function of automatic switching between 60° and 120° drive modes. Its basic block diagram is shown in Figure 1. The actual object surveying and mapping schematic diagram is shown in Figure 2 (the data in the figure are all unlocked and parked state data unless otherwise noted).
1. Circuit Introduction and Self-Test
When the electric door lock is turned on, the 48V battery DC is input to the controller through the electric door lock line. One way is sent to the ③ pin of U6 through R3, R13, R4, etc. for battery undervoltage detection, and the other way is sent to U13, U14, U15 to output +15V and +5V to power the IC and the final drive. The 16MHz crystal is connected to the pins 9 and 10 of the PIC16F72 microcontroller , and the R13 and C25 are connected to the pin 1 to form a reset circuit. When the electric door lock is unlocked and the microcontroller is powered on, it enters the initialization self-test state. It mainly detects:
1. The battery undervoltage detection circuit composed of R3, R73, R4, R11, C21, etc. (the typical value is 3.8V input to the pin 3 of U6). 2. The final current
detection and overcurrent protection circuit composed of R5, R6, U1, etc. (the normal value is 0V output from the pin 7 of U1, and about 3.6V output from the pin 1). 3. The reset signal of the throttle (the normal value is about 0.8V low level ). 4. The brake reset signal (the normal value is 4.8V high level input to the pin 7 of U6). 5. The phase signal of the brushless motor detected by the motor Hall element (normally, at least one Hall line input is 4.1V, and the others are 0V). The status after self-test is displayed by LED 2. The following are reference values (the specific display is related to the programming of the single-chip computer). Flash 1 Stop 1--Self-test passed normally Flash 2 Stop 1--Undervoltage Flash 3 Stop 1--LM358 fault Flash 4 Stop 1--Motor Hall signal fault Flash 5 Stop 1--Lower tube fault Flash 6 Stop 1--Upper tube fault Flash 7 Stop 1--Overcurrent protection Flash 8 Stop 1--Brake protection Flash 9 Stop 1--Handlebar ground wire disconnected Flash 10 Stop 1--Handlebar signal and handlebar power line short-circuited Flash 1 Stop 11--Handlebar signal not reset at power-on If the self-test passes normally, when the handlebar is turned, U6 mixes the carrier signal of the corresponding pulse width with the commutation conduction signal of the three-way drive upper and lower tubes according to the output voltage of the handlebar, so as to achieve the purpose of controlling the speed of the brushless motor. Different speeds correspond to different motor currents, and the driving speed is proportional to the motor commutation frequency . In the circuit, the final power tubes V1 and V2, V3 and V4 are respectively the upper and lower driving tubes of the brushless motor U phase; V5 and V6, V7 and V8 are respectively the upper and lower driving tubes of the brushless motor V phase; V9 and V10, Vll and V12 are respectively the upper and lower driving tubes of the brushless motor W phase. U2 is the lower tube driving IC, U4 is the upper tube driving IC; U3 and U5 are the upper and lower tubes R55 and R56 (constantan wire) are connected in series to the ground wire of the final power tube, so the current change of the final power tube will produce a voltage drop on R55 and R56, so the current detection circuit composed of R5, R6 and Ul can detect the size of the brushless motor current at any time to avoid overcurrent damage to the motor. The undervoltage protection circuit composed of R3, R73, R4, R11, C21, U6, etc., when the battery voltage drops to the set value, U6 stops outputting to avoid excessive discharge of the battery. In addition, U6 inputs the pre-set commutation signals for the 6 groups of upper and lower power tubes simulating three-phase AC respectively. These 6 groups of upper and lower power tubes must be turned on and off in strict order. Secondly, U6 processes the speed control voltage of the handlebar and outputs the PWM (i.e. pulse width modulation ) signal and the commutation signal output by U6. The mixed output control voltage is superimposed in the subsequent circuit to control the conduction and cutoff of the 3 upper and lower power tubes respectively. 2. Fault inspection When inspecting, first eliminate the short circuit fault, especially the final power tube. On the electric door lock side, you can disconnect the electric door lock connector to measure the current. If it is normal about 65mA, it means that there is no short circuit in the front stage of the controller. Secondly, when there is no short circuit and the motor does not rotate, first check whether the initialization self-test conditions are normal (as described above). A simple method to check the quality of the motor Hall element: open the electric door lock, use the pointer type (the same below) multimeter without damping AC 10V gear to measure the ?, ? and ? pins of U6, that is, the input terminals of the motor Hall w, V and u phases, and slowly turn the motor wheel by hand. If you see the pointer on the meter swinging around 0~4V, it means that the motor Hall element is basically normal. The method to check whether the controller front stage is normal is to first pass the controller self-test, observe LED2, that is, the self-test light, to see whether it is normal or not. If LED2 flashes once and stops once, it means that the self-test has passed. Otherwise, check the related fault circuit indicated by the self-test light. After the self-test passes normally, use the multimeter AC 10V gear to test U6's ○26, ○27 and ○28 pins (that is, the lower tube commutation signal), turn the handle to make the motor wheel rotate as slowly as possible, if the needle swings around 0~4V, then measure U6's 23, 24 and ⑤ pins (that is, the upper tube commutation signal), the needle should swing around 0~2V. Then measure the 13th foot of U6 (i.e. the PWM output foot). If the voltage at this point changes with the rotation of the handlebar and is between 0V and 4.8V, it means that the output of the single-chip microcomputer U6 is basically normal. The motor current detection and protection circuit is composed of current sampling nozzles R5, R6 and U1. When the brushless motor current increases to make the voltage of the 2nd foot of U1 greater than the 3rd foot by about 0.23V, the voltage of the 1st foot of U1 jumps to a low level, and the 21st foot of U6 becomes a low level, and the single-chip microcomputer enters the overcurrent protection state. C program of the electric bicycle drive system controlled by the PIC single-chip microcomputer #include //Electric vehicle double closed-loop program, using a double closed-loop method to control the motor to obtain the best zh speed performance, and can //limit the maximum current of the motor. This application uses two CCP components, of which CCP1 is used for PWM output to control //the motor voltage; CCP2 is used to trigger AD, timer TMR2, TMR1, INT interrupt, RB port level change interrupt, //watchdog and 6 general I/O ports
#define AND 0xe0 //State acquisition 5, 6, 7 bits
#define CURA 0X0a //Sum of current loop proportional and integral coefficients
#define CURB 0X09 //Current loop proportional coefficient
#define THL 0X6400 //Current loop maximum output
#define FULLDUTY 0X0FF //High level time when duty cycle is 1
#define SPEA 0X1d //Sum of speed loop proportional and integral coefficients
#define SPEB 0X1c //Speed loop proportional coefficient
#define GCURHILO 0X0330 //Speed loop maximum output
#define GCURH 0X33 //Maximum given current
#define GSPEH 0X67 //Maximum speed given
#define TSON 0X38 //Handle opening voltage 1.1 V, TSON*2 is the handle opening voltage after braking, i.e.
//2.2 V
#define VOLON 0X4c //Low voltage protection restart voltage 3.0 V i.e. 33 V
#define VOLOFF 0X49 //Low voltage protection shutdown voltage 2.86 V i.e. 31.5 V
volatile unsigned char DELAYH,DELAYL,oldstate,speed,
speedcount,tsh,count_ts,count_vol,gcur,currenth,
voltage; //Register definition
static bit sp1,spe,ts,volflag,spepid,lowpower,
off,shutdown,curpid; //Flag definition
static volatile unsigned char new[10]={0xaf,0xbe,0xff,0x7e,0xcf,
0xff,0xd7,0x77,0xff,0xff}; //Status register table
//------------PIC16F877 initialization subroutine------------
void INIT877()
{
PORTC=0X0FF; //Turn off all MOSFETs
TRISC=0X02; //Set port C output
PIE1=0X00; //Interrupt register initialization, turn off all interrupts
TR ISA =0XCF; //Set RA4, RA5 output
TRISB=0XEF; //RB port high three-bit input, collect the motor three-phase Hall signal
PORTC=new[(PORTB&AND)>>5]; //Collect the first Hall signal, and output the corresponding signal, turn on
//two MOS tubes
T2CON=0X01; //TMR2 4 -division
CCPR1L=0X0FF; //Initial PWM output full high
CCP1CON=0X0FF; //CCP1 set to PWM mode
CCP2CON=0X0B; //CCP2 set to special mode to trigger AD
ADCON0=0X81; //AD clock is divided by 32, and AD is enabled, select AN0 channel to collect
the handle voltage
TMR2=0X00; //TMR2 register initialization
TMR1H=0X00; //TMR1 register initialization
TMR1L=0X00;
T1CON=0X00; //TMR1 is divided by 1
CCPR2H=0X08;
CCPR2L=0X00; //Current sampling period is set to TAD=512 μs
PR2=0XC7; //PWM frequency is set to 5 kHz
ADCON1=0X02; //AD result left shift
OPTION=0XFB; //INT rising edge triggers
TMR2ON=1; //PWM starts working
I NTC ON=0XD8; //Interrupt setting GIE=1, PEIE=1, RBIE=1
ADIE=1; //AD interrupt enable
speedcount=0x00; //Speed counting register
speed=0x7f; //Speed holding register
spe=1; //Low speed flag
sp1=1; //Low speed flag
oldstate=0x0ff; //Initial state setting, different from other states
count_ts=0x08; //Current sampling 8 times, collect 1 handle
count_vol=0x00; //Sampling 256 handles, collect 1 Second battery voltage
ts=1; //Flag for collecting handle value
ADGO=1; //AD sampling enable
TMR1ON=1; //CCP2 component starts working
}
//------------Delay subroutine---------------
#pragma interrupt_level 1
void DELAY1(x)
char x;
{
DELAYH=x; //Delay parameter setting
#asm
DELAY2 MOV LW 0X06
MOV WF _DELAYL
DELAY1 DECFSZ _DELAYL
GOTO DELAY1
DECFSZ _DELAYH
GOTO DELAY2
#endasm
}
//-----------State acquisition subroutine----------------------
void sample()
{
char state1,state2,state3,x;
do {
x=1;
state1=(PORTB&AND); //Hall signal acquisition
DELAY1(x);
state2=(PORTB&AND);
}while(state1-state2); //When the three sampling results are different, continue to collect the state
if(state1-oldstate!=0) //See if the sampling result is the same as the last time, if not
//then execute
{oldstate=state1; //Set this state to the old state
state1=(oldstate>>5);
PORTC=new[state1]; //Port C outputs the corresponding signal to trigger the two MOS tubes
if(sp1==1){spe=1;sp1=0;}
else { //If the speed is very low, set spe to 1
spe=0;sp1=0;
speedcount<<=1;
state3=(TMR1H>>2); //Otherwise, spe=0, count the speed
speed=speedcount+state3; //speed The register is incremented by 1 every 256 μs
}
speedcount=0;
}
}
//-----------------AD sampling subroutine----------------------
void AD()
{
char x;
ADIF=0; //Clear AD interrupt flag
if(ts==1){ //If it is handle sampling, then sample the handle value
CHS0=1; //Select the current sampling channel
count_vol=count_vol+1; //Battery sampling count register
spepid=1; //Set the speed closed-loop operation flag
ts=0;tsh=ADRESH; //Store the handle value
if(count_vol==0) { //If the battery sampling time is up, select the AN2 channel to collect the battery voltage
CHS0=0;CHS1=1;volflag=1;x=1;DELAY1(x);ADGO=1;
}
}
else if(volflag==1) { //Battery sampling is completed, perform corresponding processing
CHS1=0;CHS0=1;volflag=0;voltage=ADRESH;lowpower=1;
}
else { //Otherwise, the interrupt is a sampling current interrupt
speedcount=speedcount+1; //speedcount register plus 1, used as the speed measurement
if(speedcount>0x3d) sp1=1; //If the speed is lower than 1 000 000 μs/(512 μs*3eh*3)
//, it is considered to be in a low-speed state
currenth=ADRESH;
curpid=1;
count_ts=count_ts-1;
if(count_ts==0) { //If the handle time is up, transfer to the handle sampling channel
CHS0=0;count_ts=0x08;ts=1;x=1;DELAY1(x);ADGO=1;
}
}
}
//-------------Brake processing subroutine------------------
void BREAKON()
{
char x;
off=0; //off is cleared, if it is interference, it will not be reset
shutdown=0;
if(RB0==1) { //If the brake signal is true, stop outputting voltage
ADIE=0; //Turn off AD interrupt
INTE=0; //turn off brake interrupt
CCPR1L=FULLDUTY; //output voltage 0
TMR1ON=0; //turn off CCP2, no longer trigger AD
for(;ADGO==1;) continue;//if sampling is in progress, wait for sampling to end
ADIF=0; //clear ADIF bit
CHS0=0; //select channel 0 sampling handle
CHS1=0;
x=1;
DELAY1(x);
do {
ADGO=1;
for(;ADIF==0;)continue;
ADIF=0;
CCPR1L=FULLDUTY;
asm("CLRWDT");
tsh=(ADRESH>>1);
}while(tsh>TSON||RB0==1); //when the handle value is greater than 2.2 V or the brake is still on, execute
the following statement
off=1; //set reset flag
}
}
//---------under-protection subroutine-------------------
void POWER()
{
char x;
lowpower=0;
voltage>>=1; //Convert the voltage value to 7 bits to facilitate single-byte operation
if(voltage
ADIE=0;
INTE=0;
TMR1ON=0;
CCPR1L=FULLDUTY;
for(;ADGO==1;)continue;
ADIF=0;
CHS0=0;CHS1=1;
x=1;
DELAY1(x);
do{ADGO=1;
for(;ADIF==0;)continue;
ADIF=0;
voltage=(ADRESH>>1);
CCPR1L=FULLDUTY;
asm("CLRWDT");
}while(voltage
off=1; //Set reset flag
}
}
//------------Current loop operation subroutine-----------------
void CURPI()
{ static int curep=0x00,curek=0x00,curuk=0x00;
union data{int pwm;
char a[2];}b; //Define current loop operation register
curpid=0; //Clear current operation flag
curep=curek*CURB; //Calculate the product of the last deviation and the proportional coefficientif
(currenth<2)currenth=2; //If the sampled current is zero, it is considered that there is a small current to help
//reduce the speedcurrenth
>>=1;
curek=gcur-currenth; //Calculate this deviationcuruk
=curuk+curek*CURA-curep; //According to the closed-loop PI operation method, get the output result this time,
//and process the result
belowif(curuk<0x00) { //If the output is less than zero, it is considered that the output is
zerocuruk=0;CCPR1L=FULLDUTY;CCP1X=0;CCP1Y=0;
}
else if(curuk-THL>=0) { //If the output is greater than the limit value, the maximum voltage is outputcuruk
=THL;CCPR1L=0;CCP1X=0;CCP1Y=0;
}
else { //Otherwise, output the corresponding high level time to the CCPR1 register in proportionb.pwm
=THL-curuk;
b.pwm<<=1;
CCPR1L=ba[1]; //CCPR1L=(b.pwm>>8)&0x0ff; set the high nibble of the PWM register
if(b.pwm&0x80!=0) CCP1X=1;
else CCP1X=0;
if(b.pwm&0x40!=0) CCP1Y=1;
else CCP1Y=0;
}
}
//---------------Speed loop calculation subroutine-----------------------
void SPEPI()
{ static int speep=0x00,speek=0x00,speuk=0x00;
int tsh1,speed1; //Speed register definition
spepid=0; //Clear speed calculation flag
if(spe==1) speed1=0x00; //If the speed is too low, it is considered to be zero
else speed1=0x7f-speed; //Otherwise calculate the actual speed
if(speed1<0) speed1=0;
speep=speek*SPEB;
tsh1=tsh-0x38; //Get the handle value for calculationspeek
=tsh1-speed1;
if(tsh1<0) {speuk=0;gcur=0;} //When the handle value is lower than 1.1 V, the handle setting is considered to be zeroelse
{ //Otherwise, calculate the corresponding speed loop outputif
(tsh1>=GSPEH) //Limit the maximum speedtsh1
=GSPEH;
speuk=speuk+speek*SPEA-speep; //Calculate the speed loop outputif
(speuk<=0X00) {speuk=0x00;gcur=0x00;}//Speed loop output processingelse
if(speuk>GCURHILO) { //Speed loop output limit, that is, limit the maximum current to about 12 A
speuk=GCURHILO;gcur=GCURH;}
else { //Output in speed regulation state
gcur=(speuk>>4)&0x0ff;
}
}
}
//-----------Main program----------------------------
main()
{
for(;;){
INIT877(); //After the MCU is reset, initialize it first
off=0; //Clear reset flagfor
(;off==0;) { //If the reset flag is zero, execute the following program, otherwise resetif
(curpid==1) CURPI(); //Current PI operationelse
if(spepid==1) SPEPI(); //Speed PI operationelse
if(lowpower==1) POWER();
else if(shutdown==1) BREAKON();
asm("CLRWDT");
}
}
}
//---------Interrupt service subroutine---------------------
#pragma interrupt_level 1
void interrupt INTS(void)
{
if(RBIF==1) {RBIF=0;sample();}
else if(ADIF==1) AD();
else if(INTF==1) {shutdown=1;INTF=0;} //Brake interrupt comes, set brake flag
1 Reset port 5V
2 Current detection <1v
3 Battery voltage detection >3V
4 Motor phase selection >2V 120 degrees otherwise 60 degrees
5 Turn signal 1-4V
7 Brake signal >4V
8, 19 Ground
13 PWM signal output
15, 16, 17 Motor brake signal input terminal
18 Indicator light
20 Power supply 5V
21 Overcurrent Normally 5V
23-28 Drive signal output.
Previous article:Design and application of PIC12F675 single chip microcomputer in human body detector
Next article:Homemade PIC Programmer
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- 【Silicon Labs Development Kit Review】+PG22 Hardware Resources
- MSP430fr6989 serial port DMA sending experimental routine
- Live FAQ|Microchip's Trusted Platform for CryptoAuthentication Series
- 【Qinheng Trial】7. TouchKey
- Former Chairman explains the new PCIe5.0 specification. Tektronix invites you to watch and win prizes
- Today I thought of the "collection economy", office workers are very busy
- In adjustment
- RISC-V MCU Development (Part 14): Help and Feedback
- PCB design, which tool software is the best?
- IAR settings let the code run from reset instead of main