ATtiny85 – RC switch

I have finally managed to program an ATtiny85 to act as a RC switch! The switch will work as a “poor-man’s-ESC-reverse”. I bought a cheap ESC for my Ballbot Project and it has no reverse mode, it is made for RC aeroplanes, so I have to implement a relay that acts as a “polarity-switch” to be able to make a reveres motion on the motors.

The ATtiny85 will read the position of the throttle stick, when the stick reaches about centre position the motor will stop, and the relay switch the polarity. Depending on if the throttle stick travels from centre to top or centre to bottom the motor will now be able to go into forward motion or revere motion. Without the RC switch the motor will go from forward to stop to forward again.

CamZ-20150422103637827

Looking at the receiver’s PWM-signal with an oscilloscope

At first I thought I could get the PPM-signal from the receivers battery pin, but it turned out that it uses some sort of serial communication and not PPM. I decided to take a look at the PWM-signal coming directly from channel one instead. It has a timing between 920-2060 µs when moving the throttle stick, and setting the travel rate to +/-150% in my Spektrum DX7 transmitter.

When it came to programming the MCU I simply (not too simple at fist because I’m a noob 😉 ) made a tiny C-program with a pin change interrupt reading the PWM-signal from channel one (throttle stick). With this information I can determine if the stick travels from centre to top or centre to bottom by making some simple if- and else-statements, se below:

if(PINB & (1 << PINB3))    //if PB3 is HIGH
{
    TCNT1 = 0;//resets counter/timer1
}

else
{
    if(pulse > 96)    //when stick 1 travels from 1.52 ms towards 2.06 ms
    {
        PORTB &= ~(1 << PORTB2);    //relay pole switch, + & - on motor 
        PORTB |= (1 << PORTB1);    //LED green indicates forward motion
        PORTB &= ~(1 << PORTB0);    //turn off red LED
    }
			
        else if (pulse < 93)    //when stick 1 travels from 1.48 ms towards 0.92 ms
        {
            PORTB |= (1 << PORTB2);    //relay pole switch, - & + on motor 
            PORTB &= ~(1 << PORTB1);    //turn off green LED
            PORTB |= (1 << PORTB0);    //LED red indicates backward motion
        }	
			
    else
    {
			
    }
		
}
Get the source code from my Git repository HERE!

In the clip you can see the code in action, using two LEDs to indicate forward and reverse motion. I will later on make a PCB for the ATtiny85, a relay and a bi-LED for direction indication.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *