Shop OBEX P1 Docs P2 Docs Learn Events
PWMPAL question ? — Parallax Forums

PWMPAL question ?

hitswarehitsware Posts: 156
edited 2007-05-01 02:33 in BASIC Stamp
serout 0,6,[noparse][[/noparse]"!PWMSS",240] ' initialize outputs
test
serout 0,6,[noparse][[/noparse]"!PWMM1",255,0,255,0]
pause 300
serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
pause 300
serout 0,6,[noparse][[/noparse]"!PWMM1",0,1,0,1]
pause 600
serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
pause 600
serout 0,6,[noparse][[/noparse]"!PWMM1",1,1,1,1]
pause 600
serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
pause 3600
goto test
' listening off of pin 12 on a BS2 stacked with a PWMPAL
' what causes the 'randomness' in the pattern?
' I can understand latency but a loop shoud produce
' a pattern right ?
' Do the 2 pcbs run on differant clocks ?
' This is some kind of 'beating' ?
' It seems to possibly have something to do with using 16 bit
' vs. 8 bit duration values ?
«1

Comments

  • hitswarehitsware Posts: 156
    edited 2007-04-18 01:56
    'addendum:
    serout 0,6,[noparse][[/noparse]"!PWMSS",240] ' initialize outputs
    test
    serout 0,6,[noparse][[/noparse]"!PWMM1",255,0,255,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,1,0,1]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",1,1,1,1]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
    pause 3600
    goto test
    ' listening off of pin 12 on a BS2 stacked with a PWMPAL
    ' what causes the 'randomness' in the pattern?
    ' I can understand latency but a loop shoud produce
    ' a pattern right ?
    ' Do the 2 pcbs run on differant clocks ?
    ' This is some kind of 'beating' ?
    ' It seems to possibly have something to do with using 16 bit
    ' vs. 8 bit duration values ?
  • hitswarehitsware Posts: 156
    edited 2007-04-18 02:54
    serout 0,6,[noparse][[/noparse]"!PWMSS",240] ' initialize outputs
    test
    serout 0,6,[noparse][[/noparse]"!PWMM1",255,0,255,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",255,0,255,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",255,0,255,0]
    pause 300
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,0,0,0]
    pause 3600
    goto test
    ' listening off of pin 12 on a BS2 stacked with a PWMPAL
    ' what causes the 'randomness' in the pattern?
    ' this time the notes remain whole
    BUT !
    there is a random 'pop' (transition from low to high(or high to low))
    during the 3600 pause ......
    AND !
    ? BECAUSE !

    the
    ' I can understand latency but a loop shoud produce
    ' a pattern right ?
    ' Do the 2 pcbs run on differant clocks ?
    ' This is some kind of 'beating' ?
    ' It seems to possibly have something to do with using 16 bit
    ' vs. 8 bit duration values ?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-18 16:39
    Hello,

    There is a momentary “glitch” in the outputs whenever you send a new serial command. Since you’re looping the same serial data repeatedly you’re going to see that glitch every 3.6 seconds. You should only SEROUT to the PWMPAL when you actually need to change a channel output anyway. Also, please try to be more concise in your posting…It took me awhile to figure out why there were three almost identical posts on this question. You can always edit your original post if you need to update it. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • hitswarehitsware Posts: 156
    edited 2007-04-19 01:57
    >It took me awhile to figure out why there were three
    >almost identical posts on this question

    If you would look at the posts more carefully ..
    And either listen (or watch on a scope) and/or (bonus for both) to pin 12
    You will see what I mean ........

    255,0,255,0 (set durations)
    'vs
    0,1,0,1 (set durations)
    'yield ridiculessly completely differant results
    WAY more than the differance in frequency suggests .....
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-04-19 02:25
    hitsware--

    Why not follow Mr. Savage's advice and ask clear-cut questions? He supports all of us on a LOT of different forums. His help is truly invaluable. Every opportunity one has to make it easier for him to grasp the problem makes an answer or suggestion that much more forthcoming.

    It is my firm belief--I don't know for sure because I don't work for them--that if Parallax discovers a problem with one of their products, or code they have published, they will correct the situation as soon as possible.

    Mr. Savage and the other Parallax folks are an extremely valuable resource. And, they like to be used! [noparse]:)[/noparse]

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • hitswarehitsware Posts: 156
    edited 2007-04-19 03:14
    >> 255,0,255,0 (set durations)
    >> vs
    >> 0,1,0,1 (set durations)
    >> yield ridiculessly completely differant results
    >> WAY more than the differance in frequency suggests .....

    What could be more "clear cut" than that ?
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-04-19 13:33
    hitsware--

    Regarding the following . . .

    ">> 255,0,255,0 (set durations)
    >> vs
    >> 0,1,0,1 (set durations)
    >> yield ridiculessly completely differant results
    >> WAY more than the differance in frequency suggests .....

    What could be more "clear cut" than that ?"


    Respectfully, almost anything would be clearer than what I have quoted from you above. First, to the good, there are only six lines instead of the original three pages. Second, it is addressed to no one, therefore I think it must be for me, since I am the one that suggested an alternative approach to phrasing the question. The problem is that I am unfamiliar with the technical subject matter·and you apparently have far more experience. Therefore, I cannot address too much of the technicalities of the quoted portion above. (How about putting a colon after each label in the code you posted previously? That would help, I am sure.)

    But, at my very first glance, it looks like you are trying to shift some arguments right. When I think about it for a bit and compare it to what you previously posted, I know that must not be your intent and you must have some other intent. But, what is it? Perhaps, I have missed a long-running conversation between you and others and the people you have addressed (implicitly, because there is no opening salutation) know exactly what you mean.

    Third, proper spelling always improves anyone's writing. Fourth, your postings are written in incomplete sentence fragments, often with ending punctuation randomly inserted. This makes your meaning very difficult to discern, thus the antithesis of "clear-cut." I could continue, but I am sure you understand what I mean now concerning a more clear-cut writing style.

    I have been in the technology business a very, very long time. Clear-cut communications are of paramount importance. The first thing professionals that do not know each other do is determine the meaning of the various terms (as we use them) that clutter our profession. Even professionals that do know each other go through this process. It is certainly a time-saver and, most often, a money-saver.

    You know, if you could explain the problem to me, a newcomer to this field, I bet everyone would understand it!

    Again, respectfully,

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • metron9metron9 Posts: 1,100
    edited 2007-04-19 15:05
    Somebody said...

    there is a random 'pop' (transition from low to high(or high to low))
    during the 3600 pause ......

    Could you be more specific as to the timing on the random pop. How may in what time frame.
    Speculating here since I do not have a pwmpal but I did just read the data sheet.

    Mike Green gave me some information in another post about a BS2 pin in INPUT mode.
    Somebody said...

    Actually, the opposite is true. If you set all the pins to input and they're connected to inputs, the lines will float and, in particular, will float across the switching threshold in response to induced noise in the signal lines and cause the input MOSFETs to go into their linear conduction region and draw more current. You may do better setting any normally output pins to low outputs. Any strobe or chip select pins that are active low should be set to high outputs.

    Perhaps this is the random pop?


    I also have questions on setting the pwmpal to 0,0,0,0 duty cycle. There are special situations that effect hardware timers when set to zero time , I dont know the internal workings of the PWMPAL if the 0,0,0,0 frequency is actually passed along to the timer but after reading the datasheet I would think you might be better off using the Hardware control control status. Use the hardware On/Off pin to turn the PWM on or off after you pass the frequency and duty cycle information. That shuld make it cleaner. Like I said I dont know if the input is interrupt driven or polled, double buffered or not so additional debugging on that point is something I cant do without more information on how the software controls the PWM output from the PWMPAL side.

    Hope this helps. I know things that sometimes I think should not happen make me get upset, but stay the course , drill down to the cause and you will find the answer. Sometimes it's a simple misunderstanding of how a device functions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-19 15:09
    hitsware said...(trimmed)
    If you would look at the posts more carefully ..
    And either listen (or watch on a scope) and/or (bonus for both) to pin 12
    You will see what I mean ........
    255,0,255,0 (set durations)
    'vs
    0,1,0,1 (set durations)
    'yield ridiculessly completely differant results
    WAY more than the differance in frequency suggests .....
    Okay, it looks like maybe you're trying extreme ranges for duty cycle.· If you check the documentation you will find that the duty cycle range cannot be fully covered on the complete range of allowed frequencies.· Nonetheless, my original point stands.· Your code is repeatedly sending the same information to the PWMPAL.· Since nothing is changing, the only difference will be each time you send the serial data to the PWMPAL there will be a glitch in the outputs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • hitswarehitsware Posts: 156
    edited 2007-04-19 16:09
    O.K. Thank you. I am sorry for my lack of communication and spelling skills.
    For now disregarding the 'intermittant' "pop":
    What I am doing is using pin 12 on a PWMPAL/BS2 to put out square waves at different frequencies which need to be updated periodically. (~every half second or so)
    The duration values below refer to the commands to the PWMPAL.
    If I set the duration values to 255,0,255,0 (or any lesser values in the first bytes) this works fine. (some pop at refresh time, but accepttable and understandable)
    But:
    If I set the duration values to 0,1,0,1 (or any values using the second bytes) I get glitches on the pulse train.
    I wouldn't think this is an extreme case of duty cycle (because it's 50/50 in both instances), nor frequency (since it's right in the middle of the given range of frequencies).
    This can be readily seen on a scope or heard.
    (My application is a crude music synthesizer)
    Can anyone shed some light on what may be happening here.
    Respectfully,
    Michael Miller

    Post Edited (hitsware) : 4/20/2007 3:30:32 PM GMT
  • metron9metron9 Posts: 1,100
    edited 2007-04-19 16:57
    Please take no offense to the following stab in the dark possibilities as I don't have the specs on the pwmpal (I don't know where to find them) but the following situations could indeed cause glitches.

    Perhaps the pwmpal is not using glitch free fast PWM where the counter counts from bottom to top then back to bottom
    Perhaps the pwmpal is not using a 16bit timer? and reloading an 8 bit timer?
    perhaps the pwm is software/interrupt driven and not a hardware PWM timer?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-19 17:02
    I will try to (by tomorrow) recreate your results and see what may be happening.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • hitswarehitsware Posts: 156
    edited 2007-04-19 22:38
    >(I don't know where to find them)

    http://www.parallax.com/dl/docs/prod/acc/PWMPAL.pdf

    >Perhaps the pwmpal is not using glitch free fast PWM where the counter >counts from bottom to top then back to bottom

    I know nothing of that.

    >Perhaps the pwmpal is not using a 16bit timer? and reloading an 8 bit timer?

    I think it's supposed to be 16 bit, but it is strange that you load by bytes instead of words. The first and second bytes define the high time, and the third and forth define the low time. I did have the thought that perhaps the timer(s)? was responding byte at a time. I.E. to the first and third bytes and then the second and forth (rather than making words out of bytes and then resetting the '16 bit timers' all at once.....????

    >perhaps the pwm is software/interrupt driven and not a hardware PWM >timer?

    I don't know about that either.

    Thank you for the input [noparse]:)[/noparse]

    Post Edited (hitsware) : 4/19/2007 10:58:11 PM GMT
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2007-04-19 23:11
    hitsware--

    Thanks for posting that link to Parallax's pdf on the PWMPAL! It helped a lot.

    I had always wondered how the PWMPAL controlled much of a motor since the only output was TTL level. The answer is now obvious: It doesn't. Additional circuitry is necessary. (But not too much.)

    I have an application in mind for the future that will use a motor rated at 1.2A no-load all the way to 85A stall-torque. I wonder if the PWMPAL and some heavy duty electronics could possibly form the basis of a motor controller similar to, say, the MMBe? I have searched cyber-space far and wide and have found NOTHING that even comes close to the range I quoted. (It is a Banebot gear motor.) Of course, my actual machine would not approach·stall-torque too closely or things would break pretty quickly!

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • hitswarehitsware Posts: 156
    edited 2007-04-20 00:00
    >I had always wondered how the PWMPAL controlled much of a motor since the only >output was TTL level. The answer is now obvious: It doesn't. Additional circuitry is >necessary. (But not too much.)

    Some logic level mosfets and the right gate resistors (and perhaps attendent passive ?)
    and you ought to be good to go ......
  • metron9metron9 Posts: 1,100
    edited 2007-04-20 03:07
    I have that document. I was wondering what they used for a processor on the device. It looks like an SX20. I read the data sheet and it has one 8 bit timer. This is a guess and I am just winging it here. If I did a 4 pin PWM software controlled output with one 8 bit timer I do it the following way.

    Assuming 50MHZ clock, and an SX 20 using the 8 bit clock with the prescaler gets you a 16 bit clock I think
    Setting an interrupt for every 25 uS. Increment four 32 bit counters by one for each interrupt.

    I would take the sixteen bit values the stamp sends, add then together and make that the TOP value then use the ON time value for the comparison value inside the interrupt. Switch the pin on when the counter hits 0. Switch off when the counter hits the ON value. Reset the counter to 0 when it hits TOP. Do this with all four counters and you have four channels of PWM output.

    If this is the case, the new values sent should replace the old values at counter = 0 and not when they are sent. If the SX 20 operates like the SX28 then the timing should not glitch at all because exact timing can be done on this chip and I will bet the parallax folks used something similar that really should not have any glitches.

    It will be interesting to see what Chris finds. I enjoy looking for stuff like this, if I had a PWMPAL I would be up all night trying to figure it out. Instead though, I think I may just try making a PWMPAL type co processor to run some servos I have when there was a good price on them, I have a box full of them.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • hitswarehitsware Posts: 156
    edited 2007-04-20 03:37
    Yep. You get the cigar [noparse]:)[/noparse]

    "The PWMPAL uses the SX20 to generate the PWM output via software. All the functions, including the serial communication are done via software. Take care."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support

    Post Edited (hitsware) : 4/20/2007 11:56:56 AM GMT
  • hitswarehitsware Posts: 156
    edited 2007-04-21 02:11
    Chris Savage (Parallax) said...
    I will try to (by tomorrow) recreate your results and see what may be happening.

    Does this mean you could not recreate my results ?
    Should I try to email 'customer support' ?
    This weekend I will try to do a PBasic demo of the problem.
    It would probably be better if I used a scope
    (for purposes of my demonstration)
    rather than a speaker ...... Right ?


    Post Edited (hitsware) : 4/21/2007 3:27:31 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-21 05:12
    Sorry, got tied up on another project today and didn't get a chance to set up a PWMPAL. If I don't have one at home I will set it up Monday morning. Take Care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • hitswarehitsware Posts: 156
    edited 2007-04-21 18:38
    Chris Savage (Parallax) said...
    Sorry, got tied up on another project today and didn't get a chance to set up a PWMPAL. If I don't have one at home I will set it up Monday morning. Take Care.

    Cris,
    Thanks. This seems to pretty well point out my problem:
    x var nib'................................addendum to line 3 below
    y var word'.............................with some frequencies it's worse
    serout 0,6,[noparse][[/noparse]"!PWMSS",255]'........<If I set this value to 17
    test'........................................(enabling only channel 1)
    for x=0 to 15'............................the problem goes away.
    y=255'.....................................But I need to run all the channels
    debug dec ? y'.............................at once for my application.
    serout 0,6,[noparse][[/noparse]"!PWMM1",255,0,255,0]'.(as would·most applications)
    pause 200'.........................(Say a H bridge class D amplifier)
    next
    for x=0 to 15
    y=256
    debug dec ? y
    serout 0,6,[noparse][[/noparse]"!PWMM1",0,1,0,1]
    pause 200
    next
    goto test


    Post Edited (hitsware) : 4/22/2007 2:41:18 PM GMT
  • hitswarehitsware Posts: 156
    edited 2007-04-23 15:51
    Cris,
    This may better demonstrate the problem.
    Thanks for any time you can spend on this.

    x var word
    d1 var byte
    d2 var byte
    serout 0,6,[noparse][[/noparse]"!PWMSS",255]
    test
    for x=255 to 256
    debug cls
    debug dec ? x
    d1=x//256
    d2=x/256
    serout 0,6,[noparse][[/noparse]"!PWMM1",d1,d2,d1,d2]
    pause 5000
    next
    goto test
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-23 19:31
    I ran your code…Can you describe exactly what it is you’re seeing? Also what firmware version of the PWMPAL you have. All I see is the typical glitch every 5 seconds when you change the settings…Remember, the duty cycle cannot operate in the full range over the entire range of frequencies. It happens that I just plugged in some more generic code than yours and it too operates fine so I am curious if there is something more specific?
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    SEROUT 0,6,[noparse][[/noparse]"!PWMSS",255]
    SEROUT 0,6,[noparse][[/noparse]"!PWMM1",16,0,24,0]
    STOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • hitswarehitsware Posts: 156
    edited 2007-04-23 22:38
    Chris Savage (Parallax) said...
    I ran your code…Can you describe exactly what it is you’re seeing? Also what firmware version of the PWMPAL you have. All I see is the typical glitch every 5 seconds when you change the settings…Remember, the duty cycle cannot operate in the full range over the entire range of frequencies. It happens that I just plugged in some more generic code than yours and it too operates fine so I am curious if there is something more specific?
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    SEROUT 0,6,[noparse][[/noparse]"!PWMSS",255]
    SEROUT 0,6,[noparse][[/noparse]"!PWMM1",16,0,24,0]
    STOP
    

    While the debug reads 255 I get a nice steady squarewave.
    While the debug reads 256 I get a squarewave but with intermittant glitches (almost like it is skipping pulses at times ?)
    It seems to happen more often right after the transition from 255 to 256 and again towards the return transition BUT never during the 255 part. And sometimes towards the middle of the 256 part.
    While listening the 'glitch' sounds like the refresh glitch.
    I.E. like an intermittant refresh glitch (but this only happens during the 256 part)
    If your scope doesn't pick it up you may want to try listening to the output. (the ears are more discerning than the eyes (and perhaps attendant instrumentation))
    I don't know about my 'firmware'
    I assume you mean the 'PWMPAL ID string' ?
    I can't quite figure out how to set up the "3 byte array" and then write to it? and debug it?
  • hitswarehitsware Posts: 156
    edited 2007-04-23 22:45
    >Remember, the duty cycle cannot operate in the full range over the entire range of frequencies.

    This is 50/50 duty cycle in both the 255 and 256 parts.
    Only the frequency is slightly changed.
    From 20000/255=78.4 Hz
    To 20000/256=78.1 Hz
    It seems to be the extra byte that upsets the apple cart.
  • hitswarehitsware Posts: 156
    edited 2007-04-24 14:25
    version var byte(3)
    serout 0,6,[noparse][[/noparse]"!ID"]
    serin 0,6,[noparse][[/noparse]STR version\3]
    debug asc ? version

    Returns: version = "1"
    I was expecting 3 characters, so don't know if this is right?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-28 02:20
    Hello,

    The reason you’re getting only one character is because you’re using the ASC ? in your code. To see the string array you need to do the following:

    DEBUG STR version

    This will display the full 3-digit string array.

    By the way, you last message somehow got posted three different times in two threads. I removed the extras for you. =)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • hitswarehitsware Posts: 156
    edited 2007-04-28 02:33
    >By the way, you last message somehow got posted three different times in two threads. I removed the extras for you. =)

    Thank You so much [noparse]:)[/noparse]

    Returns: "1.1"

    Post Edited (hitsware) : 4/29/2007 1:09:45 AM GMT
  • hitswarehitsware Posts: 156
    edited 2007-04-30 00:30
    How much power could you safely draw from a PWMPAL ?
    Worst case run all 4 channels (with the same instructions)
    In parallel ...
    I.E.....Could you safely go below 220 Ohm on the summing resistors ?
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-04-30 00:38
    What is this thing newbies have about "driving things" from processor chips? It's a PROCESSOR, it's not a POWER SUPPLY, nor a transistor, buffer, darlington amplifier, or other 'power' piece of equipment. There's LOTS of stuff that can drive current. Only a processor can make useful signals.

    So no, you probably can't go below 220 ohm on the summing resistors. Look up Darlington Integrated Circuits.
  • hitswarehitsware Posts: 156
    edited 2007-04-30 00:53
    OK ...
    So if I want to say drive a 45 Ohm speaker , then the 55 Ohm output impedance
    (220/4) should cause no problems.
    Thank You.....[noparse]:)[/noparse]
Sign In or Register to comment.