Guest User

Untitled

a guest
Jan 1st, 2021
30
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <NanoPWMac.h> // https://www.rmcybernetics.com/science/diy-projects/programming-projects
  2.  
  3.  
  4. //pins
  5. #define PIN_POT A2
  6. #define PIN_I_ENABLE 8
  7. #define PIN_I_PWM 9
  8. #define PIN_O_REFL 4
  9. #define PIN_O_DUTY 5
  10. #define PIN_O_VSWR 6
  11. #define PIN_O_FWD 7
  12. #define PIN_O_TEMP A3
  13. #define PIN_O_AFWD A6
  14. #define PIN_O_AREFL A7
  15.  
  16. void setup() {
  17. pinMode(PIN_I_ENABLE,OUTPUT);
  18. pinMode(PIN_I_PWM,OUTPUT);
  19. pinMode(PIN_O_REFL,INPUT);
  20. pinMode(PIN_O_DUTY,INPUT);
  21. pinMode(PIN_O_VSWR,INPUT);
  22. pinMode(PIN_O_FWD,INPUT);
  23. pinMode(PIN_O_TEMP,INPUT);
  24.  
  25. Serial.begin(115200);
  26. }
  27. int pot_val = 0;
  28. int a_forward; // analog, shows forward voltage to the laser head
  29. int a_reflected; // analog, shows reflected Voltage from the laser head
  30. bool laser_enable = false; // high = enable may not work on OEM systems
  31. bool d_reflected; // signal change indicates laser, cable or connector failure.
  32. bool d_forward; // no change when modulated indicates failure
  33. bool d_cycle_limit; // duty cycle limit reached (>60% or >1ms pulse width)
  34. bool d_vswr_limit; // does not change unless theres a missmatch between laser and driver.
  35. bool d_over_temp; // over temp fault, laser stops until temp is reduced. may not work on oem systems.
  36. long pulseW = 0;
  37. unsigned int duty = 0;
  38. long oldmillis = 0;
  39. void loop() {
  40. pot_val = 1023-analogRead(PIN_POT);
  41. pulseW = map(pot_val,0,1023,0,30000);
  42. if(pulseW > 30000){pulseW=30000;}
  43. if(pulseW < 0){pulseW=0;}
  44. NanoPWMac(20000,pulseW,1);
  45.  
  46. if(pot_val > 50){
  47. laser_enable = true;
  48. }else{
  49. laser_enable = false;
  50. }
  51.  
  52. d_reflected= digitalRead(PIN_O_REFL);
  53. d_cycle_limit= digitalRead(PIN_O_DUTY);
  54. d_forward = digitalRead(PIN_O_FWD);
  55. d_vswr_limit = digitalRead(PIN_O_VSWR);
  56. d_over_temp = digitalRead(PIN_O_TEMP);
  57. a_forward = analogRead(PIN_O_AFWD);
  58. a_reflected = analogRead(PIN_O_AREFL);
  59.  
  60. digitalWrite(PIN_I_ENABLE,laser_enable);
  61.  
  62. if((oldmillis+1000) < millis()){
  63. oldmillis=millis();
  64.  
  65. Serial.println("DEBUG ");
  66. Serial.print("ENABLED: "); Serial.print(laser_enable); Serial.println("( >2% duty )");
  67. Serial.print("Set dutycyc:"); Serial.print(map(pot_val,0,1023,0,60)); Serial.println("%");
  68. Serial.print("forward ERR: "); Serial.println(d_forward);
  69. Serial.print("forward: "); Serial.print(map(a_forward,0,1023,0,100)); Serial.println("%");
  70. Serial.print("reflected: "); Serial.print(map(a_reflected,0,1023,0,100)); Serial.println("%");
  71. Serial.print("reflected ERR : "); Serial.println(d_reflected);
  72. Serial.print("cycle_limit:"); Serial.println(d_cycle_limit);
  73. Serial.print("vswr_limit: "); Serial.println(d_vswr_limit);
  74. Serial.print("over_temp : "); Serial.println(d_over_temp);
  75. Serial.println("\n\n\n\n\n\n");
  76. }
  77. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×