### Author Topic: pulses on H3  (Read 1814 times)

0 Members and 1 Guest are viewing this topic.

#### vidam

• Supreme Robot
• Posts: 423
• Robotronics.org
##### pulses on H3
« on: August 23, 2008, 08:52:06 PM »
I'm trying to set up pin H3 as an output to generate servo pulse signals to the Axon in MCU mode.

The target timer count for servo pulse signals are calculated as follows:

Target timer count = (1 / target frequency) / (1 / timer frequency)

1.) For Axon the timer frequency is 16 MHz at 1000 us pulse:

target timer count = (1 / 1000 Hz) / ( 1 / 16 MHz) = 16,000

2.) For 1500 us:

target timer count = 10,666. 6667

3.)  For 2000 us:

target timer count = 8000

Running at 16MHz, our timer needs to count to 8,000, 10,667, and
16000 counts before 1000 u, 1500 us and 2000 us has elapsed,
respectively.

Set up the DDRH (data direction register for H) as an output:

Code: [Select]
`DDRH |= (1 << 3); // Set H3 as output on Register HStart the timer at the top of our main routine, and upply a clock of Fcpu to the timer 1circuits.TCCR1B |= (1 << CS10); // Set up timer to system clock with no prescalerTCNT1 = 0;// generate 2000 usec pulse on H3while(TCNT1 <= 8000){ PORTH = (1 << 3); // Send a pulse to H3}PORTH ^= (1<<3); // set the pulse to 0 on H3TCNT1=0; // reset counter// generate 1500 us pulse while( TCNT <= 10,667){ PORTH = (1<<3);}PORTH ^= (1 << 3); // return to 0TCNT1 = 0;// generate 1000 us pulsewhile(TCNT <= 16,000){  PORTH = (1<<3);}PORTH ^= (1<<3)TCNT1 = 0;`
Does this seem right?

• Supreme Robot
• Posts: 11,673
##### Re: pulses on H3
« Reply #1 on: August 23, 2008, 09:51:23 PM »
Quote
I'm trying to set up pin H3 as an output to generate servo pulse signals to the Axon in MCU mode.
Why not just use this one single line? Try a value of around ~500 for position to get it centered.

servo(PORTH,3,position);

#### airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
##### Re: pulses on H3
« Reply #2 on: August 23, 2008, 10:22:24 PM »
Maybe you wanna ditch cycles based servo control and instead use time based?

I wrote a quick macro ( with pomprockers help) to control servo with uS

Heres the macro:
Code: [Select]
`void pulse(unsigned long int microseconds) {     microseconds=microseconds/16;     while (microseconds > 0) {          delay_us(1);          microseconds--;     }  // end while loop} // end pulse function `

and heres the modified servo define code:
Code: [Select]
`//define the servo function macro#define servo(port,number,position)   (PORT_ON(port,number), pulse(position), PORT_OFF(port,number))`
To call the macro I just do :
Code: [Select]
` servo_1(1500)  // where 1500 is the pulse in microseconds.`

« Last Edit: August 23, 2008, 10:24:58 PM by airman00 »
Check out the Roboduino, Arduino-compatible board!

www.Narobo.com

#### vidam

• Supreme Robot
• Posts: 423
• Robotronics.org
##### Re: pulses on H3
« Reply #3 on: August 24, 2008, 06:46:22 AM »
This is the Dimension Engineering Sabertooth mode to control motors in MCU RC mode. Here is an example taken from their user guide:
Code: [Select]
` Output_High(Pin connected to S1)Delay(1000us to 2000us)Output_Low(Pin connected to S1)`So airman is right in his guess. I didn't provide enough information about my intention probably.

I just need to provide the 1000 us, 1500 us, and 2000 us pulses and of course anything in between this range will work too.

Thanks,

#### izua

• Supreme Robot
• Posts: 682
##### Re: pulses on H3
« Reply #4 on: August 24, 2008, 07:43:31 AM »
Rememeber you still need to wait some time after the line goes low! That's a very common mistake, I've pointed it out at least three times here.

edit: the high time and low time should sum up at 20ms (50Hz)
« Last Edit: August 24, 2008, 07:44:04 AM by izua »
Check out my homepage for in depth tutorials on microcontrollers and electronics.

#### vidam

• Supreme Robot
• Posts: 423
• Robotronics.org
##### Re: pulses on H3
« Reply #5 on: August 24, 2008, 02:51:20 PM »
I could not get this mode working with my Sabertooth. Back to simplified serial mode on the Sabertooth. At least i know this worked in the past.

#### airman00

• Contest Winner
• Supreme Robot
• Posts: 3,653
• narobo.com
##### Re: pulses on H3
« Reply #6 on: August 24, 2008, 08:14:53 PM »
Rememeber you still need to wait some time after the line goes low! That's a very common mistake, I've pointed it out at least three times here.

edit: the high time and low time should sum up at 20ms (50Hz)

true but you only need to wait 20ms after the entire servo control block - you don't have to wait 20 ms after every servo movement
For example: if you have 20 servos you wait 20ms after you told each servo where to go rather then tell each servo where to go and wait 20ms after each instruction per servo.
Check out the Roboduino, Arduino-compatible board!