My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

G2_PWM.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. /**
  24. * This module is stripped down version of the LPC1768_PWM.h file from
  25. * PR #7500. It is hardwired for the PRINTRBOARD_G2 Motor Current needs.
  26. */
  27. #include "../../../inc/MarlinConfigPre.h"
  28. #include "../../../module/stepper.h"
  29. //C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\module\stepper.h
  30. //C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\HAL\HAL_DUE\G2_PWM.h
  31. #define PWM_PERIOD_US 100 // base repetition rate in micro seconds
  32. typedef struct { // holds the data needed by the ISR to control the Vref pin
  33. volatile uint32_t* set_register;
  34. volatile uint32_t* clr_register;
  35. uint32_t write_mask;
  36. } PWM_map;
  37. #define G2_VREF(I) (uint32_t)(I * 5 * 0.15) // desired Vref * 1000 (scaled so don't loose accuracy in next step)
  38. #define G2_VREF_COUNT(Q) (uint32_t)map(constrain(Q, 500, 3.3 * 1000), 0, 3.3 * 1000, 0, PWM_PERIOD_US) // under 500 the results are very non-linear
  39. extern volatile uint32_t *SODR_A, *SODR_B, *CODR_A, *CODR_B;
  40. #define _PIN(IO) (DIO ## IO ## _PIN)
  41. #define PWM_MAP_INIT_ROW(IO,ZZ) { ZZ == 'A' ? SODR_A : SODR_B, ZZ == 'A' ? CODR_A : CODR_B, 1 << _PIN(IO) }
  42. #define PWM_MAP_INIT { PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_X_PIN, 'B'), \
  43. PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_Y_PIN, 'B'), \
  44. PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_Z_PIN, 'B'), \
  45. PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_E_PIN, 'A'), \
  46. };
  47. #define NUM_PWMS 4
  48. extern PWM_map ISR_table[NUM_PWMS];
  49. extern uint32_t motor_current_setting[3];
  50. #define IR_BIT(p) (WITHIN(p, 0, 3) ? (p) : (p) + 4)
  51. #define COPY_ACTIVE_TABLE() do{ LOOP_L_N(i, 6) work_table[i] = active_table[i]; }while(0)
  52. #define PWM_MR0 19999 // base repetition rate minus one count - 20mS
  53. #define PWM_PR 24 // prescaler value - prescaler divide by 24 + 1 - 1 MHz output
  54. #define PWM_PCLKSEL0 0x00 // select clock source for prescaler - defaults to 25MHz on power up
  55. // 0: 25MHz, 1: 100MHz, 2: 50MHz, 3: 12.5MHZ to PWM1 prescaler
  56. #define MR0_MARGIN 200 // if channel value too close to MR0 the system locks up
  57. extern bool PWM_table_swap; // flag to tell the ISR that the tables have been swapped
  58. #define HAL_G2_PWM_ISR void PWM_Handler()
  59. extern volatile uint32_t PWM_ISR1_STATUS, PWM_ISR2_STATUS;