Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- struct StepperInterface {
- uint32_t target_pos;
- uint32_t current_pos;
- bool halt_requested;
- };
- StepperInterface shmem __attribute__((cregister("LOCAL", near))) = {};
- //StepperInterface shmem __attribute__((location(0))) = {};
- // define some r30 bits
- #define CW (1u << 0)
- #define CCW (1u << 1)
- uint32_t volatile register __R30;
- #define delay_us(n) __delay_cycles((n) * 200u)
- #define delay_ms(n) delay_us((n) * 1000u)
- static inline void enable()
- {
- // this could either control the ENA signal or perhaps disable the
- // control signals. either way, probably want to use normal GPIO for
- // it since the PRU direct gpio (via R30) have random values at boot.
- }
- static inline void disable()
- {
- }
- static inline void deassert_CW_CCW() { __R30 = 0; }
- static inline void assert_CW() { __R30 = CW; }
- static inline void assert_CCW() { __R30 = CCW; }
- // CW/CCW version
- int main()
- {
- uint32_t pos = shmem.current_pos;
- deassert_CW_CCW();
- delay_us(1); // just to be paranoid
- enable();
- delay_ms(200);
- while( ! shmem.halt_requested ) {
- int32_t delta = shmem.target_pos - pos;
- if( delta == 0 )
- continue;
- // XXX optional: check for excessive delta
- if( delta < 0 ) {
- --pos;
- assert_CCW();
- } else {
- ++pos;
- assert_CW();
- }
- shmem.current_pos = pos; // for diagnostic purposes
- delay_us(1);
- deassert_CW_CCW();
- delay_us(1);
- }
- disable();
- __halt();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement