Author Topic: Receivers, Servos and PIC18F8520  (Read 4387 times)

0 Members and 1 Guest are viewing this topic.

Offline Iron ManTopic starter

  • Full Member
  • ***
  • Posts: 74
  • Helpful? 0
Receivers, Servos and PIC18F8520
« on: May 18, 2008, 11:35:09 AM »
alright

i'm going absolutely nuts. I'm not new to this whole programming thing, but i am new to embedded programming.

I think i've managed to wrap my head around interrupts.

Anyways, what i'm trying to do is read the servo out of a Hitec Radio receiver.  and just recreate it on another pin.

sound simple.

but i've been working at this on and off for 2 weeks and it's driving me nuts.

Right now i'm attempting to reading the signal with a CCP module, but that only gives me the period. and i need the duty cycle... but i'm not quite sure how to do this.

i feel like i'm not giving you enough information, but if you ask i can tell all.

paulstreats

  • Guest
Re: Receivers, Servos and PIC18F8520
« Reply #1 on: May 19, 2008, 04:18:11 AM »
Cant you just set up a timer to count how long between the period readings ? the timer reading should be the duty. (probably use a 16 bit timer probbly timer 2 on that pic)

Offline dolinay

  • Contest Winner
  • Jr. Member
  • ****
  • Posts: 18
  • Helpful? 0
Re: Receivers, Servos and PIC18F8520
« Reply #2 on: May 19, 2008, 07:26:56 AM »
I don't know PIC much, but played with something similar on Motorola. You could measure the duty like this:

 1) check the level on the input pin (receiver output)
 2) if it is 1, increment variable V1; if it is 0, increment V2
 repeat steps 1) and 2) quickly (say, 20-thousant times a second in timer interrupt routine or even in loop in the program) for e.g. 1 sec.
 Duty cycle is V1 / V2.   

If you just need to copy the receiver output to another pin without any change, you could just set up interrupt on the input pin so that it is generated for both rising and falling edge and in the interrupt routine then do something like this:
 if ( Input_pin == 0 ) Output_pin = 0; else OutputPin = 1;

Or the interrupt routine set up as in prev. case could measure the length of the "pulse" - which defines servo position - like this:

if ( Input_pin == 1 && Measuring == false)   // interrupt from start of the pulse
{  Reset_Timer_Counter; Measuring = true; }

if ( InputPin == 0 && Measuring )
  { pulse_length = TIMER_COUNTER; Measuring = false; }


Actually, the period of the signal (and duty also) should not be important - position of the servo is defined by the length of the pulse (1 to 2 ms). At least I think so...  ???


 

Offline Iron ManTopic starter

  • Full Member
  • ***
  • Posts: 74
  • Helpful? 0
Re: Receivers, Servos and PIC18F8520
« Reply #3 on: May 19, 2008, 10:10:12 AM »
you're right about the the width of the signal

but the PIC controller determines the width using the duty cycle and the period. They measure the width in time.

sounds like a pretty good idea, i'll try it out today and let you know how it went.

If I don't let you know... assume that I've gone nuts and shrunk myself to the size of information bit, so i could go beat up this stupid processor.

Offline Iron ManTopic starter

  • Full Member
  • ***
  • Posts: 74
  • Helpful? 0
Re: Receivers, Servos and PIC18F8520
« Reply #4 on: May 19, 2008, 10:16:08 AM »
Cant you just set up a timer to count how long between the period readings ? the timer reading should be the duty. (probably use a 16 bit timer probbly timer 2 on that pic)

That's what i currently have, is timer 1 measuring between "rising edges" which would be the period of the PWM (timer 2 is actually 8 bits, with a 8 bit period register used for creating PWMs.)

           |---------------Period-----------|
            __________                   ___________
______|                  |_________|

          |--Duty Cycle--|


There's the diagram of your typical PWM, but the two rising edges would define the period, not the duty cycle wouldn't they?

or am i not understanding what you're saying?

Offline Iron ManTopic starter

  • Full Member
  • ***
  • Posts: 74
  • Helpful? 0
Re: Receivers, Servos and PIC18F8520
« Reply #5 on: May 19, 2008, 03:33:35 PM »
http://www.societyofrobots.com/remote_control_robot.shtml

i just used the square wave to analog resistor to capacitor circuit.

.... testing to see if that works.

Offline Iron ManTopic starter

  • Full Member
  • ***
  • Posts: 74
  • Helpful? 0
Re: Receivers, Servos and PIC18F8520
« Reply #6 on: May 19, 2008, 03:59:14 PM »
ya totally worked.

..... well chalk one more up for "read the tutorials NOOB"

thanks guys.

 

SMF spam blocked by CleanTalk