Page 30 of 36

Counting circuit built and workign

PostPosted: Sun Nov 13, 2011 10:22 pm
by dirktheeng
All,

been a while since I posted anything. We had some more travel and I was working on trying to figure out how to get a board made quickly. Eventually, I just decided to go to radio shack and get a hole board and solder up a test circuit. I need this to be quick and I couldn't find a reasonable price that was fast. Anyhow, we had off for veterans day so I spent some time then getting this done. This was a LOT of soldering, but I got it done in about 8 hours or so and just started to test it out. It works just fine so far. Now I have to start writing up the code for the mega I had laying around. The first thing I will do is validate that it does indeed count accurately, then make the laser do PPI, then get it talking to the UNO via I2C and get the settings going in Mach 3 to get this all set up right and easy to use. I shouldn't even need to be connected to the mega during PPI operations.

After Xmas I will start to work on the engraving part of this as I have to really push to get some gifts made with this thing.

Here are a couple pics of the board installed in place and the place I chose to put the mega.

DSCN4381.JPG
board installed in its final place


The board fit nicely in place. The smoth stepper has a flat 26 pin ribbon cable on it and I used an IDC connector to "listen" in on the signal... much cheaper than getting a DB25 splitter... only $2. I listen for steps, directions, and laser on/off as well as limit switches. The board looks like a rats nest, cuz it kinda is, but it works well for now. If there is interest in the community, I may look to have a few made at the dorkbot place... you have to make 3 at a time.

DSCN4382.JPG
mega placement


I decided the best place for the mega was upside down on the bottom of the shelf. I put it up there with studs from RS and super glue. It is convenient and out of the way.

there is a 34 pin ribbon cable that connects the mega to the counter board. At this point, the board only counts x and y pulses, but it will count the full length of both the x and y axis at 16 x micro-stepping. It should have no problem counting up to the 2 MHz pulse freequency that the smooth stepper can go to.

BTW, this only cost me a total of $44 ($28 in parts from digikey + $16 in parts from RS) and it could be done for less. I bought extra parts in case I needed them and if I got a bunch of boards made, it would be really cheap.

Counting circuit finished... now on to programming

PostPosted: Sun Nov 20, 2011 9:48 pm
by dirktheeng
All,

I was able to find the time this week to finish the counting circuit. I got it working and reading through the Mega I have laying around. I'm glad that i didn't just go to make a board and did a test like this first. I made a mistake with the B/D (binary/decade) line. I tied it to ground insteady of high. From the data sheet it was very dificult to tell which it should be. They neglected to state it in the text of the data sheet. Also, the timing diagram didn't show it clearly... further the diagram for a "BCD" circuit (which I took to mean "binary count down") showed it tied to ground. The other thing is that after looking at the pin numbers in the ports of the Mega, I would arrange the output pins differently so I didn't have to make a cable and move the pins around. I originally planned to just read the pins directly, but then thoguht that reading an entire port as an 8 bit word is much faster and minimizes the machine code lines. The Mega will likely work for what I need it to now (a PPI controller), but I am beginning to have my doubs that it will work really well for an engraver at the speeds I want to run. The new DUE will be much better... it has 16 bit ports and runns at 92Mhz rather than 16. This means that it will take less machine instructions to read the counters (2 for the X and 1 for the Y) and it will run much faster speeds, which allows me more instructions to run the pulsing engine for the laser.

Here's the video update:


Re: Constructing Janus, by Dirk

PostPosted: Tue Nov 22, 2011 11:33 pm
by garyacrowellsr
BCD stands for Binary Coded Decimal. In BCD it counts from 0 to 9 then resets and issues a carry out.

Gary

Re: Constructing Janus, by Dirk

PostPosted: Thu Nov 24, 2011 7:33 pm
by dirktheeng
garyacrowellsr wrote:BCD stands for Binary Coded Decimal. In BCD it counts from 0 to 9 then resets and issues a carry out.

Gary


That makes a lot more sense!

PPI Code working!

PostPosted: Thu Nov 24, 2011 7:40 pm
by dirktheeng
All,

I just finished the first revision of the PPI code and tested it with a PPI of 4 and a pulse width of 500 running at 400mm/min. I ran it so slow so that I could actually watch the laser pulse on and off. It works very well so far, though I have not tested it with cutting yet. I don't expect there to be any issues running up to 1000PPI, though I will have to prove that later. I'm out of time today.

Here's rev 0 of the code... pretty simple.

Code: Select all
long xCnt = 0; // initialize the x axis integration variable
long yCnt = 0; // initialize the y axis integration variable
long xPrevCnt = 0; // initialize the x axis integration variable
unsigned int yPrevCnt = 0; // initialize the y axis integration variable
float ppiX = 157.4744*25.4; // conversion of pulses in x to inches
float ppiY = 157.76525*25.4; // conversion of pulses in y to inches
long lastPulseOnPos[]={0,0};
int laserCmd = 0;
int laserCmdPrev = 0;
int pulse = 0;
int pulseMS = 500;
int firstOnState = 0;
float PPI = 4;
unsigned long timeOld = 0;

float cumDist = 0;

#define turnLsrOff PORTB&=B01111111 //macro sets laser off
#define turnLsrOn PORTB|=B10000000 //macro sets laser on
#define lsrCmdPin ((PIND>>7)&1) // defines pin that laser comnd is on


void setup() {
  DDRA = 0x00;
  DDRC = 0x00;
  DDRL = 0x00;
  DDRB = DDRB|B01000000&B11000000;
  DDRG = DDRG&B11111000;
  DDRD = DDRD|B01111111;
}

void loop() {
  updateCounts();
  updateLaserCmd();
  if (laserCmd) {
    if (checkForMotion()){
      calcTravel();
      if (firstOnState) {
        cumDist = 0;
        timeOld = millis();
        pulse = 1;
        firstOnState = 0;
      }
      if (millis() - timeOld >= pulseMS) {pulse = 0;}
      if (cumDist >= 1/PPI) {
        cumDist = 0;
        timeOld = millis();
        pulse = 1;
      }
      if (pulse) {turnLsrOn;} else {turnLsrOff;}       
    }else{
      turnLsrOff;
    }
  }else{
    turnLsrOff;
  }
}

void calcTravel() {
  cumDist += sqrt(pow((xCnt-xPrevCnt)/ppiX,2) + pow((yCnt-yPrevCnt)/ppiY,2));
}

void updateCounts() {
  xPrevCnt = xCnt;
  yPrevCnt = yCnt;
  xCnt = PINA|(long)PINC<<8|(long)digitalRead(39)<<16;
  yCnt = PINL|(long)((PINB&B00111111)<<8)|(long)((PING&B00000011)<<14);
}

// This function reads the laser on/off command from the smooth stepper and stores the
// previous result.  This function checsk for the laser cmd going from 0 to 1 so timer
// and distcalc can be reset
void updateLaserCmd() {
  laserCmdPrev = laserCmd;
  laserCmd = lsrCmdPin;
  if ((laserCmdPrev == 0) && (laserCmd == 1)) {firstOnState = 1;}
}

// This function checks for motion in the x,y axis by comparint the previous count
// to the current count.  If the numbers are the same, then it there is no motion
int checkForMotion() {
  if ((xPrevCnt == xCnt) && (yPrevCnt == yCnt)) {return 0;} else {return 1;}
}


I'll post a video later. We're doing thanksgiving here shortly.

Happy Thanksgiving!

Re: Constructing Janus, by Dirk

PostPosted: Thu Nov 24, 2011 8:30 pm
by bill.french
LOL can't wait for the video!

Also, if you're interested in a faster board, consider the chipkit: http://www.digilentinc.com/Products/Cat ... 892&Cat=18

... our hackerspace is having a class on it in a couple weeks, if you're at all anywhere near central NJ.

PPI video demo

PostPosted: Fri Nov 25, 2011 12:24 am
by dirktheeng
Well, here is the demo. I am well on my way to getting the xmass presents done! This will work just fine! mainly, this will allow me to put constant laser power into a cut no matter what the speed or acceleration of the laser head are. This will allow me to do VERY fine work without worry about charring up everything or overheating/warping materials. Further, I am dead certain that the laser is not on unless there is motion of the head. Even with the SS, I noticed a little bit of delay between when the laser turned on/off and when the stuff moved. I've noticed little "drill" holes where the laser starts/stops. That was fine with most everything I did before this because I could do lead-in/outs and place them. However, I can't do that with scroll saw work. There are too many holes to cut to spend the time putting in all the lead ins and the work is to fine to let the laser be on constant power. To get beautiful results with reasonable effort, you have to use PPI.

Anyhow, Here's the video demo:


Re: Constructing Janus, by Dirk

PostPosted: Fri Nov 25, 2011 12:58 am
by dirktheeng
bill.french wrote:LOL can't wait for the video!

Also, if you're interested in a faster board, consider the chipkit: http://www.digilentinc.com/Products/Cat ... 892&Cat=18

... our hackerspace is having a class on it in a couple weeks, if you're at all anywhere near central NJ.


I haven't seen this board before, but it looks pretty nice. It won't be quite as fast as a DUE/Maple, but it sure has a lot of nice features. I like the cat5 feature. I could talk to it through Ethernet. Leaf labs has an expanded version of the maple coming out. They released a prototype run of sorts that looks good, though it doesn't have any documentation and has a a few mistakes in the board layout. I hope that one comes out to it's full potential soon.

Re: Constructing Janus, by Dirk

PostPosted: Fri Nov 25, 2011 3:10 am
by steppenshoe
It seems to me the Due may never come out at this rate, almost seems like vaporware. The diligent board is out now, supposedly works well and is close enough in speed for you to get on it instead of wait for the due which can come out in a week or a year. I see a lot of talk, but have the schematics on the Due even been released yet? Have they given a date for release?

Re: Constructing Janus, by Dirk

PostPosted: Fri Nov 25, 2011 4:01 pm
by dirktheeng
steppenshoe wrote:It seems to me the Due may never come out at this rate, almost seems like vaporware. The diligent board is out now, supposedly works well and is close enough in speed for you to get on it instead of wait for the due which can come out in a week or a year. I see a lot of talk, but have the schematics on the Due even been released yet? Have they given a date for release?


I know... I thought it was supposed to be out by the end of december, but I haven't seen anything on it since the announcement at the maker fare. I'm confident that it will come out eventually... but when???? ????

Anyhow, leaf labs has a cortex M3 board out now (but it's in beta). check out: http://leaflabs.com/devices/#Maple-Native It doesn't look as feature packed as the diligent board.

I think the MEGA is plenty fast for doing PPI at reasonable speeds, especially given the slow response of a CO2 laser. It takes about 1.5ms for the laser to turn on and about 0.5ms for it to turn off. 2ms on a 16Mhz processor is 32000 instructions. I think that is plenty to do what I am doing now.

However, I just got an accousto-optic modulator that will allow me to switch the laser on/off at multi megaherts frequencies (got what I need for $400). That is what I am going to use to get true "analog" engraving. That is going to require a very fast processor and highly optimized code to be able to get the AOM set every 33 micro seconds.

I'm going to start working on that later though. I don't have time now... just got a good deal now so I went for it.