AVR ATmega scheme

Discussion in 'Homework Help' started by majraL, Feb 16, 2015.

  1. majraL

    Thread Starter New Member

    Feb 16, 2015
    5
    0
    Hi!
    I have difficulties to understand this scheme. My professor gave this to me in an exam and I didn't knew what was that about. The question was "What this scheme represent and how does it work?". Nevermind about the question at the exam, but when asked, the professor told me "you have google" :). In my lectures there is none that I can relate this scheme to. In the datasheet of ATmega there is also none that can tell me something about this. Maybe I'm looking for something to specific that tells me something about this.

    Hope someone can tell me more about this in any direction. Thanks :)

    [​IMG]
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    Moved from Embedded Systems and Microcontrollers to Homework Help.
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,340
    1,022
    It is reading the AC mains cycle by putting a big resistance in series with the input pin and letting the internal protection diodes clip the mains voltage to Vcc and GND. The program will read 1 on the positive half cycle and 0 on the negative half cycle.

    This is a stupid and dangerous way to sample the AC cycle. It used to be shown in old Microchip application notes but is NOT recommended any more for safety reasons and the fact that the ports on newer chips have a very small allowable injection current.
     
  4. majraL

    Thread Starter New Member

    Feb 16, 2015
    5
    0
    Thanks! Is there any particular reason why the AC mains is connected to the pin PD2 - INT0?
     
  5. JohnInTX

    Moderator

    Jun 26, 2012
    2,340
    1,022
    Its probably intended to interrupt the processor on every 1/2 cycle of the AC mains. That way it can be used to sync to the line frequency, maintain a timer etc. The preferred way would be to opto-isolate the AC mains signal or the secondary of the power transformer of a linear power supply for the signal.

    I probably was a bit harsh using the word 'stupid' but if you consider that those 1M carbon film resistors are made by depositing a film of carbon on a ceramic dowel then cutting out an extremely thin spiral of carbon to make the resistor from the carbon remaining, you can see that a simple failure can have dangerous consequences by applying the AC mains voltage to the internal circuitry, any indicators - TOUCH PADS etc. Lets just call it a bad idea.

    And you can quote me on that to your professor.
     
    majraL likes this.
  6. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    +1

    Who knows why the designer needed to monitor the mains signal? As John says, most likely to synchronize to line frequency.

    But that circuit is a 'stupid' idea. Use a step-down isolation transformer or an opto-isolator.
     
  7. majraL

    Thread Starter New Member

    Feb 16, 2015
    5
    0
    Thanks a lot! :) Hope not to get an F when I tell him "that's not a good idea of yours, dear professor" :D
     
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,340
    1,022
    You can always blame it on me!

    Actually, thinking more on it, I can think of some applications that could use something like the scheme shown.

    As an example, consider some of the new 'smart' LED lamps that screw into a standard socket and use an IR or RF remote control to change colors, dim etc. A self contained light bulb would be OK with a non-isolated power supply (lots of cheap LED light bulbs use capacitor coupling to the line for a supply) and syncing to the line cycle as shown would enable syncing a triac/SCR to control the power to the RGB LEDs for dimming and color. If something quit, its all enclosed in a tough, self-extinguishing enclosure. As for driving the AC into the port pin as shown, that would be OK too as long as the chip's datasheet allowed it - keeping the injection current (that the protection diodes have to carry) within spec. Some early Microchip technical briefs actually described a method for powering the chip itself by port injection with AC inputs rectified by the same protection diodes. In a carefully designed circuit for a specific use, why not? So.. not so 'stupid' as I originally said - in specific instances and when all of the ramifications are taken into account.

    For most uses though, you would want to avoid the circuit shown for the reasons noted.

    As for your professor, perhaps you could lay out the case against the circuit BUT cite the certain instances when it might be OK to use it. Guaranteed A! :rolleyes:

    Good luck!
     
    Last edited: Feb 16, 2015
    majraL likes this.
  9. MrChips

    Moderator

    Oct 2, 2009
    12,420
    3,355
    In the context of a test, the question is not asking whether or not the design is a good idea or safe one.

    It would be better to explain the function of the two resistors, the two diodes and the two ground connections.
     
    majraL likes this.
  10. majraL

    Thread Starter New Member

    Feb 16, 2015
    5
    0
    Yes, as MrChips said, think we should get the idea of what is the function of the two 1M resistors, 2 diodes and 2 GND
     
  11. n1ist

    Active Member

    Mar 8, 2009
    171
    16
    I have done a design like this on a commercial light dimmer project. It was much easier and cheaper to have the processor with Vcc at the AC line and isolate the serial connection, due to the number of things that the processor had to monitor and control (dim PWM out, AC voltage and current measurement, zero cross, overcurrent trip, etc.)

    You do need to be EXTREMELY careful when doing this. One careless ground connection can ruin your day. All of my debugging was done with an isolation transformer, differential probes, USB isolators, and isolated serial ports.

    I would not do this unless it was a commercial product where unit cost is key.

    As for the Microchip apps note, it was even worse. They were spec'ing connections between ground and neutral, which is both illegal and very dangerous in fault situations. It took quite a few emails, including a legal notice, before they pulled it.

    /mike
     
  12. majraL

    Thread Starter New Member

    Feb 16, 2015
    5
    0
Loading...