Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // FIXME add attributes to allocate these at fixed addresses
- uint32_t target = 0;
- uint32_t current = 0;
- bool halt_requested = false;
- // PUL/DIR version (ENA optional)
- int main()
- {
- set PUL and ENA high;
- wait 300 ms;
- while( ! halt_requested ) {
- int32_t delta = target - current;
- if( delta == 0 )
- continue;
- if( delta < 0 ) {
- --current;
- if( DIR is low ) {
- set DIR high;
- wait 2 us;
- }
- } else {
- ++current;
- if( DIR is high ) {
- set DIR low;
- wait 2 us;
- }
- }
- set PUL low;
- wait 1 us;
- set PUL high;
- wait 1 us;
- }
- set ENA low;
- __halt();
- }
- // CW/CCW version (ENA optional)
- int main()
- {
- set CW, CCW and ENA high;
- wait 300 ms;
- while( ! halt_requested ) {
- int32_t delta = target - current;
- if( delta == 0 )
- continue;
- if( delta < 0 ) {
- --current;
- set CCW low;
- } else {
- ++current;
- set CW low;
- }
- wait 1 us;
- set CW and CCW high;
- wait 1 us;
- }
- set ENA low;
- __halt();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement