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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * This module is stripped down version of the LPC1768_PWM.h file from
  24. * PR #7500. It is hardwired for the PRINTRBOARD_G2 Motor Current needs.
  25. */
  26. #include "../../inc/MarlinConfigPre.h"
  27. #include "../../module/stepper.h"
  28. //C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\module\stepper.h
  29. //C:\Users\bobku\Documents\GitHub\Marlin-Bob-2\Marlin\src\HAL\HAL_DUE\G2_PWM.h
  30. #define PWM_PERIOD_US 100 // base repetition rate in micro seconds
  31. typedef struct { // holds the data needed by the ISR to control the Vref pin
  32. volatile uint32_t* set_register;
  33. volatile uint32_t* clr_register;
  34. uint32_t write_mask;
  35. } PWM_map;
  36. #define G2_VREF(I) (uint32_t)(I * 5 * 0.15) // desired Vref * 1000 (scaled so don't loose accuracy in next step)
  37. #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
  38. extern volatile uint32_t *SODR_A, *SODR_B, *CODR_A, *CODR_B;
  39. #define _PIN(IO) (DIO ## IO ## _PIN)
  40. #define PWM_MAP_INIT_ROW(IO,ZZ) { ZZ == 'A' ? SODR_A : SODR_B, ZZ == 'A' ? CODR_A : CODR_B, 1 << _PIN(IO) }
  41. #define PWM_MAP_INIT { PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_X_PIN, 'B'), \
  42. PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_Y_PIN, 'B'), \
  43. PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_Z_PIN, 'B'), \
  44. PWM_MAP_INIT_ROW(MOTOR_CURRENT_PWM_E_PIN, 'A'), \
  45. };
  46. #define NUM_PWMS 4
  47. extern PWM_map ISR_table[NUM_PWMS];
  48. extern uint32_t motor_current_setting[3];
  49. #define IR_BIT(p) (WITHIN(p, 0, 3) ? (p) : (p) + 4)
  50. #define COPY_ACTIVE_TABLE() do{ for (uint8_t i = 0; i < 6 ; i++) work_table[i] = active_table[i]; }while(0)
  51. #define PWM_MR0 19999 // base repetition rate minus one count - 20mS
  52. #define PWM_PR 24 // prescaler value - prescaler divide by 24 + 1 - 1 MHz output
  53. #define PWM_PCLKSEL0 0x00 // select clock source for prescaler - defaults to 25MHz on power up
  54. // 0: 25MHz, 1: 100MHz, 2: 50MHz, 3: 12.5MHZ to PWM1 prescaler
  55. #define MR0_MARGIN 200 // if channel value too close to MR0 the system locks up
  56. extern bool PWM_table_swap; // flag to tell the ISR that the tables have been swapped
  57. #define HAL_G2_PWM_ISR void PWM_Handler()
  58. extern volatile uint32_t PWM_ISR1_STATUS, PWM_ISR2_STATUS;