I'm trying -- and at the moment, failing -- to generate and measure a pulse of accurate width. The set up is very simple: using a 40X2, pull up pin B.7 using a 10k resistor. I'm also using port A to display a couple of register values using a bank of LEDs. Please see the attached code and note that the PICAXE can actively drive pin B.7 low, but a high level logic is achieved by defining pin B.7 as an input and the external resistor pulling the undriven line high. The intention is to be able to connect multiple PICAXEs together, though for the moment just a single chip is in use.
Simulations are promising: the actual length of the pulse at the pin is the same as defined in the register at 41 ms, and the value measured using the timer is 40 ms. I think that I've set the timer up correctly to measure milliseconds.
Not for the first time, real silicon differs from the simulations. Here the initially set value is the same 41 ms, but the actual pulse width at the pin is 55.45 ms and the value measured by the timer (as displayed on the port A LEDs) is 46 ms. These differences are well outside what I'm prepared to tolerate. It seems that only by stripping away commands can I approach the intended value of pulse width.
I don't have any problem with simulations and real silicon differing, but I don't understand at the moment why they are different. Is there some mistake in my coding that can be put right, or am I facing unpredictable or predictable delays due to the commands in sequence with the PAUSE statements? (Have I been missing something in setting up the simulator if the simulated time for executing an instruction differs so much from reality?) The former can hopefully be put right, but the latter may mean I'm trying to do something that's effectively impossible and so must find an alternative method.
Roger.
View attachment PulseTest40X2.bas
Simulations are promising: the actual length of the pulse at the pin is the same as defined in the register at 41 ms, and the value measured using the timer is 40 ms. I think that I've set the timer up correctly to measure milliseconds.
Not for the first time, real silicon differs from the simulations. Here the initially set value is the same 41 ms, but the actual pulse width at the pin is 55.45 ms and the value measured by the timer (as displayed on the port A LEDs) is 46 ms. These differences are well outside what I'm prepared to tolerate. It seems that only by stripping away commands can I approach the intended value of pulse width.
I don't have any problem with simulations and real silicon differing, but I don't understand at the moment why they are different. Is there some mistake in my coding that can be put right, or am I facing unpredictable or predictable delays due to the commands in sequence with the PAUSE statements? (Have I been missing something in setting up the simulator if the simulated time for executing an instruction differs so much from reality?) The former can hopefully be put right, but the latter may mean I'm trying to do something that's effectively impossible and so must find an alternative method.
Roger.
View attachment PulseTest40X2.bas