Details of PWM
theoatvecna
Posts: 20
When I call PWM.update, how does it handle it when it is in the middle of a pulse? Does it wait until the current pulse is done and then the next one gets the new value, or will it shorten or stretch the current pulse to the new value?
Next question which is related:
What I would really like is a CPU.pulseout method that returned immediately (allowed execution to continue) and used a VP to send out a pulse of the correct length. Another way to look at it would be to have a single shot PWM (only one pulse per update call. Is there any way to accomplish this?
Next question which is also related:
Is there any way that I can write my own VPs? I know this isn't a standard option, but I am wondering if I could work with Parallax or something to let me write some new VPs, and add make some changes to current ones (for instance, it would be great if timer.timeout returned the actual time elapsed, it must know it, but right now I have to recalculate it)
Thanks,
Daniel
Next question which is related:
What I would really like is a CPU.pulseout method that returned immediately (allowed execution to continue) and used a VP to send out a pulse of the correct length. Another way to look at it would be to have a single shot PWM (only one pulse per update call. Is there any way to accomplish this?
Next question which is also related:
Is there any way that I can write my own VPs? I know this isn't a standard option, but I am wondering if I could work with Parallax or something to let me write some new VPs, and add make some changes to current ones (for instance, it would be great if timer.timeout returned the actual time elapsed, it must know it, but right now I have to recalculate it)
Thanks,
Daniel
Comments
It would also be great if there was a variant of the Uart.byteAvailable() called Uart.bytesAvailable which returned how many bytes are available. That way I could postpone processing a message until I know it is all there.
· /**
·· * Check buffer use
·· *
·· * @return number of bytes in buffer.
·· */
· public int bufferCount() {
··· return (CPU.readRegister(vpBank|nmUartHead)
··········· - CPU.readRegister(vpBank|nmUartTail))&0xff;
· }
It is already in my adapted Uart class here
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
regards peter
·
file property first, otherwise you cannot save the altered file. Also note that many
.java files (especially those in folder core) cannot simply be copied and renamed
because the IDE knows of internal methods for these files. If you rename such a
file, the internal methodes are no longer recognized by the IDE.
You will find lots of adapted classes on the JavelinCode group
http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/
Regarding your other questions:
You cannot alter the firmware code, so if the firmware code waits, you cannot change this
(pulseOut for example). If you want to run other code during a pulse out use:
set output pin to pulse active state
while not timeout of a timer
· do addiotional code
set output pin to pulse inactive state
This is however only usable with pulses of longer duration.
A one shot pwm is not possible.
If you study the code for the pwm class, you'll see the low and high count
get loaded immediately into registers. These registers are probably used by
the firmware code to reload counter registers every time these reach zero.
So you can safely assume pwm waits until the current pulse is finished (but it may
happen the low state has the original length, and the high state gets the new length,
depends on the pulse state when the new values are written).
regards peter