smoothie port to mbed online compiler (smoothieware.org)

Dependencies:   mbed

For documentation, license, ..., please check http://smoothieware.org/

This version has been tested with a 3 axis machine

Committer:
scachat
Date:
Tue Jul 31 21:11:18 2012 +0000
Revision:
0:31e91bb0ef3c
smoothie port to mbed online compiler

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scachat 0:31e91bb0ef3c 1 /*
scachat 0:31e91bb0ef3c 2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
scachat 0:31e91bb0ef3c 3 Smoothie 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.
scachat 0:31e91bb0ef3c 4 Smoothie 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.
scachat 0:31e91bb0ef3c 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
scachat 0:31e91bb0ef3c 6 */
scachat 0:31e91bb0ef3c 7
scachat 0:31e91bb0ef3c 8
scachat 0:31e91bb0ef3c 9
scachat 0:31e91bb0ef3c 10 using namespace std;
scachat 0:31e91bb0ef3c 11 #include <vector>
scachat 0:31e91bb0ef3c 12 #include "libs/nuts_bolts.h"
scachat 0:31e91bb0ef3c 13 #include "libs/Module.h"
scachat 0:31e91bb0ef3c 14 #include "libs/Kernel.h"
scachat 0:31e91bb0ef3c 15 #include "StepTicker.h"
scachat 0:31e91bb0ef3c 16 #include "system_LPC17xx.h" // mbed.h lib
scachat 0:31e91bb0ef3c 17
scachat 0:31e91bb0ef3c 18
scachat 0:31e91bb0ef3c 19 StepTicker* global_step_ticker;
scachat 0:31e91bb0ef3c 20
scachat 0:31e91bb0ef3c 21 StepTicker::StepTicker(){
scachat 0:31e91bb0ef3c 22 global_step_ticker = this;
scachat 0:31e91bb0ef3c 23 LPC_TIM0->MR0 = 1000000; // Initial dummy value for Match Register
scachat 0:31e91bb0ef3c 24 LPC_TIM0->MCR = 11; // Match on MR0, reset on MR0, match on MR1
scachat 0:31e91bb0ef3c 25 LPC_TIM0->TCR = 1; // Enable interrupt
scachat 0:31e91bb0ef3c 26 NVIC_EnableIRQ(TIMER0_IRQn); // Enable interrupt handler
scachat 0:31e91bb0ef3c 27 }
scachat 0:31e91bb0ef3c 28
scachat 0:31e91bb0ef3c 29 void StepTicker::set_frequency( double frequency ){
scachat 0:31e91bb0ef3c 30 this->frequency = frequency;
scachat 0:31e91bb0ef3c 31 LPC_TIM0->MR0 = int(floor((SystemCoreClock/4)/frequency)); // SystemCoreClock/4 = Timer increments in a second
scachat 0:31e91bb0ef3c 32 if( LPC_TIM0->TC > LPC_TIM0->MR0 ){
scachat 0:31e91bb0ef3c 33 LPC_TIM0->TCR = 3; // Reset
scachat 0:31e91bb0ef3c 34 LPC_TIM0->TCR = 1; // Reset
scachat 0:31e91bb0ef3c 35 }
scachat 0:31e91bb0ef3c 36 }
scachat 0:31e91bb0ef3c 37
scachat 0:31e91bb0ef3c 38 void StepTicker::set_reset_delay( double seconds ){
scachat 0:31e91bb0ef3c 39 LPC_TIM0->MR1 = int(floor(double(SystemCoreClock/4)*( seconds ))); // SystemCoreClock/4 = Timer increments in a second
scachat 0:31e91bb0ef3c 40 }
scachat 0:31e91bb0ef3c 41
scachat 0:31e91bb0ef3c 42 void StepTicker::tick(){
scachat 0:31e91bb0ef3c 43 for (int i=0; i<this->hooks.size(); i++){
scachat 0:31e91bb0ef3c 44 this->hooks.at(i)->call();
scachat 0:31e91bb0ef3c 45 }
scachat 0:31e91bb0ef3c 46 }
scachat 0:31e91bb0ef3c 47
scachat 0:31e91bb0ef3c 48 void StepTicker::reset_tick(){
scachat 0:31e91bb0ef3c 49 for (int i=0; i<this->reset_hooks.size(); i++){
scachat 0:31e91bb0ef3c 50 this->reset_hooks.at(i)->call();
scachat 0:31e91bb0ef3c 51 }
scachat 0:31e91bb0ef3c 52 }
scachat 0:31e91bb0ef3c 53
scachat 0:31e91bb0ef3c 54 extern "C" void TIMER0_IRQHandler (void){
scachat 0:31e91bb0ef3c 55 if((LPC_TIM0->IR >> 0) & 1){ // If interrupt register set for MR0
scachat 0:31e91bb0ef3c 56 LPC_TIM0->IR |= 1 << 0; // Reset it
scachat 0:31e91bb0ef3c 57 global_step_ticker->tick();
scachat 0:31e91bb0ef3c 58 }
scachat 0:31e91bb0ef3c 59 if((LPC_TIM0->IR >> 1) & 1){ // If interrupt register set for MR1
scachat 0:31e91bb0ef3c 60 LPC_TIM0->IR |= 1 << 1; // Reset it
scachat 0:31e91bb0ef3c 61 global_step_ticker->reset_tick();
scachat 0:31e91bb0ef3c 62 }
scachat 0:31e91bb0ef3c 63 }
scachat 0:31e91bb0ef3c 64
scachat 0:31e91bb0ef3c 65