Shop OBEX P1 Docs P2 Docs Learn Events
sx52 timers — Parallax Forums

sx52 timers

Vertex78Vertex78 Posts: 51
edited 2006-10-27 23:05 in General Discussion
I am trying to learn how to use the timers on the sx52. I have read a bit on the subject but I am still confused on how exactly you would set everything up in asm to do anything. Could someone either post some simple code to create a pwm signal with a 50% duty cycle using the timers, or reference me to a good link that explains how to work with the timers.

Thanks

Comments

  • Vertex78Vertex78 Posts: 51
    edited 2006-10-27 21:20
    ok, here is what i got so far. I think it might work right, but I haven't gotten the chance to actually try it and hook up the scope.
    I am assuming he output pin will be rb.6 for timer1, is this correct?

    device sx52
    IRC_CAL IRC_SLOW
    RESET initialize
    FREQ 75_000_000
     
    
    ;**********
    ; EQUATES
    ;**********
    ;timer1
    rT1CPL            EQU        $00
    rT1CPH            EQU        $01
    rT1R2CML        EQU        $02
    rT1R2CMH        EQU        $03
    rT1R1CML        EQU        $04
    rT1R1CMH        EQU        $05
    rT1CNTB            EQU        $06
    rT1CNTA            EQU        $07
    wT1R2CML        EQU        $12
    wT1R2CMH        EQU        $13
    wT1R1CML        EQU        $14
    wT1R1CMH        EQU        $15
    wT1CNTB            EQU        $16
    wT1CNTA            EQU        $17
    
    ;timer2
    rT2CPL            EQU        $00
    rT2CPH            EQU        $01
    rT2R2CML        EQU        $02
    rT2R2CMH        EQU        $03
    rT2R1CML        EQU        $04
    rT2R1CMH        EQU        $05
    rT2CNTB            EQU        $06
    rT2CNTA            EQU        $07
    wT2R2CML        EQU        $12
    wT2R2CMH        EQU        $13
    wT2R1CML        EQU        $14
    wT2R1CMH        EQU        $15
    wT2CNTB            EQU        $16
    wT2CNTA            EQU        $17
    
    
    initialize
    
        ;load t1 compare register1 with the value of 50
        mov w,#wT1R1CML
        mov m,w
        mov w, #50
        mov !rb,w
        mov w,#wT1R1CMH
        mov m,w
        mov w,#0
        mov !rb,w
    
        ;load t1 compare register2 with the value of 50
        mov w,#wT1R2CML
        mov m,w
        mov w, #50
        mov !rb,w
        mov w,#wT1R2CMH
        mov m,w
        mov w,#0
        mov !rb,w
    
        ;do i need to change any of these?    
        mov w,#wT1CNTA
        mov m,w 
        mov w,#%11000000
    
        ;setup for prescale of 1/128 and pwm mode
        mov w,#wT1CNTB
        mov m,w
        mov w,#%00011101
    
    main
        
    jmp main
    
    
  • BeanBean Posts: 8,129
    edited 2006-10-27 23:05
    In SX/B you can just do:
    OUTPUT RB.6         ' Timer1 PWM output pin
    TIMER1 PRESCALE, 7  ' 1/128 prescale
    TIMER1 PWM, 50, 100 ' Set PWM mode output is on pin RB.6
    
    
    


    OUTPUT RB.6 ' Timer1 PWM output pin
    TIMER1 PRESCALE, 7 ' 1/128 prescale
    TIMER1 PWM, 50, 100 ' Set PWM mode output is on pin RB.6

    Then look at the generated code.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
Sign In or Register to comment.