# Servo Tester on ATTiny13 Bascom

#### HarveyH42

Joined Jul 22, 2007
426
Finally got a servo running on a Tiny13, figured I share the code if anyone is interested. Pretty simple, for all the time I spent learning this stuff. Started AVR about a year ago, Bascom a few weeks ago. Kind of huge major breakthrough for me.

Rich (BB code):
$regfile = "attiny13.dat"$crystal = 4800000

Config Portb.0 = Output
Dim A As Word
Do
For A = 1 To 20
Pulseout Portb , 0 , 1500
Waitms 20
Next
For A = 1500 To 1000 Step -10
Pulseout Portb , 0 , A
Waitms 20
Next
For A = 1 To 20
Pulseout Portb , 0 , 1500
Waitms 20
Next
For A = 1500 To 2000 Step 10
Pulseout Portb , 0 , A
Waitms 20
Next

Loop
End
The servo control signal comes off pin 5, uses internal clock. Starts center, moves left, center, then right.

#### hgmjr

Joined Jan 28, 2005
9,029
Greetings HarveyH42,

I too started playing around with AVRs about a year ago. I began the adventure using assembly language and shortly after I started using the WINAVR C-language. I have had tons of fun with AVR and have used it to help me with a number of test issues at my work. I won a cash award from my company that permitted me to purchase an ipod to which I have become very attached.

I have used AVRs to explore robotics and RGB LEDs and graphic LCD displays.

I have 2 stk500 boards and I am wearing them out.

I think you have made a fine decision to learn AVRs.

Nice job on the servo program.

Happy AVRing.
hgmjr

#### HarveyH42

Joined Jul 22, 2007
426
I chose AVR for a number of reasons, one was that I was more familiar with assembly language (6502). Avr seemed to have the richest instruction set, registers, ect. Worked fine for most stuff, but had a huge problem with precise timeing and pulses. So went with BASIC, since I have no 'C' experience.

Now that I've got the servo under control, the rest of this particular project should go pretty easy. It's a pan platform for an Airsoft gun, using two PIR modules to sweep left or right. It's for my backyard, to scare of the neighbor's cats, think he's back up to 14 or so. The over population, makes my yard a convient toilet for them. My next challenge is to figure out which device to use to fire the gun. Need to measure the current draw from the gun's motor, and choose a transistor or something.

The Airsoft gun is basically weak an harmless, doubt it will do any damage. Yard is completely fenced in. The pellets are flouresent and easy to find with an ultraviolet flashlight at night, for reuse.

A little concerned about false triggering from the PIR in daytime. May have to shut it down during some periods during the day.

#### Jaydmdigital

Joined Feb 13, 2008
2
Can you explain/show the circuit you used. Other posts I've seen aout controlling/generating a servo pulse with this part mention jitter and constant tuning of the internal oscillator. I'm trying to find out how suitable this device would be for my small project.

Thanks,
Jay

#### HarveyH42

Joined Jul 22, 2007
426
Can you explain/show the circuit you used. Other posts I've seen aout controlling/generating a servo pulse with this part mention jitter and constant tuning of the internal oscillator. I'm trying to find out how suitable this device would be for my small project.

Thanks,
Jay
Really not much to it. I just started with the BASIC compiler, and needed to drive a servo, this what I got to work. It's more of a building block, not a project of itself.

The standard R/C servo has three wires, +,_, and control signal, runs on 5v more or less. The Tiny13 has 8 pins, pin 8 is +5v, pin 4 is -5v, pin 5 is programmed for signal out. Don't see much point in drawing a picture, and it's really up to what yo want to do with it from here. There should be a capacitor across the power pins. An external crystal is just more parts, servos don't demand such high stability.

I'm no expert on this stuff, it worked and figured it might be useful bit for others as a building block.

#### Jaydmdigital

Joined Feb 13, 2008
2
Really not much to it. I just started with the BASIC compiler, and needed to drive a servo, this what I got to work. It's more of a building block, not a project of itself.

The standard R/C servo has three wires, +,_, and control signal, runs on 5v more or less. The Tiny13 has 8 pins, pin 8 is +5v, pin 4 is -5v, pin 5 is programmed for signal out. Don't see much point in drawing a picture, and it's really up to what yo want to do with it from here. There should be a capacitor across the power pins. An external crystal is just more parts, servos don't demand such high stability.

I'm no expert on this stuff, it worked and figured it might be useful bit for others as a building block.

#### cheeto4493

Joined Nov 7, 2008
4
I am very new to Bascom. And fairly new to AVR's. I copied the code you pasted as a new program, and tried to compile it, but when I ran the simulator, it showed errors.

Are there other parts of the program that you didn't copy?

~Travis

#### HarveyH42

Joined Jul 22, 2007
426
I am very new to Bascom. And fairly new to AVR's. I copied the code you pasted as a new program, and tried to compile it, but when I ran the simulator, it showed errors.

Are there other parts of the program that you didn't copy?

~Travis
That was the whole thing. That was one of my first BASCOM programs. I still have a lot to learn, many questions myself. What kind of errors are you getting? I've had troubles on other projects with the Stack. Don't remember the specifics, and haven't moved that stuff over to this computer yet. Remembered copying the two lines at the beginning of one of the example Tiny13 programs that set up the stack (HWStack=).

#### cheeto4493

Joined Nov 7, 2008
4
Rich (BB code):
Error : 22    Line :   5     Out of SRAM space  , in File : C:\TRAVS\AVR PROJECTS\SERVO TESTER\SERVO TEST.BAS
Error : 46    Line :   7     Assignment error [A: 0   1: 112]  , in File : C:\TRAVS\AVR PROJECTS\SERVO TESTER\SERVO TEST.BAS
Error : 31    Line :   7     Invalid datatype [[0006]]  , in File : C:\TRAVS\AVR PROJECTS\SERVO TESTER\SERVO TEST.BAS
Error : 124   Line :   0     LOOP expected  , in File :
Like I said, I'm an absolute newbie to BasCom, this was my "Hello World" program for it. I used to use an OoPic, until It fried somehow, turned to AVR's 'cause they were way cheaper.

I've used WinAVR to program my chip by using the MinPOV2 C file, but I'm more familiar with Basic then C, so I thought I'd try BasCom.

#### cheeto4493

Joined Nov 7, 2008
4
If I change the chip to a attiny2313, it works fine, no errors.

#### cheeto4493

Joined Nov 7, 2008
4
$hwstack = 32$swstack = 10
\$framesize = 40