Announcement

Collapse
No announcement yet.

PWM on Atmel RF200 Engine

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    ARQuattr, I have a oscope connected to GPIO0 and see no output. How do I select OC0A? I don't understand how to map OCRxA to a pin number.

    Comment


    • #32
      I don't think you can change the mapping of OCR pins to different GPIO. If you look at the datasheet for the RF200 you'll see that the GPIO0 pin is shared with OC0A and OC1C, among others. So for example you would need to use timer 1 and select OCR C to get the output on the GPIO0 pin. I haven't tried all the outputs but I've used OC1B (on GPIO1) and OC1A (on GPIO2). They both run from the same timer (timer 1).

      Comment


      • #33
        That was the ticket!

        ARQuattr, that's what I did not understand! Changing my code to TMR1 and OCRxC did the trick. Thank you very much.
        Code:
        timer_init(TMR1, WGM_FASTPWM16_TOP_ICR, CLK_FOSC_DIV64, icr)
        set_tmr_ocr(TMR1, OCRxC, icr>>1)  # Set B output duty cycle to 1/2
        set_tmr_output(TMR1, OCRxC, TMR_OUTP_CLR)  # Enable PWM on pin
        Now my buzzer is working and I can see the pulse stream on my scope.

        Comment


        • #34
          I'm now trying to get PWM to work with a servo. I can set the frequency to 50Hz, but I need to be able to set the pulse width to between .8 ms and 2.2 ms. Any suggestions?

          Comment


          • #35
            You should be able to adjust the duty by calling set_tmr_ocr again with a new val argument, e.g. use 10 for 0.8ms and 28 for 2.2

            Comment


            • #36
              I've got my servo working by trial and error.

              Code:
              set_tmr_ocr(TMR1, OCRxC, val)
              If I put my scope on it I see the following:
              Code:
              val            pos     PW
              ---------------------------------
              188(0xbc)       0     750us
              394(0x018a)    ~90    1580us
              600(0x0258)    ~170   2400us
              The datasheet says the servo will rotate 180 deg but I can't get it to go that far before it starts to chatter.

              ARQuattr, could you explain how you came up with those numbers?

              Comment


              • #37
                I was basing that off an 8-bit timer but I see you have it in 16bit mode. So assuming you are using similar code to determine the icr value as you did for the buzzer, then it would be icr=5000 for 50Hz (20ms period). Therefore, for 2.4ms, 5000 * 2.4/20 = 600 which is what you found. The value of val should be 250*pw where pw is pulse width in milliseconds.

                Comment


                • #38
                  250 is the scale factor I came up with. Thanks for confirming my approach.

                  Comment

                  Working...
                  X