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.

an idea to power reset the MCU?

johnny78

Full Member level 5
Full Member level 5
Joined
Jun 28, 2017
Messages
256
Helped
1
Reputation
2
Reaction score
4
Trophy points
1,298
Activity points
3,340
hi Guys

i have a problem with my armega328p which it got frozen few times
the WDT couldnt reset it So i was thinking of power reset by feeding power through a P channel Mosfet then reset power by cutting the power for a while

im using 16x2 i2c lcd & ds1307 with the Atmega328p & im not sure if the MCU got frozen or just the LCD so i have 2 questions

1:is it enough perrod of time if i cut the power by using a pin of the mcu then after restart the reset condition finished
2:give me an idea to do this please

thanks
Johnny
 
The 10F202 I used was in an 8-pin DIP package because I had them in stock but two of the pins are "no connect" and are not internally connected to the die. There is a 6-pin version in SOT23-5 package. They are one of the cheapest MCUs at 0.60 UKP or about 0.70 Euros/USD including tax.
Programming info: https://ww1.microchip.com/downloads/en/DeviceDoc/41228F.pdf

If you look on the internet there are several inexpensive programming tools that cover all the microchip devices including the 10F202.

Brian.
thanks Brian
yes its cheap but its not available here unfortunately & yes i have Pic kit3 & it should program it
i will check if i can ship it to somewhere near my place to get it
thanks for help

Johnny
 
The 10F202 I used was in an 8-pin DIP package because I had them in stock but two of the pins are "no connect" and are not internally connected to the die. There is a 6-pin version in SOT23-5 package. They are one of the cheapest MCUs at 0.60 UKP or about 0.70 Euros/USD including tax.
Programming info: https://ww1.microchip.com/downloads/en/DeviceDoc/41228F.pdf

If you look on the internet there are several inexpensive programming tools that cover all the microchip devices including the 10F202.

Brian.
hi Brian
i've found a cheap MCU pic12c508P but i cant find it on supported devices on the pic kit3
i have used Pic 12c508A few times & i can code it in assembly but would you check the 12c508P if i can program it on my pic kit3?
i didnt find it on Mplab IDE . there is the A version & i couldnt know what difference it have

thanks
Johnny
 
Last edited:
The 12C508 has been obsolete for a long time, superseded by the 12F508. They are almost identical and will run the same code but the 'F' version uses a different kind of memory internally. You can try programming it as a 12C508A but I suspect it will fail because they have different chip IDs so the PicKit will say it has the wrong device.

The 12C508 is still listed in the Microchip IPE 6.20 which I think is the latest version.

The only difference between the 12C508 and the 12C508A is the 'A' version can have its oscillator calibration adjusted, the version without the 'A' is fixed in the factory.

I have attached the hex file of the program I posted earlier but for the 12C508 instead of the 10F202. I haven't tested it but functionally they should be the same. Note the pin numbers are different but the pin names are still valid.

Brian.
 

Attachments

  • autoreset1.zip
    558 bytes · Views: 22
the WDT couldnt reset it
Why would you want to add more components to your board? I would fix the problem in your code. You can find lots of example code for the atmega328p just about everywhere. The watchdog works very well in the atmega328p. There is no need to add other components.
 
Dealing with a frozen microcontroller can be challenging, especially when debugging intermittent issues. Your approach to use a P-channel MOSFET for power reset is valid, and I'll provide insights on your two questions:

### 1. Power Reset Duration

Cutting power to the ATmega328P to reset it can indeed help if the MCU is frozen and not responding. The duration for which you need to cut the power depends on the specifics of your circuit and the stability of the reset condition you need. However, a few seconds is usually sufficient to ensure a complete reset. Here’s a general guideline:

- **Power Cut Duration**: A duration of 1 to 5 seconds is typically sufficient to reset most microcontrollers. This allows the MCU to fully discharge and reset any internal states. Ensure that during this period, any external components or peripherals also get a proper reset if needed.

### 2. Implementing Power Reset with a P-Channel MOSFET

Here’s a general approach for using a P-channel MOSFET to cut the power to your ATmega328P:

#### Components Needed:
- P-Channel MOSFET (e.g., IRF9540, IRF520)
- Capacitor (for time delay)
- Resistors (for pull-up/pull-down)
- NPN transistor or N-channel MOSFET (optional, for driving the gate of the P-channel MOSFET)

#### Circuit Design:

1. **P-Channel MOSFET Connection**:
- **Source (S)**: Connect to the positive power supply (e.g., 5V).
- **Drain (D)**: Connect to the VCC pin of the ATmega328P.
- **Gate (G)**: Connect to a control signal (e.g., from a GPIO pin of the ATmega328P).

2. **Gate Control**:
- Use a resistor (e.g., 10kΩ) to pull the gate of the MOSFET to the source voltage (to keep the MOSFET off by default).
- To turn off the MOSFET, the gate voltage needs to be pulled low (below the source voltage).

3. **Control Circuit**:
- Use a GPIO pin of the ATmega328P to control the gate of the P-channel MOSFET.
- When you want to cut power, set the GPIO pin to LOW, which turns off the MOSFET and disconnects the power to the ATmega328P.

4. **Power Cut Duration**:
- To ensure a reliable power cut, you might use a capacitor in conjunction with a transistor or MOSFET to delay the power restoration after the cut. The capacitor will hold the gate voltage low for a few seconds before returning it to the high state, allowing the ATmega328P to reset completely.

#### Example Schematic:

1. **Capacitor and Resistor Network**:
- Connect a capacitor (e.g., 100µF) between the gate of the MOSFET and ground. This capacitor will help in keeping the gate voltage low for a brief period after the power is cut.
- A resistor (e.g., 10kΩ) between the gate of the MOSFET and the source (5V) will ensure that the MOSFET stays off when not actively driven by the GPIO pin.

2. **Control Logic**:
- Use a simple NPN transistor or another MOSFET to drive the gate of the P-channel MOSFET if needed. The NPN transistor can be used to pull the gate of the P-channel MOSFET to ground when needed.

### Example Code to Trigger the Reset:
You can use a GPIO pin to control the gate of the MOSFET. When a reset condition is detected, you can set the pin low to cut the power.

```c
const int resetPin = 8; // Example pin connected to the gate of P-channel MOSFET

void setup() {
pinMode(resetPin, OUTPUT);
}

void loop() {
// Example condition to trigger reset
if (/* your condition */) {
digitalWrite(resetPin, LOW); // Cut the power
delay(5000); // Wait for 5 seconds
digitalWrite(resetPin, HIGH); // Restore the power
delay(1000); // Delay to ensure the MCU is fully powered up
}
}
```

### Additional Tips:
- Ensure that your power supply and MOSFET are capable of handling the current requirements of the ATmega328P and peripherals.
- Test your reset circuit thoroughly to ensure it performs reliably and does not inadvertently cause additional issues.

By implementing the above approach, you should be able to reset your ATmega328P reliably if it gets frozen, and ensure that any peripherals like the LCD and DS1307 are also properly reset.
 
The 12C508 has been obsolete for a long time, superseded by the 12F508. They are almost identical and will run the same code but the 'F' version uses a different kind of memory internally. You can try programming it as a 12C508A but I suspect it will fail because they have different chip IDs so the PicKit will say it has the wrong device.

The 12C508 is still listed in the Microchip IPE 6.20 which I think is the latest version.

The only difference between the 12C508 and the 12C508A is the 'A' version can have its oscillator calibration adjusted, the version without the 'A' is fixed in the factory.

I have attached the hex file of the program I posted earlier but for the 12C508 instead of the 10F202. I haven't tested it but functionally they should be the same. Note the pin numbers are different but the pin names are still valid.

Brian.
thx Brian
i have used the 12c508 before & the F version is erasable i still have one to test the code & yes it works on the pic kit3 as 12c508 then i will program the 12c508/P
& if the difference is in the oscillator calibration its not important at all for my app i guess

thanks
Johnny
--- Updated ---

as
Why would you want to add more components to your board? I would fix the problem in your code. You can find lots of example code for the atmega328p just about everywhere. The watchdog works very well in the atmega328p. There is no need to add other components
you are right But my code is working great & i have tested the WDT manually & it works but when the issue happened 3 times for different devices the WDT couldnt do its Job
1:after 8 months
another device after 6 months & another one after 1 year
its 24/24h working device & i dont want to try to fix it & fail after few months
so this Treatment is useful for my issue

thanks
Johnny
--- Updated ---

Dealing with a frozen microcontroller can be challenging, especially when debugging intermittent issues. Your approach to use a P-channel MOSFET for power reset is valid, and I'll provide insights on your two questions:

### 1. Power Reset Duration

Cutting power to the ATmega328P to reset it can indeed help if the MCU is frozen and not responding. The duration for which you need to cut the power depends on the specifics of your circuit and the stability of the reset condition you need. However, a few seconds is usually sufficient to ensure a complete reset. Here’s a general guideline:

- **Power Cut Duration**: A duration of 1 to 5 seconds is typically sufficient to reset most microcontrollers. This allows the MCU to fully discharge and reset any internal states. Ensure that during this period, any external components or peripherals also get a proper reset if needed.

### 2. Implementing Power Reset with a P-Channel MOSFET

Here’s a general approach for using a P-channel MOSFET to cut the power to your ATmega328P:

#### Components Needed:
- P-Channel MOSFET (e.g., IRF9540, IRF520)
- Capacitor (for time delay)
- Resistors (for pull-up/pull-down)
- NPN transistor or N-channel MOSFET (optional, for driving the gate of the P-channel MOSFET)

#### Circuit Design:

1. **P-Channel MOSFET Connection**:
- **Source (S)**: Connect to the positive power supply (e.g., 5V).
- **Drain (D)**: Connect to the VCC pin of the ATmega328P.
- **Gate (G)**: Connect to a control signal (e.g., from a GPIO pin of the ATmega328P).

2. **Gate Control**:
- Use a resistor (e.g., 10kΩ) to pull the gate of the MOSFET to the source voltage (to keep the MOSFET off by default).
- To turn off the MOSFET, the gate voltage needs to be pulled low (below the source voltage).

3. **Control Circuit**:
- Use a GPIO pin of the ATmega328P to control the gate of the P-channel MOSFET.
- When you want to cut power, set the GPIO pin to LOW, which turns off the MOSFET and disconnects the power to the ATmega328P.

4. **Power Cut Duration**:
- To ensure a reliable power cut, you might use a capacitor in conjunction with a transistor or MOSFET to delay the power restoration after the cut. The capacitor will hold the gate voltage low for a few seconds before returning it to the high state, allowing the ATmega328P to reset completely.

#### Example Schematic:

1. **Capacitor and Resistor Network**:
- Connect a capacitor (e.g., 100µF) between the gate of the MOSFET and ground. This capacitor will help in keeping the gate voltage low for a brief period after the power is cut.
- A resistor (e.g., 10kΩ) between the gate of the MOSFET and the source (5V) will ensure that the MOSFET stays off when not actively driven by the GPIO pin.

2. **Control Logic**:
- Use a simple NPN transistor or another MOSFET to drive the gate of the P-channel MOSFET if needed. The NPN transistor can be used to pull the gate of the P-channel MOSFET to ground when needed.

### Example Code to Trigger the Reset:
You can use a GPIO pin to control the gate of the MOSFET. When a reset condition is detected, you can set the pin low to cut the power.

```c
const int resetPin = 8; // Example pin connected to the gate of P-channel MOSFET

void setup() {
pinMode(resetPin, OUTPUT);
}

void loop() {
// Example condition to trigger reset
if (/* your condition */) {
digitalWrite(resetPin, LOW); // Cut the power
delay(5000); // Wait for 5 seconds
digitalWrite(resetPin, HIGH); // Restore the power
delay(1000); // Delay to ensure the MCU is fully powered up
}
}
```

### Additional Tips:
- Ensure that your power supply and MOSFET are capable of handling the current requirements of the ATmega328P and peripherals.
- Test your reset circuit thoroughly to ensure it performs reliably and does not inadvertently cause additional issues.

By implementing the above approach, you should be able to reset your ATmega328P reliably if it gets frozen, and ensure that any peripherals like the LCD and DS1307 are also properly reset.
thx Mr
i was testing the p channel mosfet right now & it works great & 500ms was enoug to reset the mcu & the lcd so i will use 1 sec reset
why should i use capacitor for the gate of the mosfet ?
it will stay On except when applying reset pulse

thanks
Johnny
--- Updated ---

The 12C508 has been obsolete for a long time, superseded by the 12F508. They are almost identical and will run the same code but the 'F' version uses a different kind of memory internally. You can try programming it as a 12C508A but I suspect it will fail because they have different chip IDs so the PicKit will say it has the wrong device.

The 12C508 is still listed in the Microchip IPE 6.20 which I think is the latest version.

The only difference between the 12C508 and the 12C508A is the 'A' version can have its oscillator calibration adjusted, the version without the 'A' is fixed in the factory.

I have attached the hex file of the program I posted earlier but for the 12C508 instead of the 10F202. I haven't tested it but functionally they should be the same. Note the pin numbers are different but the pin names are still valid.

Brian.
i need your help with the 12c508 code
i didnt use is since long time & i need to prepare everything for the PIC environment & i have tried to code it using mikro C for pic but the 12c508 isnt supported
would you please do this few lines code for me & send me the hex file again?

pin5 the gp2 i will use for reset or anyone its ok

code to be run once on power startup not like in main loop

turn on pin5
wait for 1 sec
turn off pin5
end

thanks
Johnny
 
Last edited:
I've attached a program that should do the job although it just behaves like a monostable timer. It sets GP2 high for one second after it powers up then lowers it and disconnects the pin in case something else drives it.
The code should work on 12C508 or 12F508.

To the earlier comments about fixing the code and using the internal watchdog, I have written programs in the past that use timer driven interrupts where the MCU has crashed but left the interrupts running and producing signals on the pins. I'm not sure about the ATmega328P, I've never used one but certainly in some devices it is possible for some of the device to crash while other parts continue running. If the running part is still resetting the watchdog it will not recover.

Brian.
 

Attachments

  • johnny508.zip
    730 bytes · Views: 30
Dealing with a frozen microcontroller can be challenging, especially when debugging intermittent issues. Your approach to use a P-channel MOSFET for power reset is valid, and I'll provide insights on your two questions:

### 1. Power Reset Duration

Cutting power to the ATmega328P to reset it can indeed help if the MCU is frozen and not responding. The duration for which you need to cut the power depends on the specifics of your circuit and the stability of the reset condition you need. However, a few seconds is usually sufficient to ensure a complete reset. Here’s a general guideline:

- **Power Cut Duration**: A duration of 1 to 5 seconds is typically sufficient to reset most microcontrollers. This allows the MCU to fully discharge and reset any internal states. Ensure that during this period, any external components or peripherals also get a proper reset if needed.

### 2. Implementing Power Reset with a P-Channel MOSFET

Here’s a general approach for using a P-channel MOSFET to cut the power to your ATmega328P:

#### Components Needed:
- P-Channel MOSFET (e.g., IRF9540, IRF520)
- Capacitor (for time delay)
- Resistors (for pull-up/pull-down)
- NPN transistor or N-channel MOSFET (optional, for driving the gate of the P-channel MOSFET)

#### Circuit Design:

1. **P-Channel MOSFET Connection**:
- **Source (S)**: Connect to the positive power supply (e.g., 5V).
- **Drain (D)**: Connect to the VCC pin of the ATmega328P.
- **Gate (G)**: Connect to a control signal (e.g., from a GPIO pin of the ATmega328P).

2. **Gate Control**:
- Use a resistor (e.g., 10kΩ) to pull the gate of the MOSFET to the source voltage (to keep the MOSFET off by default).
- To turn off the MOSFET, the gate voltage needs to be pulled low (below the source voltage).

3. **Control Circuit**:
- Use a GPIO pin of the ATmega328P to control the gate of the P-channel MOSFET.
- When you want to cut power, set the GPIO pin to LOW, which turns off the MOSFET and disconnects the power to the ATmega328P.

4. **Power Cut Duration**:
- To ensure a reliable power cut, you might use a capacitor in conjunction with a transistor or MOSFET to delay the power restoration after the cut. The capacitor will hold the gate voltage low for a few seconds before returning it to the high state, allowing the ATmega328P to reset completely.

#### Example Schematic:

1. **Capacitor and Resistor Network**:
- Connect a capacitor (e.g., 100µF) between the gate of the MOSFET and ground. This capacitor will help in keeping the gate voltage low for a brief period after the power is cut.
- A resistor (e.g., 10kΩ) between the gate of the MOSFET and the source (5V) will ensure that the MOSFET stays off when not actively driven by the GPIO pin.

2. **Control Logic**:
- Use a simple NPN transistor or another MOSFET to drive the gate of the P-channel MOSFET if needed. The NPN transistor can be used to pull the gate of the P-channel MOSFET to ground when needed.

### Example Code to Trigger the Reset:
You can use a GPIO pin to control the gate of the MOSFET. When a reset condition is detected, you can set the pin low to cut the power.

`c
const int resetPin = 8; // Example pin connected to the gate of P-channel MOSFET

void setup() {
pinMode(resetPin, OUTPUT);
}

void loop() {
// Example condition to trigger reset
if (/* your condition */) {
digitalWrite(resetPin, LOW); // Cut the power
delay(5000); // Wait for 5 seconds
digitalWrite(resetPin, HIGH); // Restore the power
delay(1000); // Delay to ensure the MCU is fully powered up
}
}
`

### Additional Tips:
- Ensure that your power supply and MOSFET are capable of handling the current requirements of the ATmega328P and peripherals.
- Test your reset circuit thoroughly to ensure it performs reliably and does not inadvertently cause additional issues.

By implementing the above approach, you should be able to reset your ATmega328P reliably if it gets frozen, and ensure that any peripherals like the LCD and DS1307 are also properly reset.

I've attached a program that should do the job although it just behaves like a monostable timer. It sets GP2 high for one second after it powers up then lowers it and disconnects the pin in case something else drives it.
The code should work on 12C508 or 12F508.

To the earlier comments about fixing the code and using the internal watchdog, I have written programs in the past that use timer driven interrupts where the MCU has crashed but left the interrupts running and producing signals on the pins. I'm not sure about the ATmega328P, I've never used one but certainly in some devices it is possible for some of the device to crash while other parts continue running. If the running part is still resetting the watchdog it will not recover.

Brian.
thanks Brian
i will test it on12F508 asap
 
I've attached a program that should do the job although it just behaves like a monostable timer. It sets GP2 high for one second after it powers up then lowers it and disconnects the pin in case something else drives it.
The code should work on 12C508 or 12F508.

To the earlier comments about fixing the code and using the internal watchdog, I have written programs in the past that use timer driven interrupts where the MCU has crashed but left the interrupts running and producing signals on the pins. I'm not sure about the ATmega328P, I've never used one but certainly in some devices it is possible for some of the device to crash while other parts continue running. If the running part is still resetting the watchdog it will not recover.

Brian.

I've attached a program that should do the job although it just behaves like a monostable timer. It sets GP2 high for one second after it powers up then lowers it and disconnects the pin in case something else drives it.
The code should work on 12C508 or 12F508.

To the earlier comments about fixing the code and using the internal watchdog, I have written programs in the past that use timer driven interrupts where the MCU has crashed but left the interrupts running and producing signals on the pins. I'm not sure about the ATmega328P, I've never used one but certainly in some devices it is possible for some of the device to crash while other parts continue running. If the running part is still resetting the watchdog it will not recover.

Brian.
hi Brian
i was trying to program the MCU with my pickit3 but im facing problems with it
i didnt use it since more than 3 years & im not sure if it is damaged or not
if you use the same pickit3 maybe you can help me with it

i use mplab IPE & it shows PICKIT3 S.No : DEFAULT_PK3
after connecting to device it shows calibration error for all devices i used & i can erase but when trying blank check it gives me that its not blank
& i can read but cant program

thanks
Johnny
 
I've attached a program that should do the job although it just behaves like a monostable timer. It sets GP2 high for one second after it powers up then lowers it and disconnects the pin in case something else drives it.
The code should work on 12C508 or 12F508.

To the earlier comments about fixing the code and using the internal watchdog, I have written programs in the past that use timer driven interrupts where the MCU has crashed but left the interrupts running and producing signals on the pins. I'm not sure about the ATmega328P, I've never used one but certainly in some devices it is possible for some of the device to crash while other parts continue running. If the running part is still resetting the watchdog it will not recover.

Brian.
hi Brian
i had alot of problems with my pickit3 So i went back to my old k150 programmer & old Xp laptop & programmed the 12c508A & connected a led to pin5 for test but it didnt turn on
& i have bought one 12C508/P which i couldnt know anything about it untill reading it
it was already programmed with something else & locked

can you do this test if you have 12F508 which can be reerased ? which i couldnt find one

thanks
Johnny
 
I have to go away for a few hours, I will investigate later today.

Brian.
was trying to remember about PIC programming
i made a small pic12c508 project on proteus & tested an old pic12c508 hex file i have& it works on proteus
but the code you have send didnt & i've lost an 12c508 chip
 
I have to go away for a few hours, I will investigate later today.

Brian.
hi Brian
i have wrote a new code using Mplab mpasm & have programmed it using K150 programmer & it works
you can help me with my pickit3 problem if you use one

thnks
Johnny
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top