summaryrefslogtreecommitdiff
path: root/trunk/users/adrian/FiveD_GCode.old/FiveD_GCode_Extruder/FiveD_GCode_Extruder.pde
blob: 486ee93ed2cae45db482287c3b62d828fdf30512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * 5D GCode Interpreter
 * Arduino code to load into the extruder controller
 * 
  * Adrian Bowyer 3 July 2009
 */
 
 /*
 ***NOTE***
 This program changes the frequency of Timer 0 so that PWM on pins H1E and H2E goes at
 a very high frequency (64kHz see: 
 http://tzechienchu.typepad.com/tc_chus_point/2009/05/changing-pwm-frequency-on-the-arduino-diecimila.html)
This will mess up timings in the delay() and similar functions; they will no longer work in
 milliseconds, but 64 times faster.
 */
  
#ifndef __AVR_ATmega168__
#error Oops!  Make sure you have 'Arduino Diecimila' selected from the boards menu.
#endif

#include <ctype.h>
#include <HardwareSerial.h>
#include "WProgram.h"
#include "configuration.h"
#include "extruder.h"
#include "intercom.h"



extruder ex;
intercom talker(&ex);
int loopBlink;

void setup() 
{
  pinMode(DEBUG_PIN, OUTPUT);
  loopBlink = 0;
  rs485Interface.begin(RS485_BAUD);
} 

void loop() 
{ 
  //if(rs485Interface.available())
  //    rs485Interface.print(rs485Interface.read(), BYTE); 
  
  talker.tick();
  
  // Keep me at the right temp etc.
  
  ex.manage();
  
  loopBlink++;
  if(loopBlink & 0x2000)
   digitalWrite(DEBUG_PIN, 1);
  else
   digitalWrite(DEBUG_PIN, 0); 
} 

void delayMicrosecondsInterruptible(unsigned int us)
{
  // for a one-microsecond delay, simply return.  the overhead
  // of the function call yields a delay of approximately 1 1/8 us.
  if (--us == 0)
    return;

  // the following loop takes a quarter of a microsecond (4 cycles)
  // per iteration, so execute it four times for each microsecond of
  // delay requested.
  us <<= 2;

  // account for the time taken in the preceeding commands.
  us -= 2;

  // busy wait
  __asm__ __volatile__ ("1: sbiw %0,1" "\n\t" // 2 cycles
"brne 1b" : 
  "=w" (us) : 
  "0" (us) // 2 cycles
    );
}