
Master sends desired_speed to 2 BLDC drivers and reads the real_speed from wheel
Revision 0:51917a77fe02, committed 2014-05-01
- Comitter:
- Edewin
- Date:
- Thu May 01 09:00:22 2014 +0000
- Commit message:
- Master sends desired_speed through SPI to 2 BLDC drivers and receive the real_wheel_speed
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 01 09:00:22 2014 +0000 @@ -0,0 +1,58 @@ +#include "mbed.h" + /* + * + * Sensul : 0 - Inapoi + * 1 - Inainte + */ + unsigned int driver_dreapta(unsigned char sensul_dorit, unsigned int viteza_dorita); + unsigned int driver_stanga(unsigned char sensul_dorit, unsigned int viteza_dorita); +Serial pc (PA_2, PA_3); +SPI device(SPI_MOSI, SPI_MISO, SPI_SCK); + DigitalOut cs1(PB_6); + DigitalOut cs2(PA_8); + DigitalOut sens1(PC_7); + DigitalOut sens2(PB_10); +int main() { + device.format(16,0); + device.frequency(1000000); + unsigned int vit_rot_dr=0,vit_rot_st=0,j=0; + + while(1) { + for(j=40;j<100;++j) + { + vit_rot_dr=driver_dreapta(1,0); + vit_rot_st=driver_stanga(1,j); + pc.printf("vit rotii drepte %d rpm si stangi %d rpm\n\r",vit_rot_dr, vit_rot_st); + + wait_ms(50); + } + for(j=40;j<100;++j) + { + vit_rot_dr=driver_dreapta(0,0); + vit_rot_st=driver_stanga(0,j); + pc.printf("viteza rotii drepte%d si stangi%d\n\r",vit_rot_dr, vit_rot_st); + wait_ms(50); + } + } +} + +unsigned int driver_dreapta(unsigned char sensul_dorit, unsigned int viteza_dorita) +{ + unsigned int viteza_reala=0; + sens1=sensul_dorit; + cs1=0; + viteza_reala=device.write(viteza_dorita); + cs1=1; + return viteza_reala; + } + +unsigned int driver_stanga(unsigned char sensul_dorit, unsigned int viteza_dorita) +{ + unsigned int viteza_reala=0; + sens2=sensul_dorit; + cs2=0; + viteza_reala=device.write(viteza_dorita); + cs2=1; + return viteza_reala; + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu May 01 09:00:22 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776 \ No newline at end of file