diff options
| author | Abel Tim <git@abeltim.com> | 2025-05-29 12:21:13 +0200 |
|---|---|---|
| committer | Abel Tim <git@abeltim.com> | 2025-05-29 12:21:13 +0200 |
| commit | 34d0baa8801b8ec7cbefe3b458765c29807652f5 (patch) | |
| tree | 549708f156138121d2da07ece141ec21229b4836 | |
| parent | c74a730bcb05ecf2656474e87276e6ec8139a1a0 (diff) | |
| download | robotica-34d0baa8801b8ec7cbefe3b458765c29807652f5.tar.gz robotica-34d0baa8801b8ec7cbefe3b458765c29807652f5.zip | |
encoder zephyr
Think this should work to use the encoder but cna only build not upload, need to wait till monday till i can test it with a robot.
Signed-off-by: Abel Tim <git@abeltim.com>
| -rw-r--r-- | code/main/teensy_player/src/main.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/code/main/teensy_player/src/main.c b/code/main/teensy_player/src/main.c index e082f66..e113c79 100644 --- a/code/main/teensy_player/src/main.c +++ b/code/main/teensy_player/src/main.c @@ -16,9 +16,9 @@ #define m1pwm1 DT_ALIAS(GPIO4_6) /*pin 4*/ #define m1pwm2 DT_ALIAS(GPIO4_5) /*pin 3*/ /*encoder pins*/ -#define m1encoA DT_ALIAS(GPIO2_12) /*pin 32*//*encoder number 1*/ +#define m1encoA 32 /*pin 32*//*encoder number 1*/ #define Nm1encoA INT_TO_POINTER(0) /*gives encoder number N*/ -#define m1encoB DT_ALIAS(GPIO3_22) /*pin 31*//*encoder number 2*/ +#define m1encoB 31 /*pin 31*//*encoder number 2*/ #define Nm1encoB INT_TO_POINTER(1) /*gives encoder number N*/ @@ -26,17 +26,28 @@ #define ENC_ISR_PRIO 1 /* set encoder interrupt service routine*/ -void ENCO_ISR(void *encN){ - if (encN == 0){ +/*variables*/ +/*encoders/PWM/PID*/ +#define NUM_ENCODERS 2 /*how many encoder pins there are*/ +volatile int encCount[NUM_ENCODERS] = {0}; /*sets all encoder counts to 0 changes of state*/ + +/*misc*/ +#define MY_IRQ_FLAGS 0 /*no IRQ flags*/ +void ENCO_ISR(void *encN){ + /*adds one to the encoder where a change of state is detected*/ + int encoder = (int)(intptr_t)encN; + if (encoder >= 0 && encoder < NUM_ENCODERS) { + encCount[encoder]++; } } -void ENC_ISR_installer(void) -{ +void ENC_ISR_installer(void){ /*sets up the interupts for the encoder at same priority, need to configure FIFO in case of simultanius call*/ - IRQ_CONNECT(MY_DEV_IRQ, ENC_ISR_PRIO, m1encoA_ISR, Nm1encoA, MY_IRQ_FLAGS); - IRQ_CONNECT(MY_DEV_IRQ, ENC_ISR_PRIO, m1encoB_ISR, Nm1encoB, MY_IRQ_FLAGS); + IRQ_CONNECT(m1encoA, ENC_ISR_PRIO, ENCO_ISR, '0', MY_IRQ_FLAGS); + IRQ_CONNECT(m1encoB, ENC_ISR_PRIO, ENCO_ISR, '1', MY_IRQ_FLAGS); } + +int main(void){} |
