Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 7366_lib TLE5206_lib
Diff: main.cpp
- Revision:
- 2:486bb9b6bd78
- Parent:
- 0:509b29d50fcb
- Child:
- 3:737ac9c24ca5
--- a/main.cpp Tue Jan 29 15:34:57 2019 +0000 +++ b/main.cpp Tue Feb 12 10:52:27 2019 +0000 @@ -20,8 +20,11 @@ #define H3_IN2 PA_4 //A3 - PWM3/2 #define DECOUP_HACH 50 //us - 20 000 kHz pour les oreilles +#define PERIODE_AFF 500 //ms +#define PERIODE_ASSERV 50 //ms - +Serial pc(USBTX,USBRX); +Timer timer; DigitalOut myled(LED3); SPI_7366 compt1(SPI_MOSI, SPI_MISO, SPI_SCLK,SPI_CS1); @@ -33,6 +36,8 @@ TLE5206 moteur3(H3_IN1,H3_IN2); int main() { + + //setup compt1.setup(); compt2.setup(); compt3.setup(); @@ -45,10 +50,29 @@ moteur2.write(-0.7); moteur3.write(0.7); + timer.start(); + + //variables + int32_t position = 0; + int32_t consigne = (1<<15); + int32_t erreur = 0; + float gain = 0.0001; + uint32_t seuilAffichage = PERIODE_AFF; + uint32_t seuilAsserv = PERIODE_ASSERV; + // Loop while(1) { - compt3.read_value(); - myled = !myled; - wait(1); + + if (timer.read_ms() > seuilAffichage){ + position = compt2.read_value(); + seuilAffichage += PERIODE_AFF; + pc.printf("valeur lue : %d \n\r", position); + myled = !myled; + } + if (timer.read_ms() > seuilAsserv){ + seuilAsserv += PERIODE_ASSERV; + erreur = compt2.read_value() - consigne; + moteur2.write(gain * erreur); + } } } \ No newline at end of file