Advertisement
aso4200

dcurrent.h

May 10th, 2022
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. //Routines for controlling driving current for turntable with stepper motor.
  2. //Version 20211116
  3.  
  4. #ifndef DCURRENT_H
  5. #define DCURRENT_H
  6. #endif
  7.  
  8. void driving_current(UBYTE akt);
  9. void chk_driving_current();
  10.  
  11. bool dc_state=false;
  12.  
  13. void driving_current(UBYTE akt)
  14. {
  15.     UBYTE dc_bit0,dc_bit1,dc_bit2,dc_bit3;
  16.  
  17.     if(akt)
  18.     {
  19.         if(dc_state==false)
  20.         {
  21.             dc_state=true;
  22.             if(direction)
  23.             {
  24.             dc_bit0=new_track_pos&1;
  25.             dc_bit1=new_track_pos&2;
  26.             dc_bit2=new_track_pos&4;
  27.             dc_bit3=new_track_pos&8;
  28.             digitalWrite(pin_dc_bit0,dc_bit0);
  29.             digitalWrite(pin_dc_bit1,dc_bit1);
  30.             digitalWrite(pin_dc_bit2,dc_bit2);
  31.             digitalWrite(pin_dc_bit3,dc_bit3);
  32.             digitalWrite(pin_dc_bit_active,HIGH);
  33.             Println("Driving current in track ",new_track_pos);
  34.             }
  35.         }
  36.     }
  37.     else
  38.     {
  39.         if(dc_state==true)
  40.         {
  41.             dc_state=false;
  42.             digitalWrite(pin_dc_bit_active,LOW);
  43.         Println("Driving current disconnect ");
  44.     }
  45.     }
  46. }
  47.  
  48. void chk_driving_current()
  49. {
  50.     if(setup_mode&&driving_curr)
  51.     {
  52.         driving_curr=false;
  53.         driving_current(OFF);
  54.         return;
  55.     }
  56.     if(setup_mode)
  57.         return;
  58.    
  59.     if(direction)
  60.     {
  61.         if(driving_curr==false)
  62.         {
  63.         driving_curr=true;
  64.         driving_current(ON);
  65.         }
  66.     }
  67.     else
  68.     {
  69.         if(driving_curr)
  70.         {
  71.         driving_curr=false;
  72.         driving_current(OFF);
  73.         }
  74.     }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement