Author Topic: Yet another question about servos and PWM  (Read 2364 times)

0 Members and 1 Guest are viewing this topic.

Offline SteveTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Yet another question about servos and PWM
« on: October 08, 2008, 07:13:51 PM »
First, may I say how great this site is. I stumbled across it about a week ago and have browsed virtually the whole site. My son is using LEGO Dacta with ROBOLAB but I think this will be the next step.

I have two questions:

1) How precise a time does the servo need between each pulse? Like, if I specify 1ms high then 19ms low, any extra code or functions in the main loop are going to increase this 19ms delay, are they not? Do I have to keep adjusting these delays every time I add a new servo or other function in the main loop relying on delays? Or is there some way to cause delays without stopping other code from running? (other than using interrupts, that is)

2) I am familiar with programming in basic, visual basic, and Assembly (have programmed PICs before), but have never used C. Is there a difference in language structure or syntax between different varieties of C compilers for PIC?

Thanks,
Steve.

Offline szhang

  • Robot Overlord
  • ****
  • Posts: 140
  • Helpful? 1
Re: Yet another question about servos and PWM
« Reply #1 on: October 08, 2008, 11:06:44 PM »
Not very precise.  The feed-back control in a servo isn't that finely tuned so the overhead from loops won't matter.

Interrupts are good ways of getting good timings, and are very useful.  Learn them.  (They still have a tiny overhead from switching)

For C, the syntax is the same, but the built in functions and the header files are different.  For example, how you can access a pin on the chip would be different on two different compilers.

Offline SteveTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Yet another question about servos and PWM
« Reply #2 on: October 11, 2008, 12:46:11 AM »
Thanks for that. I have used interrupts in ASM before on simpler devices such as the 16F84, so I don't mind using them, but I think I could run into trouble if I try and use too many interrupts for several functions. I was thinking there was a way of accessing the timer0 count without interrupts. Is there away of polling the timer counts in the main loop?

I'm planning on downloading C18 as I already have MPASM 8.10. The chip I 'm getting is the F184550.

Steve.

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: Yet another question about servos and PWM
« Reply #3 on: October 11, 2008, 10:28:16 AM »
Keep your ISR's very short and you'll stay out of trouble.

Offline SteveTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Yet another question about servos and PWM
« Reply #4 on: October 12, 2008, 02:28:51 AM »
OK, so ideally, I could keep all my tasks in 'main' and use the timer0 interrupt to set flags for these tasks to be carried out.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: Yet another question about servos and PWM
« Reply #5 on: October 14, 2008, 03:09:36 AM »
Quote
Is there a difference in language structure or syntax between different varieties of C compilers for PIC?
Yeap there is definitely syntax differences. But you don't need any advanced programming skills to do robots if you have source code to look at, such as the $50 Robot code.

 


Get Your Ad Here