johnny78
Full Member level 5
- Joined
- Jun 28, 2017
- Messages
- 270
- Helped
- 1
- Reputation
- 2
- Reaction score
- 5
- Trophy points
- 1,298
- Activity points
- 3,469
thanks BrianThe 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 BrianThe 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.
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.the WDT couldnt reset it
thx BrianThe 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.
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 JobWhy 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
thx MrDealing 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 need your help with the 12c508 codeThe 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.
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.
thanks BrianI'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 BrianI'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 BrianI'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.
was trying to remember about PIC programmingI have to go away for a few hours, I will investigate later today.
Brian.
hi BrianI have to go away for a few hours, I will investigate later today.
Brian.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?