Interface to a standard tarco sensor. Measure the periode and the cal the speed
Tarco.cpp@14:07d968decc76, 2016-04-15 (annotated)
- Committer:
- gert_lauritsen
- Date:
- Fri Apr 15 12:44:00 2016 +0000
- Revision:
- 14:07d968decc76
- Parent:
- 13:4b58c9730bc7
Funger som "gammel" motor styring. Kan k?rer gennem alle stadier. Der er kommet en eventlog, s? man kan se hvad der er sket.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gert_lauritsen | 2:c50da089786a | 1 | #include "Tarco.h" |
gert_lauritsen | 4:35024179a736 | 2 | #include "mbed.h" |
gert_lauritsen | 4:35024179a736 | 3 | |
gert_lauritsen | 14:07d968decc76 | 4 | Tarco::Tarco(PinName tarcosignal) : |
gert_lauritsen | 4:35024179a736 | 5 | _tarcosensor(tarcosignal) |
gert_lauritsen | 4:35024179a736 | 6 | { |
gert_lauritsen | 14:07d968decc76 | 7 | lastfrekvens=0; AdvPeriode=0; |
gert_lauritsen | 14:07d968decc76 | 8 | _tarcosensor.fall(this, &Tarco::Rotationtimer); |
gert_lauritsen | 14:07d968decc76 | 9 | TimeOut.attach(this,&Tarco::TarcoTimeout, 0.5); |
gert_lauritsen | 8:2e6b17f1da02 | 10 | } |
gert_lauritsen | 8:2e6b17f1da02 | 11 | |
gert_lauritsen | 0:8421e11df32a | 12 | |
gert_lauritsen | 7:752b8065ce2d | 13 | void Tarco::Rotationtimer() |
gert_lauritsen | 4:35024179a736 | 14 | { |
gert_lauritsen | 7:752b8065ce2d | 15 | //Da switchAuto motoren kommer ud med 24 pulser/rotation laver vi en prescale på 24 |
gert_lauritsen | 7:752b8065ce2d | 16 | // |
gert_lauritsen | 7:752b8065ce2d | 17 | static int pulscounter; |
gert_lauritsen | 14:07d968decc76 | 18 | GettingPuls=1; |
gert_lauritsen | 14:07d968decc76 | 19 | if (pulscounter++>=PulsPrRotation) { //Vi tæller til 24, således at det er tiden/omgang |
gert_lauritsen | 4:35024179a736 | 20 | t.stop(); |
gert_lauritsen | 14:07d968decc76 | 21 | AdvPeriode=t.read_us(); |
gert_lauritsen | 14:07d968decc76 | 22 | if (AdvPeriode>0) lastfrekvens=(1e6/AdvPeriode); else lastfrekvens=0; |
gert_lauritsen | 4:35024179a736 | 23 | t.reset(); |
gert_lauritsen | 4:35024179a736 | 24 | t.start(); |
gert_lauritsen | 7:752b8065ce2d | 25 | pulscounter=0; |
gert_lauritsen | 4:35024179a736 | 26 | } |
gert_lauritsen | 0:8421e11df32a | 27 | } |
gert_lauritsen | 0:8421e11df32a | 28 | |
gert_lauritsen | 13:4b58c9730bc7 | 29 | void Tarco::TarcoTimeout() { |
gert_lauritsen | 13:4b58c9730bc7 | 30 | //Timeout på tarco puls, så vi får resat tarcoen, når den staopper |
gert_lauritsen | 14:07d968decc76 | 31 | if (GettingPuls==0) { //Hvis vi ikke har haft en puld indenfor 0.5 sek, så er den stoppet |
gert_lauritsen | 14:07d968decc76 | 32 | t.stop(); t.reset(); |
gert_lauritsen | 7:752b8065ce2d | 33 | lastfrekvens=0; |
gert_lauritsen | 14:07d968decc76 | 34 | } |
gert_lauritsen | 14:07d968decc76 | 35 | GettingPuls=false; |
gert_lauritsen | 14:07d968decc76 | 36 | } |
gert_lauritsen | 14:07d968decc76 | 37 | |
gert_lauritsen | 4:35024179a736 | 38 | |
gert_lauritsen | 4:35024179a736 | 39 | float Tarco::RPM() |
gert_lauritsen | 4:35024179a736 | 40 | { |
gert_lauritsen | 7:752b8065ce2d | 41 | float rpm=lastfrekvens*60; |
gert_lauritsen | 7:752b8065ce2d | 42 | return (float) rpm; |
gert_lauritsen | 4:35024179a736 | 43 | } |
gert_lauritsen | 4:35024179a736 | 44 |