Arduino to ATtiny45 PWM dimmer?

Hi there,

I have recently made a pwm dimmer with the standard 328pu chip and put it in a circuit of its own to dimm and LED as a test using a pot etc.
This has been working fine using this code.


int potPin = 0; // Analog in 0 connected to the potentiometer
int transistorPin = 9; // connected to the base of the transistor
int potValue = 0; // value returned from the potentiometer

void setup() {
// set the transistor pin as output:
pinMode(transistorPin, OUTPUT);
}

void loop() {
// read the potentiometer, convert it to 0 - 255:
potValue = analogRead(potPin) / 4;
// use that to control the transistor:
analogWrite(9, potValue);


so thats just using the analogwrite standard pwm output of 450hz or whatever it is.

so i now want to shrink my dimmer on to an attiny45 which i have. i also have an arduino as isp shield
that i bought off ebay to programme my attiny45.

so far thats alright i guess using this website http://hlt.media.mit.edu/?p=1695

programmed the arduino for the isp programmer, sat my attiny45 chip in the holder of the shield and
programmed it.

i seem to be getting no PWM output, am i missing something? i assigned my code to the pin out of the attiny45
from that website using internal 8mhz clock on the attiny45. The varying voltage from the pot is going to the an analog
in pin but no PWM to drive the mosfet IRL540N. I previously used this in the arduino project so the attiny should still have enough
charge current to drive the gate of the mosfet.

Any ideas? would be a great help

Did you change the code to use 0 (pin 5) or 1 (pin 6) for the PWM output pin and 1 (pin 7), 2 (pin 3), or 3 (pin 2) for the analog input pin?

yes i did assign to the appropriate pins.

pot to pin 2 (pin 7 on attiny45) and pwm out pin 0 (pin 5 on attiny45)

And got no output pwm so far.

-----------------------------------PWM CODE ARRANGED FOR ATTINY45 PIN OUT---------------------------------------

int potPin = 2; // Analog in 0 connected to the potentiometer
int transistorPin = 1; // connected to the base of the transistor
int potValue = 0; // value returned from the potentiometer

void setup() {
// set the transistor pin as output:
pinMode(transistorPin, OUTPUT);
}

void loop() {
// read the potentiometer, convert it to 0 - 255:
potValue = analogRead(potPin) / 4;
// use that to control the transistor:
analogWrite(1, potValue);
}

Note that pin 7 on the chip is labeled "Pin 2" and "Analog Input 1". I think you have to use "int potPin = 1;" to use pin 7 for analog input.

Also note that pin 5 on the chip is labeled "Pin 0". I think you have to use "int transistorPin = 0;" to use pin 5 for PWM output.

cheers for the heads up. i just updated the code and i am getting this error when programming. I know the BS2 lines are ok but
not too sure what all this other stuff is underneath.

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45

avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
avrdude: stk500_cmd(): programmer is out of sync

Sounds like something has gone wrong with your ISP device. :frowning:

i finally have it working now.

I read somewhere the arduino as ISP code is basically naff! in version 1.0 or 1.0.1.

so you have to go back to previous software, i used arduino 0022 software. Programmed the standard arduino 328 chip
as the programmer using arduino as isp code, then switched back to 1.0.1 software to program the attiny in my isp shield
using the attiny45_85 zip file which contains the code/pinouts for the arduino/hardware folder.

then burn attiny bootloader depending on which freq you want to use (eg. 1 or 8mhz internal or 20mhz external clock)
then program to the right pin out.

light dimmer is working on attiny45.

since i am using an internal clock of 8mhz for the dimmer. would there be any advantage adding the extra components for xtal
external 20mhz clock? or wouldnt it matter?

cheers

well it worked untill i wanted to re program it so now it wont burn bootloader or upload code to attiny45

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45
avrdude: Yikes! Invalid device signature.
Double check connections and try again, or use -F to override
this check.

any ideas?

Post the verbose output.

all i am getting it that message above. it was working but i am not sure how you are suppose to
keep re programming the attiny45 over and over with no errors

Enable verbose output...

Post the results.

this is on upload, trying to re load the bootloader at 8mhz on the attiny45. i had it working before i just dont understand
why its not burning so i can re programme the chip again.


C:\Program Files (x86)\arduino-1.0.1\hardware/tools/avr/bin/avrdude -CC:\Program Files (x86)\arduino-1.0.1\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pattiny45 -cstk500v1 -P\\.\COM3 -b19200 -e -Uefuse:w:0xff:m -Uhfuse:w:0xdf:m -Ulfuse:w:0xe2:m 

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\arduino-1.0.1\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
         AVR Part                      : ATtiny45
         Chip Erase delay              : 4500 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : possible i/o
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     6     4    0 no        256    4      0  4000  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6    32    0 yes      4096   64     64  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
avrdude: Send: A [41] . [80]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [02] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [81]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [01] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [82]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [12] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [98]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
avrdude: Send: A [41] . [84]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [85]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [86]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [87]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [89]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: Send: A [41] . [81]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [01] 
avrdude: Recv: . [10] 
avrdude: Send: A [41] . [82]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [12] 
avrdude: Recv: . [10] 
avrdude: Send: B [42] . [14] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] @ [40] . [01] . [00] . [00] . [00] . [10] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45
avrdude: Send: P [50]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: AVR device initialized and ready to accept instructions

Reading | avrdude: Send: V [56] 0 [30] . [00] . [00] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
avrdude: Send: V [56] 0 [30] . [00] . [01] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
################avrdude: Send: V [56] 0 [30] . [00] . [02] . [00]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [00] 
avrdude: Recv: . [10] 
################################## | 100% 0.12s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude: Send: Q [51]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 

avrdude done.  Thank you.

The target (the ATtiny45) is not responding.

Double check the wiring between the programmer (your Arduino) and the target.

Other than Vcc, what do you have connected to the right side of the target?

i am using this shield i got off ebay so i minimised any wiring problems, so its just the attiny in the 8 pin socket and the 328 chip is sat underneath in the arduino for the isp programmer

k!WBQYhrYj)P!~~60_12.JPG)

You move the target from that shield to something else (a breadboard?) everytime you reprogram it?

I have been using the shield to program then dropped my attiny in my breadboarded PWM
Circuit. Which I got working recently. So I put the chip back in and burnt the 20mhz
Bootloader to the attiny trying to test if there was any difference in light dimming
Or duty cycle between 8 internal and 20 external

(just because this project used 20mhz
External) before I started to shrink the project down to attiny.

After I tried the 20mhz bootloader it's as if I bricked the chip. Doesn't want
To bootload or upload program.

I am wondering if I have dry joints on my R3 arduino as am sure I noticed something
Dodgy with the connections when I first got it. Bit not had anything wrong Since.

You can't use serial programming unless the system clock is working. Once you have programmed the fuses for an external crystal oscillator you have to connect the crystal (and load capacitors) or resonator to pins 2 and 3. I don't see a crystal for the ATtiny socket on your programming shield. That would explain why you can't program it.

LadyAda has a version of ArduinoISP that outputs an 8 MHz clock on Pin 9: GitHub - adafruit/ArduinoISP: A fork of the ArduinoISP that has 8mhz output clock If you use that and connect UNO Pin 9 to ATtiny pin 2 (XTAL1) you should be able to program it.

Is there not a way of resetting the fuses of an attiny?

It should have programmed using 20mhz as there is an xtal on my shield. Maybe it's not connected to the attiny socket. I will have to check later.

Really appreciate the info though. Very helpful.

kh602:
Is there not a way of resetting the fuses of an attiny?

Yes. Connect a clock signal to XTAL1 using LadyAda's version of ArduinoISP.

Cheers. I just wanted to check that is what you ment by using
That method to reset the fuses. I will try when I get home from
Work shortly.

Thanks once again. Al keep you posted if I run in to any bother.