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.

timers.cpp 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 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 <https://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. void HAL_timer_init() {
  30. SBI(LPC_SC->PCONP, SBIT_TIMER0); // Power ON Timer 0
  31. LPC_TIM0->PR = (HAL_TIMER_RATE) / (STEPPER_TIMER_RATE) - 1; // Use prescaler to set frequency if needed
  32. SBI(LPC_SC->PCONP, SBIT_TIMER1); // Power ON Timer 1
  33. LPC_TIM1->PR = (HAL_TIMER_RATE) / 1000000 - 1;
  34. }
  35. void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
  36. switch (timer_num) {
  37. case 0:
  38. LPC_TIM0->MCR = _BV(SBIT_MR0I) | _BV(SBIT_MR0R); // Match on MR0, reset on MR0, interrupts when NVIC enables them
  39. LPC_TIM0->MR0 = uint32_t(STEPPER_TIMER_RATE) / frequency; // Match value (period) to set frequency
  40. LPC_TIM0->TCR = _BV(SBIT_CNTEN); // Counter Enable
  41. NVIC_SetPriority(TIMER0_IRQn, NVIC_EncodePriority(0, 1, 0));
  42. NVIC_EnableIRQ(TIMER0_IRQn);
  43. break;
  44. case 1:
  45. LPC_TIM1->MCR = _BV(SBIT_MR0I) | _BV(SBIT_MR0R); // Match on MR0, reset on MR0, interrupts when NVIC enables them
  46. LPC_TIM1->MR0 = uint32_t(TEMP_TIMER_RATE) / frequency;
  47. LPC_TIM1->TCR = _BV(SBIT_CNTEN); // Counter Enable
  48. NVIC_SetPriority(TIMER1_IRQn, NVIC_EncodePriority(0, 2, 0));
  49. NVIC_EnableIRQ(TIMER1_IRQn);
  50. break;
  51. default: break;
  52. }
  53. }
  54. #endif // TARGET_LPC1768