Advertisement
Guest User

Untitled

a guest
May 18th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. // FIXME add attributes to allocate these at fixed addresses
  2. uint32_t target = 0;
  3. uint32_t current = 0;
  4. bool halt_requested = false;
  5.  
  6. // PUL/DIR version (ENA optional)
  7. int main()
  8. {
  9.     set PUL and ENA high;
  10.     wait 300 ms;
  11.     while( ! halt_requested ) {
  12.         int32_t delta = target - current;
  13.         if( delta == 0 )
  14.             continue;
  15.         if( delta < 0 ) {
  16.             --current;
  17.             if( DIR is low ) {
  18.                 set DIR high;
  19.                 wait 2 us;
  20.             }
  21.         } else {
  22.             ++current;
  23.             if( DIR is high ) {
  24.                 set DIR low;
  25.                 wait 2 us;
  26.             }
  27.         }
  28.         set PUL low;
  29.         wait 1 us;
  30.         set PUL high;
  31.         wait 1 us;
  32.     }
  33.     set ENA low;
  34.     __halt();
  35. }
  36.  
  37. // CW/CCW version (ENA optional)
  38. int main()
  39. {
  40.     set CW, CCW and ENA high;
  41.     wait 300 ms;
  42.     while( ! halt_requested ) {
  43.         int32_t delta = target - current;
  44.         if( delta == 0 )
  45.             continue;
  46.         if( delta < 0 ) {
  47.             --current;
  48.             set CCW low;
  49.         } else {
  50.             ++current;
  51.             set CW low;
  52.         }
  53.         wait 1 us;
  54.         set CW and CCW high;
  55.         wait 1 us;
  56.     }
  57.     set ENA low;
  58.     __halt();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement