Go Down

Topic: Arduino to ATtiny45 PWM dimmer? (Read 3 times) previous topic - next topic

kh602

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


johnwasser

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?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kh602

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);
}

johnwasser

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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kh602

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

johnwasser

Sounds like something has gone wrong with your ISP device. :(
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

kh602

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

kh602

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?

Coding Badly


kh602

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

Coding Badly


Enable verbose output...
http://arduino.cc/forum/index.php/topic,108797.msg820419.html#msg820419

Post the results.

kh602

#11
Oct 31, 2012, 02:09 am Last Edit: Oct 31, 2012, 02:17 am by kh602 Reason: 1
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.

----------------------------------------------------------------

Code: [Select]
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.

Coding Badly


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?

kh602

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


Coding Badly


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

Go Up