Initial commit of motor driver firmware
Fork of mbed_AS5047P_driver by
main.cpp@1:d68c51a0a706, 2016-09-28 (annotated)
- Committer:
- dhaldane
- Date:
- Wed Sep 28 16:59:46 2016 +0000
- Revision:
- 1:d68c51a0a706
- Parent:
- 0:00c56a9c6dee
Initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dhaldane | 0:00c56a9c6dee | 1 | #include "mbed.h" |
dhaldane | 0:00c56a9c6dee | 2 | #include "enc.h" |
dhaldane | 0:00c56a9c6dee | 3 | |
dhaldane | 1:d68c51a0a706 | 4 | //Ticker RTI; |
dhaldane | 1:d68c51a0a706 | 5 | Serial imProc(PTD7,PTD6); |
dhaldane | 1:d68c51a0a706 | 6 | DigitalOut led_1(PTC2); |
dhaldane | 1:d68c51a0a706 | 7 | DigitalOut led_2(PTC3); |
dhaldane | 1:d68c51a0a706 | 8 | DigitalOut led_3(PTA18); |
dhaldane | 1:d68c51a0a706 | 9 | enc motPos(PTC6,PTC7,PTC5,PTC4); |
dhaldane | 1:d68c51a0a706 | 10 | PwmOut EN(PTA4); |
dhaldane | 1:d68c51a0a706 | 11 | DigitalOut DR(PTA2); |
dhaldane | 1:d68c51a0a706 | 12 | DigitalOut BRAKE(PTA1); |
dhaldane | 1:d68c51a0a706 | 13 | AnalogIn motCurrent(PTB0); |
dhaldane | 1:d68c51a0a706 | 14 | AnalogIn temp(PTE30); |
dhaldane | 0:00c56a9c6dee | 15 | |
dhaldane | 0:00c56a9c6dee | 16 | |
dhaldane | 0:00c56a9c6dee | 17 | void get_state(){ |
dhaldane | 1:d68c51a0a706 | 18 | motPos.update_pos(); |
dhaldane | 0:00c56a9c6dee | 19 | } |
dhaldane | 0:00c56a9c6dee | 20 | |
dhaldane | 1:d68c51a0a706 | 21 | int main() { |
dhaldane | 1:d68c51a0a706 | 22 | EN.period_us(50); |
dhaldane | 1:d68c51a0a706 | 23 | EN.write(0.9f); |
dhaldane | 1:d68c51a0a706 | 24 | DR.write(0); |
dhaldane | 1:d68c51a0a706 | 25 | BRAKE.write(1); |
dhaldane | 1:d68c51a0a706 | 26 | motPos.set_offset(2160); |
dhaldane | 1:d68c51a0a706 | 27 | led_1 = 1; |
dhaldane | 1:d68c51a0a706 | 28 | // RTI.attach(&get_state, 0.01f); |
dhaldane | 0:00c56a9c6dee | 29 | while(1) { |
dhaldane | 1:d68c51a0a706 | 30 | |
dhaldane | 1:d68c51a0a706 | 31 | led_2 = 1; |
dhaldane | 1:d68c51a0a706 | 32 | led_3 = 0; |
dhaldane | 1:d68c51a0a706 | 33 | wait(0.5); |
dhaldane | 1:d68c51a0a706 | 34 | led_2 = 0; |
dhaldane | 1:d68c51a0a706 | 35 | led_3 = 1; |
dhaldane | 1:d68c51a0a706 | 36 | wait(0.5); |
dhaldane | 0:00c56a9c6dee | 37 | } |
dhaldane | 0:00c56a9c6dee | 38 | } |