diff --git a/Move.h b/Move.h index 950876a..704485d 100644 --- a/Move.h +++ b/Move.h @@ -53,6 +53,7 @@ class Move void Exit(); void Qmove(); void GetCurrentState(float m[]); + void Interrupt(); @@ -73,5 +74,10 @@ inline boolean DDA::Active() return active; } +inline void Move::Interrupt() +{ + dda->Step(); +} + #endif diff --git a/Move.ino b/Move.ino index 7892e0b..e36edf3 100644 --- a/Move.ino +++ b/Move.ino @@ -50,12 +50,6 @@ void Move::Spin() if(!active) return; Qmove(); - unsigned long t = platform->Time(); - if(t - lastTime > 1000) - { - lastTime = t; - dda->Step(); - } } @@ -131,6 +125,7 @@ void DDA::Start() { for(char drive = 0; drive < DRIVES; drive++) platform->SetDirection(drive, directions[drive]); + platform->SetInterrupt(300); active = true; } diff --git a/Platform.h b/Platform.h index 917b6b6..e8e3799 100644 --- a/Platform.h +++ b/Platform.h @@ -246,6 +246,8 @@ class Platform int GetRawTemperature(byte heater); + void InitialiseInterrupts(); + RepRap* reprap; // DRIVES @@ -360,7 +362,9 @@ inline void Platform::SetDirection(byte drive, bool direction) inline void Platform::Step(byte drive) { - digitalWrite(stepPins[drive], !digitalRead(stepPins[drive])); + //digitalWrite(stepPins[drive], !digitalRead(stepPins[drive])); + digitalWrite(stepPins[drive], 0); + digitalWrite(stepPins[drive], 1); } inline int Platform::GetRawTemperature(byte heater) diff --git a/Platform.ino b/Platform.ino index eb316ca..60a3e75 100644 --- a/Platform.ino +++ b/Platform.ino @@ -46,9 +46,51 @@ Platform::Platform(RepRap* r) // Interrupts +void TC3_Handler() +{ + TC_GetStatus(TC1, 0); + reprap.GetPlatform()->Interrupt(); +} + +/* +void startTimer(Tc *tc, uint32_t channel, IRQn_Type irq, uint32_t frequency) +{ + pmc_set_writeprotect(false); + pmc_enable_periph_clk((uint32_t)irq); + TC_Configure(tc, channel, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4); + // VARIANT_MCK = 84x10^6 for the Due + uint32_t rc = VARIANT_MCK/128/frequency; //128 because we selected TIMER_CLOCK4 above + TC_SetRA(tc, channel, rc/2); //50% high, 50% low + TC_SetRC(tc, channel, rc); + TC_Start(tc, channel); + tc->TC_CHANNEL[channel].TC_IER=TC_IER_CPCS; + tc->TC_CHANNEL[channel].TC_IDR=~TC_IER_CPCS; + NVIC_EnableIRQ(irq); +} +*/ + +void Platform::InitialiseInterrupts() +{ + pmc_set_writeprotect(false); + pmc_enable_periph_clk((uint32_t)TC3_IRQn); + TC_Configure(TC1, 0, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK4); + TC1->TC_CHANNEL[0].TC_IER=TC_IER_CPCS; + TC1->TC_CHANNEL[0].TC_IDR=~TC_IER_CPCS; + NVIC_DisableIRQ(TC3_IRQn); +} + inline void Platform::SetInterrupt(long t) { - + if(t <= 0) + { + NVIC_DisableIRQ(TC3_IRQn); + return; + } + uint32_t rc = (uint32_t)(t*84)/128; + TC_SetRA(TC1, 0, rc/2); //50% high, 50% low + TC_SetRC(TC1, 0, rc); + TC_Start(TC1, 0); + NVIC_EnableIRQ(TC3_IRQn); } inline void Platform::Interrupt() @@ -243,6 +285,8 @@ void Platform::Init() Serial.println("SD initialization failed."); // SD.begin() returns with the SPI disabled, so you need not disable it here + InitialiseInterrupts(); + active = true; } diff --git a/RepRapFirmware.ino b/RepRapFirmware.ino index 1c51308..e940294 100644 --- a/RepRapFirmware.ino +++ b/RepRapFirmware.ino @@ -101,7 +101,7 @@ void RepRap::Spin() void RepRap::Interrupt() { - + move->Interrupt(); } //*************************************************************************************************