Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

USBasp programmer using Atmega16L

Status
Not open for further replies.

Raj23

Newbie level 6
Joined
Aug 7, 2011
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,366
Hello
I have 5 atmega16Ls and I want to make a cheap AVR usb programmer using one of them.
I came across the USBasp programmer on fischl.de But it was using Atmega8.
I am using Atmega16L for robotics for a year now an I am good with digital circuits.

What changes do I have to make to the circuit and Firmware to make it work using Atmega16L.

Thank You
 

i'm using both of them. I used Codevision C to program it. I think its only the size of flash memory and its physical configuration. In terms of physical... it is bcoz atmega8 has only 3 pins for PWM while atmega16 has 4 pins. Also, the ADC of atmega8 is 6channels while atmega16 has 8channels and 2channels of its ADC can configure to increase its gain. Also the atmega16 is more efficient in terms of saving energy than atmega8.

But both of them has the same operating voltage and speed.

in terms of changes of the circuit, it would be the pin allocation and timing configuration. The PCB layout... remember, atmega8 has 28 pins while atmega16 has 40 pins! :)
 

i'm using both of them. I used Codevision C to program it. I think its only the size of flash memory and its physical configuration. In terms of physical... it is bcoz atmega8 has only 3 pins for PWM while atmega16 has 4 pins. Also, the ADC of atmega8 is 6channels while atmega16 has 8channels and 2channels of its ADC can configure to increase its gain. Also the atmega16 is more efficient in terms of saving energy than atmega8.

But both of them has the same operating voltage and speed.

in terms of changes of the circuit, it would be the pin allocation and timing configuration. The PCB layout... remember, atmega8 has 28 pins while atmega16 has 40 pins! :)

Thanks randell. I am aware of all these changes in Atmega8 and 16.
What I want to know is where to connect in Atmega16 and what are the corresponding changes in the firmware.
Like for example, if you look at the USBasp circuit for Atmega8, two LEDs are connected to ADC PORT which is PORTC. But PORTA is ADC in Atmega16. So do I have to connect these LEDs to PORTA or C in Atmega16 and what changes do I have to make in the firmware.
There are many such queries in my mind.

I am capable of doing this project on my own. For that I will have to understand thoroughly the circuit and the firmware, which will take a lot of my time and patience, which I dont have right now, as I am preparing for a robotics competition.

I was expecting a solution from somebody who has already done this. If I dont get a reply soon, my last resort will be to buy an Atmega8.
We in India, generally believe in making it cheap and using available resources. I think it is possible to make this work. Please help me and correct me if I am wrong
 

It shouldn't be a problem to use the mega16, you just have to change a few defined pins in the header files

set the correct pins for your mcu and connections in (these are the m8 settings not the corrected ones for m16)

Code:
[COLOR="#FF0000"]ISP.h[/COLOR]
#define ISP_OUT   PORTB
#define ISP_IN    PINB
#define ISP_DDR   DDRB
#define ISP_RST   PB2
#define ISP_MOSI  PB3
#define ISP_MISO  PB4
#define ISP_SCK   PB5

Code:
[COLOR="#FF0000"]UBBASP.h[/COLOR]
/* macros for gpio functions */
#define ledRedOn()    PORTC &= ~(1 << PC1)
#define ledRedOff()   PORTC |= (1 << PC1)
#define ledGreenOn()  PORTC &= ~(1 << PC0)
#define ledGreenOff() PORTC |= (1 << PC0)


Code:
[COLOR="#FF0000"]usbconfig.h[/COLOR]

/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME      B
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT      0
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT       1
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
#define USB_CFG_CLOCK_KHZ 12000
/* Clock rate of the AVR in MHz. Legal values are 12000, 16000 or 16500.
 * The 16.5 MHz version of the code requires no crystal, it tolerates +/- 1%
 * deviation from the nominal frequency. All other rates require a precision
 * of 2000 ppm and thus a crystal!
 * Default if not specified: 12 MHz
 */

and finally you have to set the correct fuses because # TARGET=atmega8 HFUSE=0xc9 LFUSE=0xef will not be correct with a different mcu

Alex

---------- Post added at 00:44 ---------- Previous post was at 00:38 ----------

Also note that the default clock rate in USBASP is 12MHz but for the m16L that you have the specification is just 8MHz

• Speed Grades
–0 - 8 MHz for ATmega16L
–0 - 16 MHz for ATmega16

I have seen some posts that the L version work the same as the 16MHz versions but I have never tried
 
  • Like
Reactions: Raj23

    Raj23

    Points: 2
    Helpful Answer Positive Rating
Thank You very much alexan_e. This is what I was looking for.
I haven't tested it yet but the code seems right. I'll reply again after I have tested it. Thanks again
 

There is not much difference between the m8 and m16, if you post a schematic I can help you with the port settings but it should be simple enough, SPI is in different pins so it should definitely change.
Again, note that the code posted above is the original mega8 code, don't use it like this , you have to change the defined pins to suite your design.

Alex
 

I have not made the schematic. I am directly soldering the connections on a general PCB.
Till now I have connected all the input connections to Atmega16 from the USB:

USB pin2 ---> (ICP1) PD6 through R1
USB pin3 ---> (OC1A) PD5 and (INT0) PD2 through R2

and other required diodes and caps.

Now where to connect the ISP output? On the original USBasp, PORTB is used for Atmega8. Is PORTB randomly chosen or used due to its oscillator output pins: OC1A, OC1B and OC2. If so, then I will have to use corresponding oscillator pins in Atmega16 on PORTD. Please clear
 

Use

#define ISP_OUT PORTB
#define ISP_IN PINB
#define ISP_DDR DDRB
#define ISP_RST PB4
#define ISP_MOSI PB5
#define ISP_MISO PB6
#define ISP_SCK PB7

use the SPI pins of M16 like above
instead of B4,B5,B6,B7 instead of B2,B3,B4,B5

Alex

EDIT, I meant USE B4,B5,B6,B7 instead of B2,B3,B4,B5
 
  • Like
Reactions: Raj23

    Raj23

    Points: 2
    Helpful Answer Positive Rating
thanks for the output connections.
Are my input connections correct? if yes, then what would be the corresponding changes in firmware
 

I have also checked the main.c, you have to change a couple of things there too because the port pins are hard coded and not based on the define

Code:
/*
 * USBasp - USB in-circuit programmer for Atmel AVR controllers
 *
 * Thomas Fischl <tfischl@gmx.de>
 *
 * License........: GNU GPL v2 (see Readme.txt)
 * Target.........: ATMega8 at 12 MHz
 * Creation Date..: 2005-02-20
 * Last change....: 2009-02-28
 *
 * PC2 SCK speed option.
 * GND  -> slow (8khz SCK),
 * open -> software set speed (default is 375kHz SCK)
 */

int main(void) {
	uchar i, j;

	/* no pullups on USB and ISP pins */
	PORTD = 0;
	PORTB = 0;
	/* all outputs except PD2 = INT0 */
	DDRD = ~(1 << 2);

	/* output SE0 for USB reset */
	DDRB = ~0;
	j = 0;
	/* USB Reset by device only required on Watchdog Reset */
	while (--j) {
		i = 0;
		/* delay >10ms for USB reset */
		while (--i)
			;
	}
	/* all USB and ISP pins inputs */
	DDRB = 0;
	[COLOR="#FF0000"]DDRD &= 0b10011111; // add this to set as input the usb pins[/COLOR]

	/* all inputs except PC0, PC1 */
	[COLOR="#FF0000"]DDRC = 0x03;  //00000011  if you change the leds then change these
	PORTC = 0xfe; //11111110[/COLOR]

	/* init timer */
	clockInit();

	/* main event loop */
	usbInit();
	sei();
	for (;;) {
		usbPoll();
	}
	return 0;
}

Alex

---------- Post added at 17:00 ---------- Previous post was at 16:59 ----------

thanks for the output connections.
Are my input connections correct? if yes, then what would be the corresponding changes in firmware

There is only one SPI connection and the USB, which output connections do you mean?
Do you mean the LEDS?
 

No I meant the ISP connections. What are the changes to be made in usbconfig.h?
 

You said
USB pin2 ---> (ICP1) PD6 through R1
USB pin3 ---> (OC1A) PD5 and (INT0) PD2 through R2

so the settings are
Code:
/* ---------------------------- Hardware Config ---------------------------- */

#define USB_CFG_IOPORTNAME      D
/* This is the port where the USB bus is connected. When you configure it to
 * "B", the registers PORTB, PINB and DDRB will be used.
 */
#define USB_CFG_DMINUS_BIT      6
/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected.
 * This may be any bit in the port.
 */
#define USB_CFG_DPLUS_BIT       5
/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected.
 * This may be any bit in the port. Please note that D+ must also be connected
 * to interrupt pin INT0!
 */
 

With all the effort that goes in, I think it would make more sense to just buy an ATMEGA8. According to this: AVR Core : Amateurworld.in, *** World of Amateur Electronics ***, it's only Rs 95 at the moment. At your local store you should be able to get it cheaper as I can buy an ATMEGA8 for Tk 100 (about 60 to 70 Rs). However, if you have the time (which you mentioned you don't), you can make the adjustments and have fun changing the firmware and hardware to suit your requirements and actually utilize an ATMEGA16L lying around.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top