mael diy
/
cyclage_pont_H_compteur
H bridge with 4 relays for cycling motor, with a temporisatoin or position reading
Revision 0:7aa5e1ea57aa, committed 2018-02-20
- Comitter:
- maeldiy
- Date:
- Tue Feb 20 09:48:09 2018 +0000
- Commit message:
- provide H bridge through 4 relays for cycling motor with a temporisation
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Feb 20 09:48:09 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Tue Feb 20 09:48:09 2018 +0000 @@ -0,0 +1,75 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Export the project to Keil MDK, and debug your application + +From the command-line, run the following command: + +``` +mbed export -m K64F -i uvision +``` + +To debug the application: + +1. Start uVision. +1. Import the uVision project generated earlier. +1. Compile your application, and generate an `.axf` file. +1. Make sure uVision is configured to debug over CMSIS-DAP (From the Project menu > Options for Target '...' > Debug tab > Use CMSIS-DAP Debugger). +1. Set breakpoints, and start a debug session. + +![Image of uVision](img/uvision.png) + +## Troubleshooting + +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
Binary file img/uvision.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Feb 20 09:48:09 2018 +0000 @@ -0,0 +1,206 @@ +/* cycling using relay command through discrete +2017 19 10 by mael reymond +function : +display state on led onboard +command 2 relays (1 per direction) +send on serial monitor number of cycles since power on*/ + +#include "mbed.h" +Serial pc(SERIAL_TX,SERIAL_RX); +DigitalOut myled(LED1); +DigitalInOut relais_1(PB_5); // voir montage pont en H http://eskimon.fr/285-arduino-601-le-moteur-courant-continu +DigitalInOut relais_2(PB_8); +DigitalInOut relais_3(PC_7); +DigitalInOut relais_4(PA_9); +AnalogIn status(PC_5); + +SPI spimax(D11, D12, D13); DigitalOut CS(D9); // for MAX7219 7 segment display +// the MAX7219 address map (datasheet table 2) +#define MAX7219_DECODE_REG (0x09) +#define MAX7219_INTENSITY_REG (0x0A) +#define MAX7219_SCANLIMIT_REG (0x0B) +#define MAX7219_SHUTDOWN_REG (0X0C) +#define MAX7219_DISPLAYTEST_REG (0x0F) +#define MAX7219_DIGIT_REG(pos) ((pos) + 1) + +// shutdown mode (datasheet table 3) +#define MAX7219_OFF (0x0) +#define MAX7219_ON (0x1) + +// digit pattern for a 7-segment display. datasheet table 5 +const char digit_pattern[16] = +{ + 0x7E, // 0 + 0x30, // 1 + 0x6D, // 2 + 0x79, // 3 + 0x33, // 4 + 0x5B, // 5 + 0x5F, // 6 + 0x70, // 7 + 0x7F, // 8 + 0x7B, // 9 + 0x77, // A + 0x1F, // b + 0x4E, // C + 0x3D, // d + 0x4F, // E + 0x47 // F +}; + + +int counter = 0; +int duree_fermeture = 3; // par defaut 4 secondes +int duree_ouverture = 3; // par defaut 4 secondes +int duree_neutre = 0.2; // par defaut 200 ms +long n,u,d,c,m, dm,ddm,cm,mm; // pour l'afficheur +void fermeture(); // relais 1 & 3 fermés +void ouverture(); // relais 2 & 4 fermés +void neutre(); // tout relais ouverts +void max7219(char reg,char dta) { CS = 0; spimax.write(reg); spimax.write(dta); CS = 1; } + + +void init_max7219() +{ + // Turn on the display + max7219(MAX7219_SHUTDOWN_REG, MAX7219_ON); + // enable test mode. datasheet table 10 + max7219(MAX7219_DISPLAYTEST_REG, MAX7219_ON); + wait(6); + // disable test mode. datasheet table 10 + max7219(MAX7219_DISPLAYTEST_REG, MAX7219_OFF); + // set medium intensity. datasheet table 7 + max7219(MAX7219_INTENSITY_REG, 0x8); + // turn off display. datasheet table 3 + // max7219(MAX7219_SHUTDOWN_REG, MAX7219_OFF); + // drive 8 digits. datasheet table 8 + max7219(MAX7219_SCANLIMIT_REG, 7); + // no decode mode for all positions. datasheet table 4 + max7219(MAX7219_DECODE_REG, 0x00); +} +int main() { + +init_max7219(); +/*max7219(1,0x02);wait(2); + +max7219(3,0x06);wait(2); + +max7219(5,0x70);wait(2); +max7219(7,digit_pattern[2]);wait(2); +max7219(2,digit_pattern[6]);wait(2); + +*/ + /* relais_1.mode(PullDown); + relais_2.mode(PullDown); + relais_3.mode(PullDown); + relais_4.mode(PullDown); */ + +max7219(1,0x00);wait(2); + while(1) { + + /* pc.printf("status : %3.3f%%\n", status.read()); // counter display on serial monitor + pc.printf("status normalised: 0x%04X \n", status.read_u16()); // counter display on serial monitor + bool etat =0; + if (status.read()>0.8) { etat =1 ;}else etat = 0; + pc.printf("etat : %d\n", etat ); // counter display on serial monitor + myled = 1; // LED is ON + /* + neutre(); + ouverture(); + neutre(); + fermeture(); + counter++; //counter increment + // pc.printf("counter : %d\n", counter ); // counter display on serial monitor + + // display cycle number + dm = counter/10000000; + mm = counter/1000000 -10*dm; + cm = counter/100000 -100*dm -10*mm; + ddm = counter/10000 -1000*dm -100*mm - 10 *cm; + m = counter/1000 -10000*dm -1000*mm - 100 *cm -10*ddm; + c = counter/100 -100000*dm -10000*mm - 1000 *cm -100*ddm - 10*m; + d = counter/10 -1000000*dm -100000*mm - 10000 *cm -1000*ddm - 100*m - 10*c; + u = counter - 10000000*dm -1000000*mm - 100000 *cm -10000*ddm -1000*m - 100*c - 10*d; + + // dm = counter/10000000; + // mm = counter/1000000 -10*dm; + // cm = counter/100000 -100*dm -10*mm; + // ddm = counter/10000 -1000*dm -100*mm - 10 *cm; + /* m = counter/1000; + c = counter/100 - 10*m; + d = counter/10 - 100*m - 10*c; + u = counter -1000*m - 100*c - 10*d; + */ + if (u == 9) { + pc.printf("counter : %d", counter); // counter display on serial monitor + pc.printf(" m : %d", m); + pc.printf("c : %d", c); + pc.printf("d : %d", d); + pc.printf("u : %d", u); + } + // wait_ms(10); + + max7219(1,digit_pattern[u]); + max7219(2,digit_pattern[d]); + max7219(3,digit_pattern[c]); + max7219(4,digit_pattern[m]); + max7219(5,digit_pattern[ddm]); + max7219(6,digit_pattern[cm]); + max7219(7,digit_pattern[mm]); + max7219(8,digit_pattern[dm]); + } +} + + +void ouverture() +{ + +// relais 2 & 3 fermés + + relais_2.input(); + relais_3.input(); + + relais_2.output(); + relais_2= !relais_2; + relais_3.output(); + relais_3= !relais_3; + + myled = 0; // LED is OFF + wait(duree_ouverture); + + +} + +void fermeture() +{ + + // relais 1 & 3 fermés + myled = 1; // LED is ON + relais_1.output(); + relais_1= !relais_1; + relais_4.output(); + relais_4= !relais_4; + wait(duree_fermeture); + +} + + +void neutre() +{ + +// setting every relay pins as output HIGH, since relays command is a ground + relais_1.output(); + relais_2.output(); + relais_3.output(); + relais_4.output(); + relais_1= 1; + relais_2= 1; + relais_3= 1; + relais_4= 1; + + myled = 1; // LED is ON + wait(duree_neutre); + +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Feb 20 09:48:09 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#eca67ca7dafab4ef70c21e2463b541132d0dd691