Hi,
Lots of topics there, so it's hard to be brief, but I'll try:
Maybe it would be possible to read the back emf of the motor when the mosfet is turned off and use it to measure the speed or the current when the mosfet is on?
No, I don't think the back emf is practical here. Firstly, I believe it would be necessary to "Pause" the PWM and wait for the electrical signals to stabilise (or disappear) before making any measurement, which would be too disruptive to the overall system operation. Also, a "universal" (a.c./d.c.) motor does not contain a permanent magnet, but has a (magnetic-) "field coil" (in series with the main coil). I thought that the "residual magnetism" in the soft-iron laminations would "kick-start" the motor as a generator (at least if there is a load across its terminals to activate the field winding). But perhaps not, since the motor seemed to exhibit very little "eddy current braking" (briefly mentioned in #66 para 3).
Yes, I had considered monitoring the current, but I think it probably raises more questions then it answers. The motor current is not the same as the power supply current in a PWM system, and both probably would need to be electrically isolated from the mains motor to drive the PICaxe ADC? Also, if the main aim is to stabilise/control the speed (rpm) of a motor, then the best thing to measure is the rpm directly !
Also today I rebuilt the power supply to give the A3144 a +8V and -4V supply so the input to the LM2917 had a -ve swing of -4V but still I have only a small output. It appears like the input has to a square wave about 0V so my 1 magnet pulse per revolution will not be suitable. I think I will need to make an encoder disk if I pursue this direction as shown in the data sheet.
The input stage of the LM2917 is a High Gain Differential Input "Op-Amp", but the 8-pin version connects one of the inputs internally only to ground. So the input signal must deviate above and below this pin level (0v), but by only a few mV should be sufficient. The "variable reluctance magnetic pickup" (basically a coil of wire grounded at one end) will automatically do this, but so should a coupling capacitor feeding a bias resistor (the latter grounded at its far end). IMHO the Operational Description in the LM2917 Data Sheet (section 9., page 10 onwards) is particularly good; it's obviously a very "old" chip design because it includes an internal circuit diagram

. I was designing very similar ICs (they actually contained PWM modulators) more than 50 years ago!
As used at the moment, the LM2917 seems to offer very little added value. The F-V converter is basically just a "Current Pump", sometimes known as a "Voltage Doubler" (two capacitors and two diodes), often used to generate a "boost" supply rail (2 x Vcc) or (by changing the diode connections), a negative supply rail (-Vcc). The F-V version rearranges the diode connections again, to give an output voltage between 0 and Vcc and adds a known load resistance across the output capacitor. At high frequencies they all "sit up" the input voltage peak-peak level onto the appropriate base/reference voltage, but at lower frequencies the restricted current flow defines an appropriate voltage across the load resistor. Those (5) components are almost identical in function to the peripheral components of the LM2917.
Certainly an "encoder wheel" should be able to give superior results, but I think it could need at least 50 lobes or bars per revolution. An optical method might be easier to experiment with (ultimately a magnetic system probably would be more rugged) but I think it might be worth persevering with a PICaxe/PULSIN system for now. However, I have come to the conclusion that the "Tacho" part needs to run synchronously with the motor revolutions, whilst the Servo/Control Loop part probably needs to run at a reasonably constant frequency (or execution time). That might be possible with a single PICaxe using Interrupts or some of the PIC's internal hardware functions, but for now let's consider two separate devices. Connecting a d.c. voltage level from one chip to the other is obviously one way to communicate the speed, however, using a DAC (PWM) output, a filter capacitor and then an ADC to get back to "a number" again, seems rather like overkill (so maybe use a serial communications link).
I have spent quite a lot of time trying to understand the program and some of the syntax you have given me but I still can't follow it because my working with basic is at a much lower level than yours but, because it is working I will come back to that at a later time for more help if that's ok.
I'm not sure how best to help here, but are you using the PICaxe Editor's Simulator? The Single Step mode allows you to "watch" what the program is doing. You may need to start by selecting RUN, but can then PAUSE and STEP through each program line. For simple programs I still prefer the PE5 version (which is available in the Obsolete section of the
Software Downloads) link; for example it pops up the simulation windows (although the default to EPROM instead of RAM memory is annoying) without the need to "unpin" them as with PE6. Both PE5 and PE6 can be installed and run from the task bar at the same time if desired, although there may be some conflicts when sharing the external hardware.
AFAIK the only "advanced" operation I've used was the
** 1024 which with hindsight would be better with the equivalent
/ 64 (division), but certainly PICaxe's integer-only maths can introduce some complications. I do tend to use multiple operations in a single line, when possible, because it can be faster and I do like to fit a complete "functional block" of code within a single screen-view. The Colon "
:" is equivalent to a "new line", and can be useful if the commands are closely related, but will be treated as a single step in the Simulator (that can be good or bad). The SemiColon "
;" (or also the single-quote "
' " can be a useful alternative) marks a "Comment", i.e. that the program-code compiler should ignore the remainder of the line. However, it also can be used to "Comment-Out" a whole line without actually deleting it, for example when debugging, or to show "optional" instructions (e.g. SERTXDs).
It is possible to input or change data values whilst the Simulator is Running, e.g. for PULSIN or READADC commands, etc., but this can be quite tedious, so sometimes I "overwrite" the values with a Commented-Out line. There is actually an
#IFDEF SIMULATING .... directive, but I tend to Keep It SimpleS.

Of course there are quite a lot of "Commands" to identify and learn, but they should be shown in a specific colour in the Program Editing window, and a good description is online at the top of the forum window at
PICAXE > Basic Commands.
Cheers, Alan.