Pages: [1]   Go Down
Author Topic: 1 kHz PWM signal  (Read 924 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey y'all,
I'm trying to create a 1kHz PWM to control a firgelli L12. First time using an Arduino - it should be simple but I'm pretty sure the frequency is off judging by the the way the actuator is spazzing about (it sort of goes to the configuration but then keeps on making slight movements rather than sitting still). Here's the code:
Code:
pinMode(10, OUTPUT);

TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11) | _BV(WGM10);
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10);

OCR1AH = 0;
OCR1AL = 250;

OCR1BH = 0;
OCR1BL = 30;

So I was hoping the timer would count up to 250 and then reset. Any idea what I've missed?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The count is zero-relative so if you want 250 you need to enter 249.

I just tested that, and with 249 you get a 1 kHz signal with a 12.4% duty cycle. If you were hoping for a 12% duty cycle make the 30 to be 29 for the same reason.
Logged

0
Offline Offline
Shannon Member
****
Karma: 162
Posts: 10496
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On an Arduino with a crystal those settings produce 996Hz, using OCR1A = 249 gives 1kHz.

If you are using an Uno with a resonator expect +/- 0.3% accuracy - I can't imagine the device
cares about the precise frequency though, I think it is LPF'ing it.

The actuator is spec'd to 0.1mm, so if the variation is below that level its perfectly in-spec.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: