11
 http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/ Food Living Outside Play Technology Workshop Attiny25/45/8 5 PWM generator and Servo tester! Updated Code! by Jan_Henrik on April 14, 2014 Table of Contents Attiny25/45/85 PWM generator and Servo tester! Updated Code!  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Intro: Attiny25/45/85 PWM generator and Servo tester! Updated Code!  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 1: Material and Tools  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 2: PCB layout  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 3: PCB layout #2  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Step 4: Assemble it!  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Step 5: The Software!  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Step 6: The code  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Step 7: Testing  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Step 8: Troubleshooting  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Step 9: Ideas!  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Step 10: Finishing  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Related Instructables  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Advertisements  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Comments  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Attiny254585 PWM Generator and Servo Tester

Embed Size (px)

DESCRIPTION

Attiny254585 PWM Generator and Servo Tester

Citation preview

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Food Living Outside Play Technology Workshop

    Attiny25/45/85 PWM generator and Servo tester! Updated Code!by Jan_Henrik on April 14, 2014

    Table of Contents

    Attiny25/45/85 PWM generator and Servo tester! Updated Code! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Intro: Attiny25/45/85 PWM generator and Servo tester! Updated Code! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Step 1: Material and Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Step 2: PCB layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Step 3: PCB layout #2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Step 4: Assemble it! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Step 5: The Software! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Step 6: The code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Step 7: Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    Step 8: Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    Step 9: Ideas! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    Step 10: Finishing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

    Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Intro: Attiny25/45/85 PWM generator and Servo tester! Updated Code!Hello, in this project I want to show you how to build a PWM generator with a Attiny processor. It is very easy to build and a nice project for starters as also forprofessionals. You will need some electronic knowledge and some knowledge about Arduino. It wont be to hard, because i already wrote a code for the Attiny, which youcan use.

    This PWM generator also works as servotester, it supports all kinds of servos, which dont need more then 5V

    Features:

    Operating voltage: 5VMax PWM current: 1 APWM frequency (by now) : 500HZ , I am trying to make that changeable, if you know how, let me know :)High effencysmall sizesmall prize ;)...

    So lets get started!

    Image Notes1. That is the servotester

    Step 1: Material and ToolsThe materials will cost less then 4$, also you need a Attiny programmer, i used an Arduino Uno!Materials:

    2 Resistors (450 OHM)1 Resistor (1 kOHM)1 BC548 NPN Transistor (or equal)1 BC516 PNP Transistor (or equal)some Jumpers1 Potentiometer (10 kOHM or higher)serval kinds of terminals (picture 1)some unisolated wire1 eight pin IC holder1 Attiny (25/45/85) I used the Attiny45some PCBsolder

    Tools:

    soldering irona cutter knifea pincera attiny programmer (Arduino Uno)a breadbaord...

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Image Notes1. Unisolated wire

    2. Solder

    3. 10 kOHM potentiometer

    4. Terminals with screw5. attiny456. PCB7. NPN transistor8. a single resistor :(9. Jumpers

    10. IC holder11. Terminals

    Step 2: PCB layoutHere is the PCB layout i made, beacuse of the less parts it is super simple and easy to build!

    The PWM output will be on pin 2 of the Attiny and the analog input will be on pin 4. The BC558 is used as Inverter and as a first amplifier.After that the BC516 is used to get the current to a maximum rating of 1A, what is actual very good and can drive a pc fan or a dc Motor!!!!

    note: the PWM signal is only against 0V not against 5V!

    !!! take care dont wire the Transistors wrong, it can cause a shortcircuit!!!

    Image Notes1. Attiny452. BC5163. BC558

    4. Potentiometer5. Output in the next step

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Image Notes1. Sometimes solder points are broken

    Step 3: PCB layout #2Now there is a special about this PWM generator. It has the ability to drive servos, the problem is that different manufacturer sue different pin connections for their servos.That makes problems, when you want to test serval kinds of servos, so i Made a connector system which allows you to change the output pins of the PWM generator!

    In picture 1 you can see the system, it has 3 jumper pads, one for the PWM signal, one for 5V (+) and one for 0V (-).As we change the Jumpers ( picture 2 ) we can change the ouput of the Servo connector on the right side.!!! NEVER have some Jumpers in a row, it will cause a short circuit and can destroy your PWM generator!!!

    In picture 2 the jumpers are correctly plugged!

    Image Notes1. 5V on theese pins2. 0V on those 33. PWm on this 3 pins4. this is connected5. this too

    Image Notes1. pwm signla goes here2. 5V go here3. to here4. 5V here5. PWM here6. 0V here7. to here8. PWM9. 0V10. 5V

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Image Notes1. Sometimes solder points are broken

    Step 4: Assemble it!My PCB looks now like this, I added a few sticker, terminals and a small potentiometer, to make it look nice.

    Its your choice how it will look like :)

    Image Notes1. That is the servotester

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Step 5: The Software!now its time to program the Attiny25/45/85! for this i use a Arduino Uno with a AttinyShield, but you dont need a shield! You can also do that on a Breadboard.

    A smal how to:

    1: Add the Attiny core to your Arduino software ( http://code.google.com/p/arduino-tiny/ )2: Wire your Attiny and Arduino like in the Picture 13: open your Arduino program4: go to File>Examples>ArduinoISP5: Upload it6: open a new window7: go to Tools>Board>Attiny45(internal 8 MHZ), click on it8: now open your code ( code for the project in the next step)9: Upload it.......wait.....wait.....10: Error : avrdude: please define PAGEL and BS2 signals in the.....is okay

    11: now your Attiny is programmed! (yay)

    Not working?

    Check out a full Instructable about it by @randofo its awesome and helped me alot

    http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/

    Step 6: The codeNow its time to program the Attiny!

    I wrote a code for this project, its made for the Attiny. By now it only supports 500HZ PWM, but i will update it as soon as i can.My goal is 50HZ, beacuse 50 HZ are needed for a servo.

    You can get my code from Git Hub:

    https://github.com/Jan--Henrik/Attiny-PWM-generat...

    Just upload it, as described in step 5, plug your arduino in the PCB and it should work.

    The is also a code aviable for the Arduino, dont change them, otherwise it wont work.

    Okay, here is a fixed code for servo testing only, it isnt a PWM signal, but it controlls servos!

    https://github.com/Jan--Henrik/Attiny-PWM-generato...

    And also here is a 15 HZ version of the PWM signal!

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    https://github.com/Jan--Henrik/Attiny-PWM-generato...

    Step 7: TestingFinally, your own personal PWM generator using a Attiny25/45/85 is ready for testing! :)First plug your 5V power source in, it is recommended to use one with a current monitor, because if the current go staright up to more then a few Ampere, you made amistake (troubleshooting in the enxt step).Mine uses a current of 10-20mA

    I used an old oscilloscope, but you can also build your own one!Just check out my other Instructable, How to build a Oscilloscope!!

    http://www.instructables.com/id/USB-Oscilloscope-with-Signal-generator/

    Importand: never place jumpers in the same row!!

    Video of the Output signal!!

    Image Notes1. That is the servotester

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Step 8: TroubleshootingCurrent goes to high:

    shortcircuit on the PCBBuilt around transistors falsBuilt around IC fals...

    No PWM at the output:

    make sure you emasure against 0V not against 5Vcheck connections on the board ( maybe something not soldered)IC not correctly plugged inOscilloscope right set?

    PCB catches fire

    ... -.-

    Image Notes1. Sometimes solder points are broken

    Step 9: Ideas!Idea:

    Instead of a potentiometer you can add a heat-dependent resistance and instead of a servo you can add a pc fanto control the speed of you pc fan, to cool your pc with more effectiveness.

    Its jsut an idea, to add sensors instead of a potentiometer...

    Image Notes1. My selfmade heat sensor, with a heat-dependent Resistor

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    Step 10: Finishingcongratulations!

    You made your own PWM generator, yes that is your own merit!!!

    Also thank you for reading, check out my other projects, and feel free to vote for me in a contest! :)

    Jan Henrikwww.janhenrik.org

    Related Instructables

    Attiny25/45/85Police Light,with Arduino! byJan_Henrik

    Arduino ISP toATTiny85 bybaelza.bubba

    Arduino, theSimple code! byJan_Henrik

    ATTiny poweredArduinoProjects - Imade it atTechShop bymadebyjoe

    Arduinoultrasonic rangefinder, with IClcd display! byJan_Henrik

    Attiny85 RFTransmitter toArduino UnoReceiver(Manchesterlibrary /wArduino 1.0) byfinlander912

    Advertisements

    Comments16 comments Add Comment

    jaker3278 says: May 7, 2014. 5:42 PM REPLYJan,

    I wrote my own pwm controller for a different microcontroller without using any built in pwm module using the following method:-

    1. set up an interrupt to generate 50*255 times per second. - so that you can time every 1/50th of a second in 255 little time slices.

    2. use a counter variable to count the interrupts as they happen and reset every 50 interrupts.

    3. use another counter variable then to count from 1 to 255 interrrupts in that 1/50th of a second.

    4. when the first counter resets to zero then set the pwm output to high. then, when the second counter hits your target width (by comparing its count with thepot input (suitably scaled to fit 1-255 range) you set the pwm output low.so, every 1/50th of a second the output goes high and then after a period determined by your pot value it will go low until the end of that 1/50 of a secondwhen it will go high again etc etc.

    hope that helps.

    cheers

    jakers dad

    Jan_Henrik says: May 8, 2014. 6:56 AM REPLYOkay, interresting, i will try it :)Thank you!!

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    jaker3278 says: May 8, 2014. 12:53 PM REPLYJan,

    sorry, I mangled that explanation a bit. You actually only need one interrupt counter if you dont need to keep track of the number of seconds. seeattached image which hopefully will make things clear.

    of course you may need to take into account that position control only wants pulses between 1 and 2 mS long and not the full 20mS of the 50Hzperiod. My pwm was for speed control rather than position (and i was controlling acceleration so i needed the seconds info) but all the same it willwork and is amazingly easy actually.

    good luck

    Jakers dad

    Jan_Henrik says: May 8, 2014. 10:23 PM REPLYYea, Thank you! :)

    tchai says: Sep 26, 2014. 2:30 PM REPLYHello,

    In order to test servo, why do you need transistor on the signal output?

    Jan_Henrik says: Sep 27, 2014. 2:55 AM REPLYThe idea is to also directly drive Motors and lamps with PWM :) you can remove it, when you only want to test servos!

    SergioA says: Aug 11, 2014. 6:27 AM REPLYsorry, what could be replacement for BC516? here i can not get it.

    Jan_Henrik says: Aug 11, 2014. 9:33 AM REPLYTheoretical any PNP Transistor :)

    domints says: Apr 15, 2014. 1:07 PM REPLYAbout the PWM frequency - if what you say is right, your "Arduino" is using the highest prescaler for the Timer1 (that one used to generate PWM on that pin). Soto increase frequency, you just have to decrease prescaler. You might try macro from core_timers.h from tiny_core:Timer1_ClockSelect( timer1_cs_t cs )as timer1_cs_t cs you might try some of the values:#define TIMER1_PRESCALER_VALUE_1 (1)#define TIMER1_PRESCALER_VALUE_2 (2)#define TIMER1_PRESCALER_VALUE_3 (4)#define TIMER1_PRESCALER_VALUE_4 (8)#define TIMER1_PRESCALER_VALUE_5 (16)#define TIMER1_PRESCALER_VALUE_6 (32)#define TIMER1_PRESCALER_VALUE_7 (64)#define TIMER1_PRESCALER_VALUE_8 (128)#define TIMER1_PRESCALER_VALUE_9 (256)#define TIMER1_PRESCALER_VALUE_10 (512)

  • http://www.instructables.com/id/Attiny254585-PWM-generator-and-Servo-tester/

    #define TIMER1_PRESCALER_VALUE_11 (1024)#define TIMER1_PRESCALER_VALUE_12 (2048)#define TIMER1_PRESCALER_VALUE_13 (4096)#define TIMER1_PRESCALER_VALUE_14 (8192)#define TIMER1_PRESCALER_VALUE_15 (16384)Of course without #define's and values (I'm just lazy enough to copy-paste from .h file ;) )If not, you might try to change the TCCR1 register value according to the attiny85 datasheet, page 89 and 90.Hope this will help you.P. S.now probably tiny85 is using prescaler #15, so using #14 should increase frequency twice ;) to about 1kHz

    Jan_Henrik says: Apr 16, 2014. 4:14 AM REPLYThank you, I will try it in the afternoon...

    I already tried the TCCR1 register value, it didnt work good, but i will keep trying!

    :)

    domints says: Apr 16, 2014. 10:37 PM REPLYOh... I see, that you want to lower the frequency, not to increase... So that may be hard, because you'd need to increase prescaler, but it's impossiblebecause of using the biggest now. But you're using Arduino Core, so why won't you just use Servo library?

    Jan_Henrik says: Apr 16, 2014. 11:08 PM REPLYThats a good questions, by now I dont thought about it :D:D

    alterator says: Apr 16, 2014. 4:02 PM REPLYmeasuring 5 times and delaying 10ms each time limits the PWM frequency -- measure ADC once like every half second or every second - and keep the pwmstatic for the rest of time. - this way you get rid of the unneeded delays, and can increase frequency.

    and BC516 is only 500mA. (or Im missing something?)otherwise - nice little gadget.. :)

    Jan_Henrik says: Apr 16, 2014. 10:39 PM REPLYHi, it wont increase the frequency, it doesnt matter, how much the processor is occupied, it doesnt change the PWM frequency...

    The PWM signal has a sperated timer(s)http://www.fairchildsemi.com/ds/BC/BC516.pdf

    it says 1 A D:

    Thank you for your input :)

    bezo88 says: Apr 15, 2014. 11:12 AM REPLYnice work. looks good. you can make a servo tester with a 555 timer

    Jan_Henrik says: Apr 16, 2014. 4:11 AM REPLYThank you, but with a NE555 it wouldnt work good, because the NE55 cant make a good PWM, it can just change the frequency, what can be used withsome extra parts ( capacicators & co ) to fake a pwm, try it with a oscilloscope... :P