Servo Tester on ATTiny13 Bascom

Discussion in 'Embedded Systems and Microcontrollers' started by HarveyH42, Dec 8, 2007.

  1. HarveyH42

    Thread Starter Active Member

    Jul 22, 2007
    425
    5
    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.

    Code ( (Unknown Language)):
    1. $regfile = "attiny13.dat"
    2. $crystal = 4800000
    3.  
    4. Config Portb.0 = Output
    5. Dim A As Word
    6. Do
    7. For A = 1 To 20
    8. Pulseout Portb , 0 , 1500
    9. Waitms 20
    10. Next
    11. For A = 1500 To 1000 Step -10
    12. Pulseout Portb , 0 , A
    13. Waitms 20
    14. Next
    15. For A = 1 To 20
    16. Pulseout Portb , 0 , 1500
    17. Waitms 20
    18. Next
    19. For A = 1500 To 2000 Step 10
    20. Pulseout Portb , 0 , A
    21. Waitms 20
    22. Next
    23.  
    24. Loop
    25. End
    The servo control signal comes off pin 5, uses internal clock. Starts center, moves left, center, then right.
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  3. HarveyH42

    Thread Starter Active Member

    Jul 22, 2007
    425
    5
    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.
     
  4. Jaydmdigital

    New Member

    Feb 13, 2008
    2
    0
    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
     
  5. HarveyH42

    Thread Starter Active Member

    Jul 22, 2007
    425
    5
    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.
     
  6. Jaydmdigital

    New Member

    Feb 13, 2008
    2
    0
    Maybe I wasn't clear. I know very well how to control a servo with a MCU. What is new to me is this particular part from Atmel. Did you notice any issue with jitter (server jumping rather than staying locked in position)? I'm trying to determine if I need a different part and design before my AVR Dragon arrives and I can program the Tiny13's I already ordered. I really love the idea of a $1.30 for a chip as a solution :D I'm used to working on the Mega128 but the core remains the same so that really helps.

    Thanks for your time,
    Jay
     
  7. HarveyH42

    Thread Starter Active Member

    Jul 22, 2007
    425
    5
    I was going for a sweep, and it runs smoothly. It holds steady at the center 1.5 ms, until triggered to sweep left or right. Not sure if that answers the question.

    Last time I ordered Tiny13, they were $0.88 each from Digikey, for 25...
     
  8. cheeto4493

    New Member

    Nov 7, 2008
    4
    0
    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
     
  9. HarveyH42

    Thread Starter Active Member

    Jul 22, 2007
    425
    5
    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=).
     
  10. cheeto4493

    New Member

    Nov 7, 2008
    4
    0
    Code ( (Unknown Language)):
    1. Error : 22    Line :   5     Out of SRAM space  , in File : C:\TRAVS\AVR PROJECTS\SERVO TESTER\SERVO TEST.BAS
    2. Error : 46    Line :   7     Assignment error [A: 0   1: 112]  , in File : C:\TRAVS\AVR PROJECTS\SERVO TESTER\SERVO TEST.BAS
    3. Error : 31    Line :   7     Invalid datatype [[0006]]  , in File : C:\TRAVS\AVR PROJECTS\SERVO TESTER\SERVO TEST.BAS
    4. 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.
     
  11. cheeto4493

    New Member

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

    New Member

    Nov 7, 2008
    4
    0
    I added,

    Code ( (Unknown Language)):
    1. $hwstack = 32
    2. $swstack = 10
    3. $framesize = 40
    And it seems to have fixed the errors, need to break out the chip and the servo and give it a test run.
     
Loading...