My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

HAL_timers.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
  6. * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
  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. * Description:
  24. *
  25. * Timers for LPC1768
  26. */
  27. #ifdef TARGET_LPC1768
  28. #include "../../inc/MarlinConfig.h"
  29. #include "HAL_timers.h"
  30. void HAL_timer_init(void) {
  31. SBI(LPC_SC->PCONP, SBIT_TIMER0); // Power ON Timer 0
  32. LPC_TIM0->PR = (HAL_TIMER_RATE) / (STEPPER_TIMER_RATE) - 1; // Use prescaler to set frequency if needed
  33. SBI(LPC_SC->PCONP, SBIT_TIMER1); // Power ON Timer 1
  34. LPC_TIM1->PR = (HAL_TIMER_RATE) / 1000000 - 1;
  35. }
  36. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
  37. switch (timer_num) {
  38. case 0:
  39. LPC_TIM0->MCR = _BV(SBIT_MR0I) | _BV(SBIT_MR0R); // Match on MR0, reset on MR0, interrupts when NVIC enables them
  40. LPC_TIM0->MR0 = uint32_t(STEPPER_TIMER_RATE) / frequency; // Match value (period) to set frequency
  41. LPC_TIM0->TCR = _BV(SBIT_CNTEN); // Counter Enable
  42. NVIC_SetPriority(TIMER0_IRQn, NVIC_EncodePriority(0, 1, 0));
  43. NVIC_EnableIRQ(TIMER0_IRQn);
  44. break;
  45. case 1:
  46. LPC_TIM1->MCR = _BV(SBIT_MR0I) | _BV(SBIT_MR0R); // Match on MR0, reset on MR0, interrupts when NVIC enables them
  47. LPC_TIM1->MR0 = uint32_t(TEMP_TIMER_RATE) / frequency;
  48. LPC_TIM1->TCR = _BV(SBIT_CNTEN); // Counter Enable
  49. NVIC_SetPriority(TIMER1_IRQn, NVIC_EncodePriority(0, 2, 0));
  50. NVIC_EnableIRQ(TIMER1_IRQn);
  51. break;
  52. default: break;
  53. }
  54. }
  55. #endif // TARGET_LPC1768