Shop OBEX P1 Docs P2 Docs Learn Events
SX/B PWM command frequency — Parallax Forums

SX/B PWM command frequency

Robert SchwartzRobert Schwartz Posts: 141
edited 2005-07-09 13:53 in General Discussion
Hello everybody,
Does anyone know the frequency for the PWM command in SX/B. Also, is it constant, or dependant on clock speed?

Thanks,
Robert Schwartz

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-08 00:50
    The PWM instruction is accumulator-based; it's intent is to charge an RC circuit to provide an analog output. The duration parameter is speed independent.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Robert SchwartzRobert Schwartz Posts: 141
    edited 2005-07-08 04:08
    I don't mean how long the string of pulses will last, I mean how long each pulse last. I want to use PWM to control motors (by toggling enable). However, the maximum frequency that my motor driver can accept is roughly 1Mhz. I need the frequency of the PWM pulses to be less than that for this to work.
  • pjvpjv Posts: 1,903
    edited 2005-07-08 04:57
    Robert;

    If you set the interrupt rate at 1 MHz, then your wish is granted.

    Cheers,

    Peter (pjv)
  • Robert SchwartzRobert Schwartz Posts: 141
    edited 2005-07-08 18:43
    Thanks, but how exactly do I do this. I think it is somewhere in the option register(?), but not sure where. Can the speed be changed to any frequency below 1/2 operating ferquency?
    Thanks,
    Robert Schwartz

    Post Edited (Robert Schwartz) : 7/8/2005 6:49:38 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-08 18:51
    Peter, I think Robert is specifically asking about the SX/B PWM command, which Im pretty sure is mainline code not ISR. Robert, I don't know if you can alter the base frequency of the SX/B command. If not, just use Bean's 16 channel PWM code, it is written in SX/B (non-ISR code), the interrupt method provides you with more control over the PWM. Or compile the PWM command you want, and modify the generated code. I know this requires assembly, but I don't know if you can achieve what you looking for with SX/B alone. The PWM command is clock dependant, so changing oscillator frequency will change the PWM frequency, but I would not try to solve this issue·by swapping out the oscillator.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-08 19:20
    The PWM instruction is accumulator based so it does not have a fixed frequency or period -- what it's good at is charging an RC circuit to provide analog output. You could actually route the RC connection to one side of the comparator and create a little 8-bit A2D converter using PWM to "hunt" for the unknown voltage.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-08 19:34
    Ok so the PWM is accumulator based, the format is "PWM pin, duty, cycles", he is asking what the cycle unit is, IOW what is the equivalent "Unit in Cycles" for an SX executing the PWM command, as disclosed for each BS breed in Table 5.94 in the Stamp User Manual. I don't have access to the SX/B help files at the moment to determine if this is given. I know that the cycle unit is dependent upon the oscillator frequency, but you should be able to provide an equation for the cycle unit using the oscillator frequency as a parameter.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-08 19:51
    After further thought, I have become more confused, Jon you state there is no fixed frequency. All BS PWM commands do have a fixed frequency as disclosed in Table 5.94, where cycles dictates how many of these fixed frequency oscillations occur. Are you stating that the SX/B PWM command does not operate the way·BS PWM does?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-08 22:04
    Maybe I'm not the best guy to explain it ... I know how use it, but that's probably where my expertise stops. The great thing about SX/B is that you can look "under the hood" by examining the output of the SRC file (or use Ctrl-L) to see the assembly listing. This should tell you everything you want to know.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • pjvpjv Posts: 1,903
    edited 2005-07-08 22:10
    Robert/Paul;

    I see I should read more carefully Robert as your question was SX/B related. I missed that point, and answered a the question in an assembler reference....·thanks Paul for catching that.

    As you all know, I am SX/B challenged, hence unqualified to comment; I should have kept my mouth shut.

    Happy SX/B'ing,

    Peter (pjv)
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-09 07:01
    Well here is the generated code for PWM rb.0, 128, 3

       168  006B  0CFB        MOV FSR,#TRIS_B                ;  PWM rb.0, 128, 3
            006C  0024
       169  006D  0400        CLRB IND.0                    
       170  006E  005F        MODE $0F                      
       171  006F  0200        MOV !RB,IND                   
            0070  0006
       172  0071  0018        BANK $00                      
       173  0072  0C03        MOV __PARAM1,#3               
            0073  0028
       174  0074  0069        CLR __PARAM2                  
       175  0075  0C02        MOV __PARAM3,#2               
            0076  002A
       176  0077  0C41        MOV __PARAM4,#65              
            0078  002B
       177  0079  0C80        ADD __PARAM2,#128             
            007A  01E9
       178  007B  0703        MOVB rb.0,C                   
            007C  0406 0603 0506
       179  007F  02EB        DJNZ __PARAM4,@$-6            
            0080  0010 0A79
       180  0082  02EA        DJNZ __PARAM3,@$-9            
            0083  0010 0A79
       181  0085  02E8        DJNZ __PARAM1,@$-16           
            0086  0010 0A75
       182  0088  0CFB        MOV FSR,#TRIS_B               
            0089  0024
       183  008A  0500        SETB IND.0                    
       184  008B  005F        MODE $0F                      
       185  008C  0200        MOV !RB,IND                   
            008D  0006
       186  008E  0018        BANK $00                      
       187                  
    

    Its too late to diasect it completely tonight, but its clear its a triple loop. 1st param is the # of cycles, 2nd·param is the accumulator which is incremented by the duty cycle each pass, the carry bit determines the output. 3rd and 4th params, Im not sure of, one of these probably determines the general frequency.
  • BeanBean Posts: 8,129
    edited 2005-07-09 13:53
    Paul,
    Since the duration parameter is in milliseconds, __PARAM3 and __PARAM4 create enough loops to last for 1 millisecond.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    Product web site: www.sxvm.com

    "One experiment is worth a thousand theories"
    ·
Sign In or Register to comment.