Problem after programing

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am new in the AVR world. I use Atmel Studio 7,  I program with USBAsp an ATmega328p. 
I upload my program to the device by ISP and the program runs ok.
BUT ! when I disconect the programmer and connect an external power supply the microcontroller seems not to be programmed. It doesn't do anything. 
It only works when the USBAsp is connected and the program is downloaded in the device.
What am I doing wrong ?

 

Thanks in advance, Folks !

This topic has a solution.

Omar.

Last Edited: Mon. Jun 24, 2019 - 10:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MOST programmers require the target board to be separately powered. According to the schematic I  just saw, if you use a 10-pin programming connector, the target CAN be power by USBAsp. 

 

What do you have connected to the reset pin on your  target?

 

If your USBAsp has a jumper to connect power to the Vtarget pin so that the programmer provides power, what happens if you disconnect that jumper and provide your own target power? Does it still program?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sat. Jun 22, 2019 - 05:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you have capacitors on your chip power pins?  Is voltage connected to all of the supply pins & all gnds connected?  Show your schematic.  What is your clock source---internal RC? 

Is your power supply supplying clean 5V or 3.3V?  Did you measure that pwr is actually getting to the pins?

Why do you say the chip is "doing nothing"?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have powerd up the circuit with an externay power supply and programmed the chip, in that case when I took off the USBAsp the program still works, BUT when I take off the external 5V for a moment and repower . The chip seems to have nothing programmed, "and do nothing".
It acts as if the chip was new, without any program.
The only way it works is uploading the program by the USBAsp and keeping it connected.

I think is a bad configuration of the FUSES, but I'm new and have no clue !

 

Thanks again !

Attachment(s): 

Omar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A 328 has two power pins, VCC and AVCC, both must be connected to power and have 100nf caps to adjacent GND pins.
Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Could be an uninitialized variable.  During the programming operation the SRAM is cleared and 0 is acceptable value for the variable to allow the program to run.  After a power cycle the SRAM can contain any values and just so happens the power on value causes your program to crash.

Letting the smoke out since 1978

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the answers. I have power in both VCC and AVCC. Even all the variables are not initialized. I'm not using SRAM positions, just "PUSH" and "POP" (which I think uses SRAM, I do not know if I'm wrong with this. Excuse me, my unknowledge).
I use the ISP with USBAsp programmer as I said. I upload the program to the 328p and the program runs ok, no bugs, it shows a counter in the LCD module and it's ok.
The problem is when I turn off the circuit and turn it on again, it act as if it loose the programming and it doesn't run at all. The LCD module doesn't initialize, etc.
I am not used to work with AVR's perhaps there are something wrong in the uploading method using the USBAsp, or something that I have to inizialize with fuses, so the chip can store the program. 
Even all this, It works when I programm it, there are something that makes the device, seems to loose the program when it is turning off.

 

Omar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is very unlikely that you "loose the program". What leads you to the conclusion that  it is not working? 

 

One of the problems that has been reported a few times has been that there is no power supply path once the programmer is unplugged. It has seemed to be a missing ground connection. What happens if you leave the programmer plugged into the target but the programmer unplugged from the PC (e.g. unpowered)?

 

Another test: unplug your programmer, as you have described and try to restart it. Use a voltmeter to measure the voltage between MCU ground pins and the MCU Vcc & AVcc pins. Also between ground and the MCU reset pin; it should be close to your supply voltage. 

 

Jim

 

 

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sat. Jun 22, 2019 - 09:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First Jim, Thank you very much for your time answering me ! ! !
I have done a small vid 1min for you to see the exact problem.
I think it is not about a missing ground or bad power, because the circuit works and the programm also works. The problem is, it seems not to stay in the flash memory. 
https://photos.app.goo.gl/amXPqT...

 

If I disconect de USBAsp its the same (it is not powering the circuit). In this moment I am using an external power supply.

Omar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I argue that "lost program" is almost never true. People have claimed seeing it, but there have always been other causes, in the end.

 

I wonder if you are really using the simulator instead of actually programming the target?

 

Try this:

 

Program it outside of debug mode using the Tools > Device Programming menu. There, you can program it straight via ISP and you can VERIFY it (that is, read it back to the programmer and compare with the program it tried to load). That will tell you if the program is really in there. Also, there is no debug mode to get in the way.  THEN try  to disconnect and restart.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Beside the lcd, what parts are not working?

Do you have some pins, or leds that are working?

 

The problem is the LCD may take a long time to get ready after power is applied...do you have a second of delay before the program starts to send things to the LCD?

Of course all of the other parts & pins should be fine.  Does even an LED light up? 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Usually I'd look at power or the reset pin, but I'm guessing avrcandies is right on this one. When you load the program, the thing has already been turned on for a few seconds or more when the program starts. When you apply power, the program starts immediately and perhaps initializes the display before the display is ready to be initialized.

 

Try adding _delay_ms(1000) at the start of the program before you initialize the display. You likely can get away with something shorter than a second, but let's get it working first.

The largest known prime number: 282589933-1

In my humble opinion, I'm always right. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Protest agenst sensorship.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Mon. Jun 24, 2019 - 08:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FIRST thank you all for your help !  

I made some other tests to figure out what the problem is. I tried changing the chip. Using the chip in some other app. As I said, VCC and AVCC are powered. both GND pins are at 0V (PIN 7 and PIN 22) the AREF pin is also to 5V. The RESET pin has a 100k resistor and a 1N4148 to power and a 104 to ground. I have programmed the chip by the USBAsp program (outside the Atmel Studio).  I am using an old PC power supply to work with the 5 volts. 

I don't want to give it up, because when I upload the programm it works ok and it do what it have to do.  I really don't think it loose the programm, but there is something that it doesn't work in stand alone mode.  What is the difference or what changes in between charging the programm in the flash memmory or leting it start alone?

Attachment(s): 

Omar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

The chip is 99.999% NOT bad, or it wouldn't program/run in the first place.

Do you try blinking an led and see if that keeps working?

You forgot to post your code for any extra help.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

omarh0 wrote:

FIRST thank you all for your help !  

I made some other tests to figure out what the problem is. I tried changing the chip. Using the chip in some other app. As I said, VCC and AVCC are powered. both GND pins are at 0V (PIN 7 and PIN 22) the AREF pin is also to 5V. The RESET pin has a 100k resistor and a 1N4148 to power and a 104 to ground. I have programmed the chip by the USBAsp program (outside the Atmel Studio).  I am using an old PC power supply to work with the 5 volts. 

I don't want to give it up, because when I upload the programm it works ok and it do what it have to do.  I really don't think it loose the programm, but there is something that it doesn't work in stand alone mode.  What is the difference or what changes in between charging the programm in the flash memmory or leting it start alone?


AREF should never be connected to VCC, it should have 100nf to GND, you risk internal damage to the chip.
Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AREF should never be connected to VCC, it should have 100nf to GND, you risk internal damage to the chip.
 

Connecting AREF pin to Vcc (Avcc) is kinda ok if AVCC is selected as the reference, otherwise.... maybe it makes a nice software destruct technique....10, 9, 8,7,5, 4 ...

 

I wonder how many freaks have purposely built in a destruct setting of some sort (intentionally!).. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am here again and again thank you all very much !
I add a beep while it is counting and this told me that the program is running. The beep sounds, but the LCD module doesn't initialize, it doesn not show the characters, anyway when I upload the programm IT WORKS ! !
I took off the 5v to the AREF pin, I put a 104 cap to ground instead, as you told me and I add 100k pull-ups resistors in the C port PC1-PC2-PC3-PC4-PC5. where I have the strobe, data and clock pins of the CD4094  and the RS and E pins of the LCD module.
I ask again, what is the difference betwen upload the program or let it start alone ?  What register shoud I have to beware of ?  
I show you the program if it is worth. I know the program is ok and works but now when I turn the circuit off and turn it on again the LCD module doesnt inicialize`.

 

;*************************************************************** 
; Control LCD.ASM 
; ATmega328P - 4 MHz - LCD control by Shift Register 4094
;*************************************************************** 
.device        ATmega328P
.include     "M328Pdef.INC"
.CSEG 
.ORG    0x00 

;Control lines definition
;Definicion de lineas de control
.equ    LCD_PORT=    PORTC
.equ                E =     PC2    ;E an Pin PD0 
.equ              RS =     PC1    ;RS an Pin PD2 
;                  RW =     GND
.equ    PUERT_4094=    PORTC
.equ        CLK_4094=    PC3
.equ       DAT_4094=    PC4
.equ       STR_4094=    PC5
.equ    BUZZ_PORT=    PORTD
.equ             BUZZ=    PD5

;LCD commands
;Comandos del LCD
.equ         Clear_LCD =     0x01    ;0b00000001    ;Reset LCD
.equ    turn_OFF_LCD=    0x08
.equ        home_LCD =     0x02    ;0b00000010    ;move cursor to home pos.
.equ           Set_LCD =     0x38    ;0b00111000    ;8 bits,2 lineas,5x7dots 
.equ             LCD_on =     0x0E    ;0b00001110    ;lcd=on, cursor=on, blinking=off
.equ        Cursor_OFF=    0x0C    ;0b00001100    ;lcd=on, cursor=off ; blinking=off
.equ         Cursot_ON=    0x0E    ;0b00001110    ;lcd=on, cursor=on ; blinking=off
.equ     Entry_mode =     0x06    ;0b00000110    ;Mode Set
.equ                line1=        0x80
.equ                line2=        0xC0

;Var definitions
;definición de variables
.def     TEMP =     R16
.def    BUFFER=    R17
.def    DLY1_R=    R18
.def    DLY2_R=    R19
.def    RES1=    R20
.def    RES2=    R21
.def    RES3=    R22

;INPUT [0] OUTPUT [1] CONFIGURATION
;CONFIGURACION DE ENTRADAS [0] Y SALIDAS [1]
    LDI    TEMP,    0x3E
    OUT    DDRC,    TEMP
    LDI    TEMP,    0x20
    OUT    DDRD,    TEMP

;Reposicionar el Stack Pointer
    LDI    TEMP,    HIGH(RAMEND)
    OUT    SPH,    TEMP
    LDI    TEMP,    LOW(RAMEND)
    OUT    SPL,    TEMP

;*************************************************************** 
; Programa principal                                       
;*************************************************************** 
Main: 
    CALL    LCD_init
Main2:
    LDI    BUFFER,    line1
    CALL    LCD_iw
    LDI    YH,    HIGH(MSJE_01<<1)
    LDI    YL,    LOW(MSJE_01<<1)
    CALL    SendMSJE

    LDI    BUFFER,    line2
    CALL    LCD_iw
    LDI    YH,    HIGH(MSJE_02<<1)
    LDI    YL,    LOW(MSJE_02<<1)
    CALL    SendMSJE

 

;The counter STARTS here.

 

    LDI    RES1,    0x00
    LDI    RES2,    0x00
    LDI    RES3,    0x00
Cuenta:
    CALL    ShowNUM
    ;--------------------------
    LDI    DLY1_R,    0xFF
    LDI    DLY2_R,    0xFF
    CALL    Loop_dly
    LDI    DLY1_R,    0xFF
    LDI    DLY2_R,    0xFF
    CALL    Loop_dly
    ;--------------------------
    ;Cursor back 3 times to refresh counter
    LDI    BUFFER,    0x10
    CALL    LCD_iw
    LDI    BUFFER,    0x10
    CALL    LCD_iw
    LDI    BUFFER,    0x10
    CALL    LCD_iw
    ;--------------------------
    INC    RES3
    CPI    RES3,    0x0A
    BRNE    Cuenta
    LDI    RES3,    0x00
    ;============================
    SBI    BUZZ_PORT,    BUZZ
    CALL    Dly_1mS
    CBI    BUZZ_PORT,    BUZZ
    ;============================
    INC    RES2
    CPI    RES2,    0x0A
    BRNE    Cuenta
    LDI    RES2,    0x00
    INC    RES1
    CPI    RES1,    0x0A
    BRNE    Cuenta
    LDI    RES1,    0x00
    JMP    Main2

;StayHERE:
;    JMP    StayHERE

;             0123456789ABCDEF
MSJE_01:    .DB    "- TEST machine -"
MSJE_02:    .DB    "  Counter: $    "

ShowNUM:
    ;--------------------------------------
    ;Show the Number in the LCD
    ;--------------------------------------
    LDI    TEMP,    0x30
    ADD    TEMP,    RES1
    MOV    BUFFER,    TEMP
    CALL    LCD_dw

    LDI    TEMP,    0x30
    ADD    TEMP,    RES2
    MOV    BUFFER,    TEMP
    CALL    LCD_dw

    LDI    TEMP,    0x30
    ADD    TEMP,    RES3
    MOV    BUFFER,    TEMP
    CALL    LCD_dw
    RET

;************************************************************** 
; Rutina para sacar datos atravez del 4094
;************************************************************** 
Out_4094:
    PUSH    TEMP
    LDI    TEMP,    0x08
    SBI    PUERT_4094,    CLK_4094
Loop_4094:
    CBI    PUERT_4094,    CLK_4094
    NOP
    ROL    BUFFER
    BRCS    One
;Zero:
    CBI    PUERT_4094,    DAT_4094
    RJMP    NextBit
One:
    SBI    PUERT_4094,    DAT_4094
NextBit:
    NOP
    SBI    PUERT_4094,    CLK_4094
    NOP
    DEC    TEMP
    BRNE    Loop_4094
    ;-----------------------------
    ;Latch to put data in PINS
    NOP
    SBI    PUERT_4094,    STR_4094
    NOP
    CBI    PUERT_4094,    STR_4094
    ;-----------------------------
    POP    TEMP
    RET

;************************************************************** 
; Rutina de inicializacion del modulo LCD
;************************************************************** 
LCD_init:
    ;Power-Up delay
    CALL    Dly_15mS    ;DELAY 15mS
    ;Reset the LCD controller
    LDI    BUFFER,    Set_LCD
    CALL    LCD_iw
    CALL    Dly_5ms        ;DELAY 5mS
    LDI    BUFFER,    Set_LCD
    CALL    lcd_iw
    CALL    Dly_1ms        ;DELAY 1mS
    LDI    BUFFER,    Set_LCD
    CALL    LCD_iw
    CALL    Dly_1ms        ;DELAY 1mS
    ;Funcion set instruction
    LDI    BUFFER,    Set_LCD
    CALL    LCD_iw
    ;Specified by data sheet procedure...
    LDI    BUFFER,    Cursor_OFF
    CALL    LCD_iw
    LDI    BUFFER,    Clear_LCD
    CALL    LCD_iw
    LDI    BUFFER,    Entry_mode
    CALL    LCD_iw
    ;LDI    buffer,    Cursor_ON
    ;CALL    LCD_iw
    CALL    Dly_1ms        ;DELAY 1mS
    RET

;*************************************************************** 
; Subroutine Delay of time 
; Estas rutina son retrasos de tiempo en general
; para la inicializacion del LCD.
;***************************************************************
;Times calculated with de AVR Delay Loop calculator.
; http://bretmulvey.com/avrdelay.html
Dly_1mS:
    LDI    DLY1_R,    0x06
    LDI    DLY2_R,    0x31
    JMP    Loop_dly
Dly_5mS:
    LDI    DLY1_R,    0x1A
    LDI    DLY2_R,    0xF9
    JMP    Loop_dly
Dly_15mS:
    LDI    DLY1_R,    0x4E
    LDI    DLY2_R,    0xE8
Loop_dly:
    DEC    DLY2_R
    BRNE    Loop_dly
    DEC    DLY1_R
    BRNE    Loop_dly
    RET                    

;*************************************************************** 
; Subrutinas para enviar datos o instrucciones al LCD
;*************************************************************** 
; El COMANDO o DATO debe estar cargado en el registro BUFFER
LCD_iw:                    ;Instrucction write
    CBI    LCD_PORT,    RS
    JMP    LCD_cont
LCD_dw:                    ;Data write
    SBI    LCD_PORT,    RS
LCD_cont:
    CALL    Dly_1mS
    SBI    LCD_PORT,    E
    CALL    Dly_1mS
    ;OUT    LCD_DAT_PORT,    BUFFER    ;change the PORT to the shift register 4094
    CALL    Out_4094
    CALL    Dly_1mS
    CBI    LCD_PORT,    E
    RET

;*************************************************************** 
;    Subrutina para enviar mensajes al LCD
;*************************************************************** 
;El mensaje tiene que venir apuntado en YH y YL
;    LDI    YH,    HIGH(MSJE_xx<<1)
;    LDI    YL,    LOW(MSJE_xx<<1)
SendMSJE:    
    LDI    TEMP,    0x00
Loop_MSJE:
    MOV    ZL,    YL
    ADD    ZL,    TEMP
    LPM    BUFFER,    Z
    CPI    BUFFER,    0x24    ;'$' stop sending character
    BREQ    End_MSJE
    CALL    LCD_dw
    INC    TEMP
    CPI    TEMP,    0x10
    BRNE    Loop_MSJE
End_MSJE:
    RET

 

Omar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Before you begin writing anything to the LCD, make sure you include a 1 second delay, that will be plenty.  Just put it in after you set up your ports.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

omarh0 wrote:
LCD_init:
    ;Power-Up delay
    CALL    Dly_15mS    ;DELAY 15mS  <==== Make this delay longer!!! Try 100ms
    ;Reset the LCD controller
    LDI    BUFFER,    Set_LCD
    CALL    LCD_iw

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274

 

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I HAVE SOLVED THE PROBLEM !!!   I changed the Y register by the Z register, the problem was I din't know the way of pointing to the data with Z+.
Now I can took off the power of the circuit and when I power it agani, it keeps running.
    

LDI	ZH,	HIGH(MSJE_01<<1)
LDI	ZL,	LOW(MSJE_01<<1)

MSJE_01:	.DB	"- TEST machine -"

SendMSJE:
	LDI	TEMP,	0x00
Loop_MSJE:
	MOV	ZL,	YL
	ADD	ZL,	TEMP
	LPM	BUFFER,	ZL
	CPI	BUFFER,	0x24	;'$' stop sending character
	BREQ	End_MSJE
	CALL	LCD_dw
	INC	TEMP
	CPI	TEMP,	0x10
	BRNE	Loop_MSJE
End_MSJE:
	RET

=======================
================CHANGED : 
=======================

SendMSJE:
	LDI	TEMP,	0x00
Loop_MSJE:
	LPM	BUFFER,	Z+
	CPI	BUFFER,	0x24	;'$' stop sending character
	BREQ	End_MSJE
	CALL	LCD_dw
	INC	TEMP
	CPI	TEMP,	0x10
	BRNE	Loop_MSJE
End_MSJE:
	RET	

 

Omar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

 I changed the Y register by the Z register, the problem was I din't know the way of pointing to the data with Z+.

You still haven't said what the failure was.... it worked when you used the programmer?

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I really don't know why using the Y register produce loss of data in the stand alone mode. When I changed by the Z register, it works. The LCD initialization have the same timing, the power supply is the same I was working with. I only change the Y reg, as you see in the uploaded  program part.

Omar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
	CPI	BUFFER,	0x24	;'$' stop sending character

How does that work then? The text does not have a terminating '$' ??

MSJE_01:	.DB	"- TEST machine -"

I guess you are simply relying on the test against TEMP, 0x10 ?

 

(BTW $ terminator? Really? Are you old enough to remember CP/M then?)