33
GROUP A25 | FOURNIER Maxime /GOUBET Lionel In association with BOUCLET Nicolas and DEFORGE Etienne N 3 PROJECT REPORT : RADIO COMMAND

PROJECT REPORT - lionel.goub.free.frlionel.goub.free.fr/==COURS==/N3/PROJET ELEC/Rappo…  · Web viewHaving at our disposal two microcontroller ST7, one for each board, we have

Embed Size (px)

Citation preview

PROJECT REPORT

GROUP A25 | FOURNIER Maxime /GOUBET LionelIn association with BOUCLET Nicolas and DEFORGE Etienne

(N3PROJECT REPORT: Radio command)

SYNOPSIS (pages)

General Presentation(3)

1st part: Hardware

I] H-Bridge(4)

II] Others hardware devices(5)

III] Schemas(6)

IV] Budget(9)

2nd part: Software

I] Transmitter

A) Initializations(10)

B) Data acquisition(10)

C) Neutral zone(11)

D) Data transmission mode(12)

II] Receiver

A) Initializations(14)

B) Data recovery mode(15)

C) LED information(16)

D) Control of the servo-motor(16)

E) Control of the DC current engine(18)

3rd part: Tests(20)

N3 PROJECT REPORT

Group A25

ROJE

General Presentation

At the end of the N3 year and for our electronic project, we were asked to use our acquired knowledge to create in group of two students a radio command to manage different functions. These functions could be used to control remotely a vehicle or a robot.

The different functions are:

Moving forward and backward using a DC engine with flexible speeds.

Turning left or right with a servo-motor and a flexible steering angle.

Managing a switch of a LED (on or off) which symbolizes for example cars headlights.

So we have to create two boards, a transmitter one on which we connect the joystick (for the 4 directions) and the switch (for the LED) and where we acquire the corresponding data in order to transmit it properly with a suitable frame. And a receiver one where we use this data to generate the necessary signals to pilot the devices described above.

Having at our disposal two microcontroller ST7, one for each board, we have to produce the code and create the circuit applets to satisfy to the schedule of conditions.

In this file you will find a precise description of the lead of our project, with reflections about the different ways of doing something, the choices made and the tests on specific parts of the circuit or of the program.

(LED10010110transmitterLEDLEDreceiverDC engineServo motorST7receiverST7transmitterjoystickSwitchl/rfor/back)

(3)

1st part : HardwareI] H-Bridge

Description: the H-bridge, an interface power to drive the DC current engine.

At the beginning, we have seen that there will be a problem with the DC engine, if we don't put anything between the ST7 and the engine. The H-bridge is this thing. It permits to have enough power to drive the engine correctly thanks to the mother board.

At the beginning, we have tried to do it with traditional transistor, but the power was not sufficient. Finally, we use MOSFET transistor, which permits us to drive correctly the engine. The ST7 usually functions with 10mA current, while the DC engine needs at least 1A. The H-bridge makes the link between the microcontroller and the engine.

Thanks to the H-bridge, the DC engine can be run forwards or backwards. This facility is possible with the transistors. Theoretically, we can use switches to run the feel rotation. But using a transistor is more useful for the commutation. Moreover, a transistor can amplify the current, and can be easier controlled by numerical or analogical signals. The diodes, which are included in our MOSFET transistors, are here to protect the transistors from the falls of voltage. These falls can generate high current, and roast any components.

One other problem, in controlling DC engine, is that the engine needs an important voltage to start. The solution we found is to feed the DC engine with the constant voltage it needs to start. The transistors will control the speed of the engine, and the feel rotation.

The diodes are here to protect the transistors against the over-voltages of the DC engine.

According to the sense of the current, the transistors will function in saturated or blocked mode. Here is little explanation of the operation of the H-bridge. The transistors are represented by switches. Once the DC engine turns in one direction:

In this direction, the switches 1 and 4 are saturated, and the switches 2 and 3 are blocked.

In this direction, the switches 2 and 3 are opened, while the 1 and 4 are closed.

We can see that the DC engine don't turn in the same direction according to which switch is opened or closed. The voltage source in the diagram is the start engine necessary voltage.

About the LEDs, a resistor is placed before to limit the current going in the LED.

The capacitors are made to limit the influence of the parasites and the noise. (see Test n4 p25)

II] Others hardware devices

Converter 12V->5V DC-DC (78L05)

On the receiver board, we feed with a 12V tension, but the ST7 need a 5V tension. So we use a regulator Step-down to reach the tension wanted. To stabilize the tension, we put two capacitors on the two sides of the regulator.

An option: the battery

An option for a battery is available on our printed card. We couldn't realize it because of a financial problem. But everything on the card is ready to welcome a battery. So we put a jump to be able to choose between a basic alimentation 5V and the tension from the battery. The power connector is here to be able to add the card of the battery when we want.

The reverser transistor

The monitors informed us that the transmitter data need to be reversed. Considering that the transmission is out of order, we used a wire to replace the transmission. So we dont need any more to reverse the data.

III] Schemas

Transmitter:

RECEIVER

H-Bridge

IV] Budget

Quantit

Dsignation

Prix unitaire ()

Prix en

2

Bouton poussoir

0,70

1,40

2

Cavalier

0,07

0,14

4

Condensateur 100nF

0,10

0,40

1

Condensateur 330nF

0,10

0,10

1

Jump

0,27

0,27

2

LED rouge

0,13

0,26

1

Rgulateur 12V - 5V

0,70

0,70

4

Rsistance 10k

0,02

0,08

4

Rsistance 1k

0,02

0,08

4

Rsistance 4,7k

0,02

0,08

2

Transistor MOSFET N

0,91

1,82

2

Transistor MOSFET P

1,45

2,89

2

Transistor NPN BC547

0,08

0,15

Total

8,37

2nd part : Software

I] Transmitter

A) Initializations

CALL initialisation

Description: We initialize different registers for the set up of the program and that is the first function we call in the main program.

In it, we first set the main registers called PADDR and PAOR, to specify if we configure the pins of the A port as input or output and the type of each one. We do only use the PA7 as push-pull output. The other PA pins and every PB pins are configured as input pull-up. The PADR register in which we let the 0 value contains the values.

For this project we also need to use the radio Transmitter-receiver and we need to use the serial communication SCI explained in the datasheets of the ST7. There are other different registers to configure:

SCICR1 :

Set to 00000000 we do not use the 9th bit and do not use the different control provided by the 4 LSB

SCIBRR and SCIETPR: used for the frequency division

they are not used because we stay at the natural frequency of the ST7

SCISR : which manages the transfer.

Set to 11000000.

Actually, we set up the TDRE and the TC bit which is its reset value.

MCCSR: clock management

set to its reset value of 00000000, we stay at the CPU frequency (fCPU )and do not use the output clock (MCO).

ATCSR: timer control register set to its reset value 00000000

B) Data acquisition

CALL envoi_joydg

CALL envoi_joyavar

CALL envoi_cdeled

Description: We acquire the value of the different variable with the A/D converter.

The data coming from the joystick represent its position by a voltage between 0V and 5V. This value is converted by the A/D converter into a numerical value between 0 and 255. This converter is managed by the ADCCSR register which gives us information about the status of the conversion. (see Test n2 p21)

First we do switch on the converter:

LD A,#%00100000

LD ADCCSR,A

Then we wait until the acquisition of the value is complete:

pas_achevee1:

LD A,ADCCSR

CP A,#%10100000

JRNE pas_achevee1

When we get it, we can switch the converter off:

LD A,#%00000000

LD ADCCSR,A

The wanted coded value is written into the ADCDR register. 8 MSB in the ADCDRH and two LSB in the ADCDRL, we neglect those two quite insignificant bits which represent at the maximum 3/1028.

Finally, we load the value in the variable:

LD A,ADCDRH

LD joydg,A

C) Neutral zone

After having tested the joystick operation in practice, we realized that there was a problem in the middle of the position of the joystick which could bring us disturbance with the command of the servo-motor like the DC current engine. That is why we create a neutral zone which in the automatic value is the neutral value (127). (see Test n1 p20)

CALL gestion_zone_neutredg

Description: Into this procedure we modify the value given by the ADCDR register so as to fit it with the neutral zone.

We create two linear functions that way:

f(0) = 0

f(112 x 143) = 127

f(255) = 255

So

f(x) = (1 + 1/8 + 1/64)x if 0 x 112

f(x) = (1 + 1/8 + 1/64)x - 36 if 143 x 255

f(x) = 127 else

It is not very difficult to divide the value of joydg by entire powers of 2. Indeed, we do only have to shift it left to right once to divide it by 2, etc. That is the reason why we write the function like this.

First we compare the ADCDR value stocked in joydg value to 127, and then we try to know if it is in the neutral zone or not. After this we can modify it and restock it into the corresponding variable.

D) Data transmission mode

LD A,#%00000110

LD joydgh,A ; identification de la donnee envoye

LD A,#%00000100

LD joydgl,A

RLC joydg

RLC joydgh

With the code above, we separate the data in two words of 8 bits which contain half of the value and also an identifier to be able to recognize every transmitted data in the receiver ST7. It is possible to schematize the operation like this:

Joydg :

A

B

C

D

E

F

G

H

Will be send like this:

Joydgh: Joydgl:

0

1

1

0

A

B

C

D

0

1

0

0

E

F

G

H

Identifiers used:

Joydgh

0110

Joydgl

0100

Joyavarh

1010

Joyavarl

1000

led

0000

Right now it is possible to activate the transmission because our data is modified for the neutral zone, separated and identified:

SCICR2: manages the transmitter activating different options of it.

Set to 00001000 to enable the transmitter

Then, we check the SCISR register to verify if the bit7 is set or not. Whether it is not set, there is no transfer to the data register so we can write the desired value we want to transmit into the SCIDR register: the high one and then the low one.

The same procedure is lead for the joydg, the joyavar end the LED command. The ST7 program is running following those different steps starting again at the beginning every time it finishes.

After this, we receive the data in the ST7 receiver and treat it to generate the desired signals for the servomotor, the DC current engine and the lighting of the LED. (see Test n5 p25)

II] Receiver

A) Initializations

CALL initialisation

Description: We initialize the different registers that we are going to use in this microcontroller.

We are going to use the A pins from PA0 to PA3 as outputs respectively one for the LED command, one for the generation of the two PWM for the DC current engine and the last one for the servomotor. Each pin of the A port are configured in push-pull for the outputs(PA0 to PA3) and in pull-up for the inputs(PA4 to PA7). Port B pins are let as pull-up input include the PA6/RDI pin (the others B pins are not used).

LD A,#%00001111

LD PADDR,A

LD A,#%00000000

LD PBDDR,A

LD A,#%11111111

LD PAOR,A

LD A,#%11111111

LD PBOR,A

Every pin is initialized to 0 in the DR registers.

Because we use the SCI (Serial Communication Interface), we initialize the corresponding registers:

Like in the emitter we do not divide the frequency so the SCIBRR and the SCIERPR registers are initialized with 0.

We do not use either the extension to 9 bits (SCICR1 value is 0).

SCISR register, which manages the serial communication, takes its default value: 11000000.

The clock control registers MCCSR and ATCSR are initialized to the same value as in the emitter.

Because of the use of a H-bridge, we need to generate two PWM (Pulse Width Modulation) for the control of the DC current engine. We will not invert the signal and so the PWM0CSR and PWM1CSR are put to 0.

For an optimum performance of the DC current engine, it needs a signal with at least a frequency of 20 KHz, which means 50 s for the time base:

Because we use a 4 MHz quartz, and because the frequency at the entrance of the ST7 is automatically divided by 2, our time base is 0.5 s, we could reach the maximal authorized time base of 50 s. But for simplification with the division, we will define an acceptable time base of 32s, which represents 64 steps in the PWM.

So we can determine the ATR value:

ATR = (4095 64) = 4031 (0FBF in hexadecimal).

LD A,#$0F

LD ATR1H,A

LD A,#$BF

LD ATR1L,A

In its default position the engine mustn't rotate. So the DCR (Duty Cycle Register) equals the ATR:

LD A,#$0F

LD DCR0H,A

LD A,#$BF

LD DCR0L,A

Finally, we have to initialize all that concern the servomotor. First, we initialize the position of the servomotor on the middle :

LDA,#31

LDrapportcyclique,A

Then we clear the counter of interruptions,

CLRcompteurinterruption

CLR(compteurinterruption,Y)

And we activate the interrupt program

LDA,#253

LDLTARR,A

LDA,#%00000010

LDLTCSR2,A

LDA,#%00000000

LDEISR,A

LDA,#%00000000

LDEICR,A

RIM

After the initialization, we want to recover our data.

B) Data recovery mode

CALL reception

Description: We create a loop to get the five values (two for the joydg like for the joyavar and one for the LED).

First of all we change into the SCICR2 the value of the RE bit, to enable the receiver, the microcontroller starts to look for a start bit. Then we check into the SCISR register the RDRF bit which tells us if the data is fully received or not.

Identification:

The received value is written into the SCIDR register. We try to recognize it according to the identifiers established into the emitter ST7.If the LED identifier is recognized we directly do what is necessary on the PA0 output.

CALL modif_donnees

Description: After having identified the received data and if it is not the LED, it is necessary to recombine the separated values on two words of 8 bits each to get an exploitable data on 8 bits.

C) Led information

In the ST7 transmitter, the generation of the signal which is about to be sent into the SCIDR register is very simple. Indeed, there are only two positions: switched on or off. That is why in the data part of the word of 8 bits, we have got only two values 1 or 0.

When we receive the data in the ST7 receiver, it is also very easy to identify the LED data.

After having checked its identifier, we only have to compare the informations value to 1 or 0 and put on the corresponding output of the ST7 (PA0 pin) respectively VCC and GND. (see Test n3 p21)

D) Control of the servo-motor

The servo-motor need a square signal at 50 Hz with a duty cycle between 5 and 10 percent so as to the servo-motor can take different positions:

-90, t2=1ms

0, t2=1,5ms

90, t2=2ms

In order to create this signal, we use the second lite timer of the ST7 (LTCSR2). This timer can interrupt the main program every 16 s (because fosc/32 = 2MHz/32 = 62,5kHz see datasheet p72) but the longer of the interrupt program don't allow us to make and interruption less than every 30,5s else the program will only run in the interrupt program:

(nb of cycles)

pushA (3)

pushY(4)

LDA,LTCSR2(3)

LDY,#1(3)

LDA,(compteurinterruption,Y) ;incrementation du compteur(5)

ADDA,#1(2)

LD(compteurinterruption,Y),A(6)

LDA,compteurinterruption(3)

ADCA,#0(2)

LDcompteurinterruption,A(4)

BTJFPADR,#1,etatbas(5)

etathaut:

LDA,rapportcyclique(3)

CPA,(compteurinterruption,Y)(5)

JRNEfininterrup(3)

;passage de la sortie l'etat bas

BRESPADR,#1(5)

JPfininterrup(2)

etatbas:

;comparaison de compteurinterruption avec 417

LDA,#$A1(2)

CPA,(compteurinterruption,Y)(5)

JRNEfininterrup(3)

LDA,#$01(2)

CPA,compteurinterruption(3)

JRNEfininterrup(3)

;passage de la sortie l'etat haut

BSETPADR,#1(5)

CLRcompteurinterruption(5)

CLR(compteurinterruption,Y) (7)

fininterrup:

popY(4)

popA(5)

IRET(9)

We have a minimum of 93 cycles so of 46,5s < 3x16=48s so we chose to make an interruption every 3x16=48s (LTARR=256-3=253).

In our program, we use the rapportcyclique (duty cycle) which represent the number of interruptions that we have to reach to wait between 1 and 2ms. It depends on the value of joydg. To found its value we make this calculation:

With a time base of 48s,

20ms 417 interruptions

1ms 21 interruptions

2ms 42 interruptions

We establish a linear function which gives us rapportcyclique from the value of the joystick left/right with this:

21 interruptions 0 for the joystick

42 interruptions 255 for the joystick

So rapportcyclique = (21/255) joydg + 21

That we approximate:

(Rapportcyclique = (joydg/16)+(joydg/64) + 21)

Our interrupt program uses the variable compteurinterruption as a counter of interruptions. First we increment this value. Then, we look if we are on the high or low level on output. If we are in high level, we wait until we compteurinterruption = rapportcyclique whereas, we wait until compteurinterruption = 417 which means that we have made a period of 20 ms. Anyway, when we reach one of this conditions, we invert this output signal on the PA1 pin. We reset compteurinterruption every end of period. (see Test n3 p21)

E) Control of the DC current engine

CALL moteur

Description: It is the procedure where we control the DC current engine.

As previously explained the DC current engine command requires two PWM signals.

We check the value of the joyavar to know if we have to activate the PWM0 or the PWM1 and to set the other one to 0.

LD A,joyavar

CP A,#128

JRUGE senspositif

JP sensnegatif

;sens positif

...

LD A,#%00000001

LD PWMCR,A

BRES PADR,#3 ;forage 0 de PA3=PWM1

...

;sens negatif

...

LD A,#%00000100

LD PWMCR,A

BRES PADR,#2 ;forage 0 de PA2=PWM0

If the engine rotates in the positive direction(joyavar from 128 to 255), the duty cycle follows this evolution:

DCR = (joyavar/2) + 3967

Else joyavar is between 0 and 127:

DCR = (-joyavar/2) + 4095

The corresponding value of the DCR is set into the DCRxH and DCRxL registers.

After all of these steps, the program starts again at the beginning until it is stopped.

(see Test n3 p21)

3rd part : Tests

TEST n1: JOYSTICK and SWITCH

Aim of the test: This joystick is given by the teachers but we wanted to test it to know exactly how it works. We did two tests:

The first test: We acquired the two axes, vertical/horizontal and left/right on two pins of the micro-controller in order to switch on 4 LED. The firsts tries was made witch the ST7 Flite 20, because they were more available, and we did after the same with the Flite 30.

(ST7transmitterfor/backl/rjoystick)

After some problems with the registers, we noted that our joystick has a problem: it switches the 4 LED good but the problem came from the middle zone. In this case, the 4 led can be half switched on. With the LED it is not a concern, but with the DC engine and the servo motor, it could be annoying.

Thats why we introduced a neutral zone: the two axes are acquired and switched the LED after a value, so the acquisition is more stable.

The second test: We acquired just one axe (because we didnt have enough LED) and we switched on 6 LED with the joystick and another one with the switch.

(SwitchST7transmitterfor/backjoystick)

We wanted to see if the value is well acquired, and if the switch is working. We had some problems with the switch because it is linked to the round but with the pin correctly configured, it works. We used also the neutral zone, seen in the first test

TEST n2: JOYSTICK and SWITCH with ST7transmitter

Aim of the test: Determine if the acquisition of data makes properly.

We connect the ST7transmitter to the Joystick and switch board via the IN-DART and the programming cards.

We load the program in the ST7, and run it.

We change the positions of the joystick and the switch

We temporary halt the program

We look if variables in the watch windows correspond to the positions we gave.

We tried many positions (switch open or close, joydg on right or on left and joyavar on up or down).

TEST n3: ST7 receiver in visual develop

To check our program on Visual Develop we get rid of the procedure reception and modif_donnees. Then, we add by ourselves the values for joydg, joyavar and the LED like this into the main program.

(Joyavar value = 223Joydg value = 0LED switched on)

Then we look into the plot window to observe the signals generated on the different output pins.

Generation of the LED command (PA0 pin):

The LED is switched on:

We remark that we have got 5 V on the PA0 output which switches the LED on.

Generation of the servo-motor signal (PA1 pin):

The value put in the program is 0 so the generated signal should be like this: a high value during 1 ms and a low value during 19ms

Actually we only have got a period of 10 ms right there, this is because of the fact that in the hardware configuration, the frequency is automatically divided by two and here it is not the case. Anyway, we remark that we have got on the visual develop check a period of 10 ms and a duty cycle of 1/20.

So the test is concluding, we have got what we expect.

Now, we modify by hand the value of joydg into the ST7 receiver program and put 255, the other extreme value. We should obtain for the same reasons as previously a period of 10 ms but a duty cycle of 1/10. Here under is what we got by simulation. By the way we switch the LED off:

And that fits with what we were expecting.

Generation of the DC engine signal:

We are now going to check the generation of the PWM signals for the engine. We enter by hand the value 64 into the program for joyavar:

We remark that we have got a value in the PA3 pin and 0 onto the PA2 pin.

The duty cycle is about and that is what we wanted, because our value of 64 is in the midst of the dynamics. So we have to obtain this precise duty cycle.

Lets check right now if with another value we get what we want:

We put by hand the value 223 so we should obtain the opposite, 0 onto the PA3 and a value on the PA2. Here is what we get:

We remark on the plot above that on the PA2 pin the duty cycle is of and that is because we have put 223 which represents this duty cycle.

255max

DC223

Engine

Speedmin

128

Generated signal

On PA2 pin

Moreover, our period is visibly of 16ms which means 62.5 KHz, and this is the frequency wished for the engine.

All of these tests show that the generation of the signal is OK for the program used alone.

TEST n4: H-Bridge

The H-bridge has been tested on the printed circuit. According to the value coming, the DC engine is turning in one direction, with a certain speed.

TEST n5: Radio transmission

We do not care about the envoi_joyavar and the envoi_cdeled procedures in order to verify on the TDO pin thanks to the plotter window if the frame generated fits with the corresponding value.

This is how we how the SCI communication works:

A start bit (value 0) and then the Bits 0 to 7 are transmitted. To finish a stop bit (value 1).

By hand, we enter the value 167 into the joydg variable. After the transformation because of the neutral zone, the new joydg value is 153 (99H), so it is separated like this:

Joydg :

1

0

0

1

1

0

0

1

Will be send like this:

Joydgh: Joydgl:

0

1

1

0

1

0

0

1

0

1

0

0

1

0

0

1

So the frame generated has to be like this:

0

1

0

0

1

0

1

1

0

1

0

1

0

0

1

0

0

1

0

1

Into the plotter window, this is what we get on the TDO pin (PA7):

This is what we were expecting. So the text is concluding for the transmission.