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.
Announcement
Collapse
No announcement yet.
PWM on Atmel RF200 Engine
Collapse
X
-
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
-
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
Comment
-
I've got my servo working by trial and error.
Code:set_tmr_ocr(TMR1, OCRxC, val)
Code:val pos PW --------------------------------- 188(0xbc) 0 750us 394(0x018a) ~90 1580us 600(0x0258) ~170 2400us
ARQuattr, could you explain how you came up with those numbers?
Comment
-
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
Comment