2017-08-14 21:40:13 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-09-01 00:30:43 +02:00
|
|
|
* The class Servo uses the PWM class to implement its functions
|
2017-08-14 21:40:13 +02:00
|
|
|
*
|
|
|
|
* All PWMs use the same repetition rate - 20mS because that's the normal servo rate
|
2017-11-18 09:08:03 +01:00
|
|
|
*/
|
2017-08-19 02:16:57 +02:00
|
|
|
|
|
|
|
/**
|
2017-09-27 11:57:33 +02:00
|
|
|
* This is a hybrid system.
|
2017-08-19 02:16:57 +02:00
|
|
|
*
|
|
|
|
* The PWM1 module is used to directly control the Servo 0, 1 & 3 pins. This keeps
|
|
|
|
* the pulse width jitter to under a microsecond.
|
2017-08-14 21:40:13 +02:00
|
|
|
*
|
2017-09-27 11:57:33 +02:00
|
|
|
* For all other pins the PWM1 module is used to generate interrupts. The ISR
|
2017-08-19 02:16:57 +02:00
|
|
|
* routine does the actual setting/clearing of pins. The upside is that any pin can
|
|
|
|
* have a PWM channel assigned to it. The downside is that there is more pulse width
|
|
|
|
* jitter. The jitter depends on what else is happening in the system and what ISRs
|
|
|
|
* prempt the PWM ISR. Writing to the SD card can add 20 microseconds to the pulse
|
|
|
|
* width.
|
2017-08-14 21:40:13 +02:00
|
|
|
*/
|
2017-09-27 11:57:33 +02:00
|
|
|
|
2017-08-14 21:40:13 +02:00
|
|
|
/**
|
|
|
|
* The data structures are setup to minimize the computation done by the ISR which
|
2017-08-19 02:16:57 +02:00
|
|
|
* minimizes ISR execution time. Execution times are 2.2 - 3.7 microseconds.
|
2017-08-14 21:40:13 +02:00
|
|
|
*
|
|
|
|
* Two tables are used. active_table is used by the ISR. Changes to the table are
|
|
|
|
* are done by copying the active_table into the work_table, updating the work_table
|
|
|
|
* and then swapping the two tables. Swapping is done by manipulating pointers.
|
|
|
|
*
|
|
|
|
* Immediately after the swap the ISR uses the work_table until the start of the
|
|
|
|
* next 20mS cycle. During this transition the "work_table" is actually the table
|
|
|
|
* that was being used before the swap. The "active_table" contains the data that
|
|
|
|
* will start being used at the start of the next 20mS period. This keeps the pins
|
|
|
|
* well behaved during the transition.
|
|
|
|
*
|
|
|
|
* The ISR's priority is set to the maximum otherwise other ISRs can cause considerable
|
|
|
|
* jitter in the PWM high time.
|
2017-08-19 02:16:57 +02:00
|
|
|
*
|
|
|
|
* See the end of this file for details on the hardware/firmware interaction
|
2017-08-14 21:40:13 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 20:59:40 +01:00
|
|
|
#ifndef _LPC1768_PWM_H_
|
|
|
|
#define _LPC1768_PWM_H_
|
|
|
|
|
|
|
|
#include "pinmapping.h"
|
2018-02-04 02:33:26 +01:00
|
|
|
#include <lpc17xx_clkpwr.h>
|
2017-08-14 21:40:13 +02:00
|
|
|
|
|
|
|
#define LPC_PWM1_MR0 19999 // base repetition rate minus one count - 20mS
|
2018-02-04 02:33:26 +01:00
|
|
|
#define LPC_PWM1_PCLKSEL0 CLKPWR_PCLKSEL_CCLK_DIV_4 // select clock divider for prescaler - defaults to 4 on power up
|
|
|
|
#define MR0_MARGIN 200 // if channel value too close to MR0 the system locks up
|
2017-08-14 21:40:13 +02:00
|
|
|
|
2017-10-26 20:37:26 +02:00
|
|
|
void LPC1768_PWM_init(void);
|
2017-11-16 02:01:52 +01:00
|
|
|
bool LPC1768_PWM_attach_pin(pin_t pin, uint32_t min=1, uint32_t max=(LPC_PWM1_MR0 - (MR0_MARGIN)), uint8_t servo_index=0xFF);
|
2017-10-26 20:37:26 +02:00
|
|
|
bool LPC1768_PWM_write(pin_t pin, uint32_t value);
|
|
|
|
bool LPC1768_PWM_detach_pin(pin_t pin);
|
|
|
|
bool useable_hardware_PWM(pin_t pin);
|
2017-11-19 20:59:40 +01:00
|
|
|
|
|
|
|
#endif // _LPC1768_PWM_H_
|