Studio 4 not connecting to STK500 after programing m48

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

I'm working on a PWM app using T0 on the mega48 and when I finally started running on the STK500 I had problems connecting to the board after programming the chip the first time. The first chip I used had been programed before with some other app. The board will fire up and the m48 will run the app that I put on it, but after making some mods to the code I went to reburn and Studio 4.12 b490 wouldn't connect to the board. What the heck I thought... so I checked all the typical things that go wrong for me, no joy. So I pull the m48 and Studio connects to the STK500 no problem. Put the chip back in, no good. try a new m48 and happiness, so I burn the new hex file with success and it performs as expected. I try to connect to the board from Studio, no good. I'm using COM1 RS232 port (no USB converter) Brayterm is running on COM2, so I rescan in Brayterm and it says COM1 is available.

What throws me in my attempts to trouble shoot is what about my program disables Studio to even connect to the STK500. I did check that no fuses were programed other than the default, I'm running the internal 8MHz.

Has anyone else ever dealt with this or similar problem? I would appreciate any suggestions / help.

Thank you.

/*! \file *******************************************************************
*
* File              : DC_MotorControler.c
* Compiler          : GCC (WinAVR)
* Revision          : 1.0
* Date              : 06/21/09
* Updated by        : Ben Nemec
*
* Supported devices : All devices with a PWM can be used.
*                     The example is written for ATmega48
*
* Description       : controll speed of a brush type DC motor using PWM and
*                    an H-bridge circuit, control from UART, SPI or TWI port                   
*
****************************************************************************/

#include 
#include 
#include 
#include 
#include "DC_MotorController.h"
#include "UART.h"
#include "ADC.h"

//constants
#define FALSE  0
#define TRUE   (!FALSE)

// Private Macro definitions
#define  sbi(port,bit)  (port |= (1<<bit))   //set bit in port
#define  cbi(port,bit)  (port &= ~(1<<bit))  //clear bit in port
#define  PWM   PD6
#define  HBp   4

#define  CNTLA PORTC
   #define  FAULT PC2   //fault signal input from A3940

   #define  RSTn  0     //pwer down & clear latched faults
   #define  PHASE 1     //motor direction control
//   #define  ENBL  2     //high allows direct control of driver outputs via phase
   #define  SR    PC3   //sychornous rectification
   #define  MODE  4     //current decay mode
  


// private function prototypes:
void init_counter(void);
void InitMotorControler (void);


/* Main */
int main( void )
{ 
   //dissable all interrupts
   cli();

   //crank clock up to 8MHz see datasheet doc2545 p35
   //CLKPR = 0x80; //must write CLKPCE = 1 at same time as rest to 0   
   //CLKPR = 0x00; //program to divide by 1
   // not calibrating osc.

   //configure heartbeat pin:
   sbi (DDRD, HBp);
   sbi (PORTD, HBp);
   volatile uint16_t hrtBtCounter = 0; 
   volatile uint16_t i;
   volatile uint8_t data;


   for (i = 0; i< 10; i++)
   {
      for (hrtBtCounter = 0; hrtBtCounter < 50; hrtBtCounter ++); 
      cbi (PORTD, HBp);
   
      for (hrtBtCounter = 0; hrtBtCounter < 50; hrtBtCounter ++); 
      sbi (PORTD, HBp);
   }
   //
   cbi (PORTD, HBp);

   init_counter();
   init_adc();                    
   USART_Init(25);
   SendNTString("UART Initialized\n\r");
   InitMotorControler();

   hrtBtCounter = 0;
   for (;;)  //ever
   {
      

      data = USART_Receive();

      if (data >= 0x30 && data <= 0x39)
         OCR0A = (data - 0x30) * 28; 
         
   }
   return 0;
}

//*************************  init_counter  **********************************
/* 
Phase Correct PWM Mode (WGM02:0 = 1), TOP = 0xFF
non-inverted PWM; COM0x1:0 bits = two.


   0 0 1 clkI/O/(No prescaling)

*/
void init_counter(void)
{
   cbi (PRR, PRTIM0);

   //setup counter frequency
   //0x24 (0x44) TCCR0A [COM0A1 COM0A0 COM0B1 COM0B0 "“ "“ WGM01 WGM00]
   TCCR0A = 0x81;    // [  1      0      0      0    0 0   0     1
   //0x25 (0x45) TCCR0B [FOC0A FOC0B "“ "“ WGM02 CS02 CS01 CS00]
   TCCR0B = 0x01;    // [  0     0   0 0   0     0    0    1 ]
}


//*************************  InitMotorControler  ***************************/
void InitMotorControler (void)
{
   init_counter();      // Initiate and starts Counter 0 for PWM
   sbi(DDRD, PWM);      // set pin as output for PWM
   sbi(DDRC, RSTn);        // set port pin directions for control
   sbi(DDRC, PHASE);        // set port pin directions for control
//   sbi(DDRC, ENBL);        // set port pin directions for control
//   sbi(DDRC, SR);        // set port pin directions for control
//   sbi(DDRC, MODE);        // set port pin directions for control

   //powerup the Allegro A3940 according to the app note.
//   cbi(CNTLA, ENBL);        
   sbi(CNTLA, RSTn);
   _delay_us(10);      //allow time for vregs in A3940 to come up.  
//   sbi(CNTLA, SR);         
//   sbi(CNTLA, MODE);       

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

Just to unconfuse me...is the chip running on the STK500 or your own board?

If on the STK500 what are you driving with it? Is it possible tha VCC drops due to overloading?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I'm sorry for not being clear, by board I meant the STK500. I did have the PWM line connected to a separate board that has an allegro A3940 and H bridge. When I started having problems that came off. I'm just running one of the LEDs with the PWM output now. So nothing connected to the STK500.

I double checked and I'm not using the RST pin on the mega48.

When I power up the STK500 with a programed mega48 in the socket (SCKT3200A2 per the user manual) all the status LEDs of the STK500 show normal. Too much load on VTG is normally the problem I create, but it doesn't appear to be this time.

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

I got back to this project (hobby makes it low on the list :( ) and John's suggestion got me to try connecting with all the jumpers open. Then one by one connect until Studio fails to connect. So it's the AREF jumper that wrecks it. I tried different values for Aref in the the "Board" tab under the STK500 dialog window but every time I connect the AREF jumper on the STK500 Studio fails to connect, unless there is a new chip or no chip.

So the main problem is solved, but I'd like to know why it's behaving this way.

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

I see ADC.H but no ADC code. If you use VCC as the reference in your code then it is likely that you are shorting out the internal VCC to the AREF pin.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

yep, you got it John. That's the case. I should have figured that out, too rusty I guess.

Thank you for your help.