I've looked at that note and came away with the impression that it was pretty sloppy. Microchip app notes are great resources but frequently have significant errors and just plain bad coding style. There was one appnote where they must have changed the processor late in the process because several code sequences had incorrect banks for SFRs. I suspect that's what happened with the "lots of left over pins" comment. I also recall seeing several app note code sequences that had the RMW problem. Kind of bad when microchip is propagating those kinds of errors. It is an easy to make, yet false, assumption that their code is reasonably correct. I look at app notes as nice places to look for ideas. I would also be interested in your changes. --- Joe McCauley wrote: > I've just spent the last couple of days wrestling > with AN906 which describes > how to use a PIC16F684 as a stepper motor controller > (full step, half step & > microstepping mode). > > &appnote=en012150> > > I found the app note text only bore a passing > resemblance to the code for > the article (both downloaded at the same time from > the Microchip website). > Things described in the text such as chopper mode > current limiting were not > implemented in code, resulting in large currents > flowing in the windings. > > The app note says "The modes of operation are off, > forward, off, and > reverse". > > There is no reverse mode implemented in the code, > though it is of course > easy to roll your own. > > Modifying the PWM lookup table as described on page > 6 of the appnote to > accommodate different winding voltages does not seem > to help much, I really > do have to look at this a bit closer though. > > It also appears to me that, in the > Mode4IncrementState routine, the wrong > PWM values were being output to the motors in > microstepping mode due the > fact that the upper 8 bits of the PWM value were > being anded with 0x30 > instead of 0x3f before being placed in the CCPR1L > register. Changing this > gave a much cleaner sine profile to the current > waveform when microstepping. > > Even more bizarrely, the author claims in his > conclusion that "Extra I/O > pins and CPU resources are left over for > implementing serial communication, > an LCD interface, or any number of I/O > configurations." > > The device used has 12 I/O pins, 6 of which are used > to drive the motor, 4 > for the current sensing circuitry & 2 for inputs (in > this case a > speed/position control pot & switch) > > Has anyone else had any experiences like this with > Microchip app notes? I > normally don't look at them for a complete > application, but this one looked > perfect for something I was doing until these > problems bit me. It seems to > me that this particular application was either badly > written or supplied > with the wrong version of code. > > I've only mentioned the stuff I found so far in the > sections of code I was > interested in. I have no idea how many other errors > are in it or indeed if I > should rely on any of it. > > If anyone is really interested in trying to use this > app note, let me know & > I'll mail them a copy of my modified code & a full > set of waveforms showing > operation in microstepping mode. (not yet willing to > vouch for how correct > my version is yet though :o) > > Joe > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > __________________________________ Do you Yahoo!? Yahoo! Small Business - Try our new Resources site http://smallbusiness.yahoo.com/resources/ -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist