External clock/xtal not worked in atmega328p-au 32 pin MLF package

When I 1st joined the forum in 2011 there main site docs were big on diy-duinos where you develop on the Uno what you pry out of the socket and stick in your end-product. The Uno is a development board. Adafruit started the Minty Boost process.

I have used Nick Gammon's tutorial to bootload many AVR's. I have 1284P's!

Knowing what is in that link, if a board has ICSP I can load it and set fuses.

Here's fun for minimal; a 28-pin 328 DIP in a 40 pin narrow socket leaves 12 holes with underside pins to solder to. Possible to build a socket-duino that the AVR plugs into without ever heating a chip pin.

1 Like

Hello everyone, in same circuit i have another issue, for circuit you can see above. The new issue is atmega328 stop working after some time until we press reset button.
and I am using voltage divider circuit for measure 45volt - 85volt. and programmed to control relay on particular voltage sensing by atmega328.
I am sharing my code and hardware schematic please let me know where I am mistaking.
hare the complete code:-

void feedback();
void low_battery();
void full_battery();

float battery_low_limit, battery_high_limit;
int battery;
//-------------------------------------------------------------------------------------------setup fun.--------------------------------------------------------------------------
void setup() {
//-------------------------------------------------I/O PINS INITIALIZATION-------------------------------------------------
pinMode(10,OUTPUT); //feedback relay
pinMode(11,OUTPUT); //feedback relay
pinMode(12,OUTPUT); //feedback relay

// pinMode(3,OUTPUT); // PWM pin

pinMode(2,OUTPUT); // general purpose relays MOTOR ON/OFF +
pinMode(4,OUTPUT); // general purpose relays MOTOR ON/OFF -
pinMode(5,OUTPUT); // general purpose relays CHARGING ON/OFF +
pinMode(6,OUTPUT); // general purpose relays CHARGING ON/OFF -
pinMode(7,OUTPUT); // general purpose relays USED FOR FEEDBACK CONNECTION TO THE CONTROLLER

pinMode(A0,INPUT); // battery voltage sensing
pinMode(A1,INPUT); // 48V battery sensing
pinMode(A2,INPUT); // 60V battery sensing
pinMode(A3,INPUT); // 72V battery sensing
pinMode(A4,INPUT); // thortar sensing
// pinMode(A5,INPUT); // break sensing

//---------------------initial states of system relay-----------------------------------------
digitalWrite(2,LOW); //MOTOR OFF +
digitalWrite(4,LOW); //MOTOR OFF -
digitalWrite(5,LOW); //CHARGING OFF +
digitalWrite(6,LOW); //CHARGING OFF -
digitalWrite(7,LOW); //FEEDBACK ON

digitalWrite(10,LOW); //FEEDBACK OFF PHASE 1
digitalWrite(11,LOW); //FEEDBACK OFF PHASE 2
digitalWrite(12,LOW); //FEEDBACK OFF PHASE 3
//---------------------------------------------------------other parameter initialization ----------------------
if(digitalRead(A1)==HIGH){
battery=48; //48v scooty
}else if(digitalRead(A2)==HIGH){
battery=60; //60v scooty
}else if(digitalRead(A3)==HIGH){
battery=72; //72v scooty
}else{
battery=48; //48v system
}
//----------------------------------------------------switch condition--------------------
switch(battery){
case 48:
battery_low_limit = 291.371; //50v
battery_high_limit =297.198; //51v WRONG
break;
case 60:
battery_low_limit = 478.822; //63v
battery_high_limit =481.477; //64v
break;
case 72:
battery_low_limit = 437.061; //75v
battery_high_limit =442.884; //76v
break;
// case 48:
// battery_low_limit = 337.920; //50v
// battery_high_limit =344.064; //51v
// break;
// case 60:
// battery_low_limit = 426.846; //62v ->63 changes
// battery_high_limit =433.621; //63v ->64 changes
// break;
// case 72:
// battery_low_limit = 507.904; //75v
// battery_high_limit =516.096; //76v
// break;
}
}
//================================================================================main function=====================================================================================
void loop() {
feedback();
delay(30);
int battery_voltage = analogRead(A0); // Sense the current battery voltage.

if(battery_voltage <= battery_low_limit){ //check battery is low or not.
low_battery(); // calling low battery function.
}else if(battery_voltage >= battery_high_limit){ // check the battery is fully charged of not.
full_battery(); // calling full battery function
}
feedback();
delay(25);
}
//============================================================================full battery function ================================================================================
void full_battery(){ // operation performed function if battery fullu charged.
digitalWrite(2,LOW); //MOTOR OFF +
digitalWrite(4,LOW); //MOTOR OFF -
digitalWrite(5,LOW); //CHARGING OFF +
digitalWrite(6,LOW); //CHARGING OFF -
}
//-------------------------------------------------------------------------low battery fucntion ------------------------------------------------------------------------------------
void low_battery(){ //operation performed fucntion if battery is low.
digitalWrite(2,HIGH); //MOTOR ON +
digitalWrite(4,HIGH); //MOTOR ON -
digitalWrite(5,HIGH); //CHARGING ON +
digitalWrite(6,HIGH); //CHARGING ON -
}
//---------------------------------------------------------------------------feedback function---------------------------------------------------------------------------------------
void feedback(){ //cheching the feedback condition and perform operation acco.
float analog_value=analogRead(A4);
float thortar_voltage=(analog_value*5)/1024;
if(thortar_voltage > 1.06){ // A5 is sensing the break and A4 is sensing the thortar.
digitalWrite(10,LOW); //FEEDBACK OFF PHASE 1
digitalWrite(11,LOW); //FEEDBACK OFF PHASE 2
digitalWrite(12,LOW); //FEEDBACK OFF PHASE 3
digitalWrite(7,LOW); //FEEDBACK OFF
}else{
digitalWrite(10,HIGH); //FEEDBACK ON PHASE 1
digitalWrite(11,HIGH); //FEEDBACK ON PHASE 2
digitalWrite(12,HIGH); //FEEDBACK ON PHASE 3
digitalWrite(7,HIGH); //FEEDBACK ON
}
}

Please, use the <'code/> tag.

And the schematic of the circuit is in attechment.
COMPLETE SRT IEG SCOOTY SYSTEM IN ALTIUM.pdf (1.3 MB)

I hope you all got all required details.
Again, I am elaborating the issues:

  1. The voltage measurement: - when i checked on analog pin its shows 2.343 volt and I did "204.8*2.343 " this value I set for relay on for 60v mode, but the relay is not switching. At first I set by calculation, but the value is not matching with software (means calculated values and measure by multimeter values are different so, I measure voltage on analog pin of atmega328 and according to them programmed it, at first the circuit is run properly but after 1-2 weeks the value on analog pin of atmega328 changes and now the final issue is its not turning on/switching.

  2. when I don't connect anything to board and only powered it, then after 2-3 minutes the atmega stop working/freeze all output pin gone to logic zero. I don't know why this is happening. please help me to know.

```void feedback();
void low_battery();
void full_battery();

float battery_low_limit, battery_high_limit;
int battery;
//-------------------------------------------------------------------------------------------setup fun.--------------------------------------------------------------------------
void setup() {
//-------------------------------------------------I/O PINS INITIALIZATION-------------------------------------------------
pinMode(10,OUTPUT);  //feedback relay
pinMode(11,OUTPUT);  //feedback relay
pinMode(12,OUTPUT);  //feedback relay

// pinMode(3,OUTPUT);   // PWM pin

pinMode(2,OUTPUT);   // general purpose relays MOTOR ON/OFF +
pinMode(4,OUTPUT);   // general purpose relays MOTOR ON/OFF -
pinMode(5,OUTPUT);   // general purpose relays CHARGING ON/OFF +
pinMode(6,OUTPUT);   // general purpose relays CHARGING ON/OFF -
pinMode(7,OUTPUT);   // general purpose relays  USED FOR FEEDBACK CONNECTION  TO THE CONTROLLER

pinMode(A0,INPUT);   // battery voltage sensing
pinMode(A1,INPUT);   // 48V battery sensing
pinMode(A2,INPUT);   // 60V battery sensing
pinMode(A3,INPUT);   // 72V battery sensing
pinMode(A4,INPUT);   // thortar sensing
// pinMode(A5,INPUT);   // break sensing

//---------------------initial states of system relay-----------------------------------------
   digitalWrite(2,LOW); //MOTOR OFF +
   digitalWrite(4,LOW); //MOTOR OFF -
   digitalWrite(5,LOW); //CHARGING OFF +
   digitalWrite(6,LOW); //CHARGING OFF -
   digitalWrite(7,LOW); //FEEDBACK ON

   digitalWrite(10,LOW);  //FEEDBACK OFF PHASE 1
   digitalWrite(11,LOW);  //FEEDBACK OFF PHASE 2
   digitalWrite(12,LOW);  //FEEDBACK OFF PHASE 3
//---------------------------------------------------------other parameter initialization ----------------------
if(digitalRead(A1)==HIGH){
 battery=48;                      //48v scooty
}else if(digitalRead(A2)==HIGH){
 battery=60;                      //60v scooty
}else if(digitalRead(A3)==HIGH){
 battery=72;                      //72v scooty
}else{
 battery=48;                      //48v system
}
//----------------------------------------------------switch condition--------------------
  switch(battery){
    case 48:
      battery_low_limit = 291.371; //50v
      battery_high_limit =297.198; //51v WRONG
    break;
    case 60:
      battery_low_limit = 478.822;  //63v
      battery_high_limit =481.477;  //64v
    break;
    case 72:
      battery_low_limit = 437.061;  //75v
      battery_high_limit =442.884;  //76v  
    break;
    //   case 48:
    //   battery_low_limit = 337.920; //50v
    //   battery_high_limit =344.064; //51v
    // break;
    // case 60:
    //   battery_low_limit = 426.846;  //62v  ->63 changes 
    //   battery_high_limit =433.621;  //63v ->64 changes 
    // break;
    // case 72:
    //   battery_low_limit = 507.904;  //75v
    //   battery_high_limit =516.096;  //76v  
    // break;
  }
}
//================================================================================main function=====================================================================================
void loop() {
  feedback();
  delay(30);
  int battery_voltage = analogRead(A0); // Sense the current battery voltage.

  if(battery_voltage <= battery_low_limit){  //check battery is low or not.
    low_battery();                          // calling low battery function.
  }else if(battery_voltage >= battery_high_limit){ // check the battery is fully charged of not.
    full_battery();                               // calling full battery function
  }
 feedback();
 delay(25);
}
//============================================================================full battery function ================================================================================
void full_battery(){                        // operation performed function if battery fullu charged.
   digitalWrite(2,LOW); //MOTOR OFF +
   digitalWrite(4,LOW); //MOTOR OFF -
   digitalWrite(5,LOW); //CHARGING OFF +
   digitalWrite(6,LOW); //CHARGING OFF -
}
//-------------------------------------------------------------------------low battery fucntion ------------------------------------------------------------------------------------
void low_battery(){                         //operation performed fucntion if battery is low.
    digitalWrite(2,HIGH);  //MOTOR ON +
    digitalWrite(4,HIGH);  //MOTOR ON -
    digitalWrite(5,HIGH);  //CHARGING ON +
    digitalWrite(6,HIGH);  //CHARGING ON -
}
//---------------------------------------------------------------------------feedback function---------------------------------------------------------------------------------------
void feedback(){                            //cheching the feedback condition and perform operation acco.
float analog_value=analogRead(A4);
float thortar_voltage=(analog_value*5)/1024;
  if(thortar_voltage > 1.06){  // A5 is sensing the break and A4 is sensing the thortar.
    digitalWrite(10,LOW);  //FEEDBACK OFF PHASE 1
    digitalWrite(11,LOW);  //FEEDBACK OFF PHASE 2
    digitalWrite(12,LOW);  //FEEDBACK OFF PHASE 3
     digitalWrite(7,LOW);  //FEEDBACK OFF
  }else{
    digitalWrite(10,HIGH); //FEEDBACK ON PHASE 1
    digitalWrite(11,HIGH); //FEEDBACK ON PHASE 2
    digitalWrite(12,HIGH); //FEEDBACK ON PHASE 3
     digitalWrite(7,HIGH); //FEEDBACK ON
  }
}
1 Like

Your PCB has quite a few mistakes but the worst is connecting D3 direcly to two PC817s without current limiting resistors.
That most certainly damaged the 328.

thanks for that, but I noticed that earlier and that's why I didn't use pc817. I design that pcb for both use with and without pc817, So when I noticed that mistake then is decided to use the pcb in mode two means without pc817 and used new atmega328. After all that the problem is same. sometimes the relays automatic trigger without any input signals. If you notice anything wrong in PCB tracks designing or anything else, please let me know.
086M_SRT_SRT IEG SCOOTY SYSTM - V7.pdf (103.5 KB)

I checked the circuit many times and didn't find anything wrong with that. from my opinion, the issue is generated by microcontroller atmega328, but I don't know resign behind that. Is Input pins read wrong or they are sensing a lot of noise?

I have deleted your other cross-post @pradeepetce.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I checked the circuit board by running outside and found that when throttle is sensed by the atmega328p analog pin one throttle hall sensor is blown, means throttle is dead, but the problem is not detected. I added a 500R resister between throttle and A4 pin. for solving this issue. But I am not sure it will work or not?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.