Olin Lathrop wrote: > > So, any suggestions on getting 2x analogue > > output from a small PIC at high speed?? > > The easy solution is to use a PIC with two PWM modules or use external D/As. > However, you might be able to do this if you're very careful. With 20MHz > clock and 32,000 analog out updates per second, you have 156 instructions > per update. Doing one PWM at this rate isn't too hard, especially if there > are no other interrupts. > > Doing two is going to be tricky, because handling of one will result in > latency (and therefore wrong value) in the other. You'd pretty much have to > dedicate the PIC to doing nothing else. In that case you probably need > another PIC to do the stuff this PIC can't do, in which case it would be > cheaper and easier to just get a PIC with two PWM outputs in the first > place. Thanks Olin, I think I have a final solution and I came to the same comclusion that you did, that PWM is best. My problem is that the PWM voltage is used for current regulation, and needs to be fairly ripple free. So that means filter RC at least at 10x the PWM period, so that meant VERY high speed PWM if I need to get 32,000 actual current levels/sec, that's maybe 320,000 Hz PWM. I was looking at resistor ladder solutions to give the different analogue outputs and found I was looking at it from the wrong direction. To get 2-phase 8 microsteps I don't need two high resolution DACs, I need one DAC with 9 steps and 2 outputs. I can do that with 9 PIC pins and a bunch of resistors. I even had circuit and parts values worked out, but this pin count forced me to F87x series parts, which I didn't want (and lots of resistors). Once I had the 9-stage 2-output thing happening, I thought about PWM again. Why use PWM modules? Why even use the TIMER? Why limit PWM to the 256 count fixed frequency concept? What about something like this: ;----------------------------------------------- ; Stage 1 of 9 (example) stage_1_loop: movlw b'00000011' ; both AB phases on movwf PORTB ; change output pins nop ; delays as needed nop ; movlw b'00000010' ; turn phase A off movwf PORTB ; change output pins nop ; delays as needed nop ; movlw b'00000000' ; turn phase B off movwf PORTB ; change output pins nop ; delays as needed nop ; nop ; delays as needed nop ; nop ; delays as needed nop ; goto stage_1_loop ; loop forever ;----------------------------------------------- This tight loop gives *very* high freqeuncy PWM, so I can meet my spec of small RC constant/ripple and also give very fast response. Using infinite loop gives rock solid timing for accurate PWM voltage of both motor phases. I can use interrupt on change feature on the "step" control input pin to simply count up or down and then goto a new code loop, one loop for each of the 9 voltage levels I need, to control BOTH phases in each tight loop. Extending the theory, I can handle all four quadrants for all 32 possible 8-microstep variations, using four PIC pins. So I no longer have to use one set of pins for current and four more pins for phase direction switching, I can just use the 4 PWM pins to directly contol the h-bridge halves. Nice. Parts count just went down again. To get my required 9 sets of voltages, I think every voltage can be done using hardcoded blocks of about 20 to 30 instructions. So although there will be different pwm FREQUENCY for the differing 9 stages, it gives all required voltage variances at a fast enough speed. At 20MHz the 30 instruction loop still gives 170,000 Hz pwm, and this lets me use a small enough RC to get the result. Another advantage is that the interrupt on the "step" input command, then jumping to tight hardcoded loops gives fairly instant control of the PWM voltages... Now my next challenge is to read up on hardware errors re fast port changing and pin capacitance, but I can design it to only write to the 4 pins (the whole port) in one hit, and use the other 4 pins as inputs, and hope this will keep me out of trouble if I don't load the pins too much. Many thanks to everyone who offered help with this one! :o) -Roman -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.