1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

"Modified Sine" wave inverter 18F2431

Discussion in 'Microcontrollers' started by phaedrus, May 31, 2012.

  1. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Hello Gentlemen,

    I am looking for some clarifications on using this micro for a modified sine wave inverter (basically a square wave which has dead bands between the positive and negative cycles). The configuration is a center tapped transformer switched to ground with 2 MOSFET banks.
    I chose this micro since I can get a 50Hz complementary PWM from a 20MHz crystal operation in PCPWM mode using the prescaler and postscaler.And also because it is possible to program dead bands between the 2 complementary PWM outputs.
    I hope someone can vet my assumptions.
    Does a Center Aligned output mode mean that the PWM ON time will be centered at the mid point of the PWM period and not just begin at the mid point of the PWM period ? If so that would make it ideal for this kind of application.
    TIA.
     
  2. atferrari

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,812
    Likes:
    121
    Location:
    Buenos Aires - Argentina
    I think so.

    I recall there are graphics explaining how each mode works.

    Is it hard for you to test a simple setup?

    That is what I would do.

    The power control module has a lot of possibilities. I like that micro.
     
  3. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Hi Atferrari,

    Ah well.... I would do just that eventually.Just that those chips have to purchased online instead of at the local shops.So just checking if my ideas are somewhere in the same ballpark before I order them.
    Thanks !!
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. atferrari

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,812
    Likes:
    121
    Location:
    Buenos Aires - Argentina

    I do not know if it is even possible but could you try to simulate the most basic implementation with Mpsim?
     
  6. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Well I did try it out ,seems like it might not work out.I need a push pull PWM,while this seems to have a complementary PWM,which I confused with a push pull one.

    init_PWM()
    {
    TRISB0 =0;
    TRISB1 =0;
    DTCON = 0b11000101; // dead time for complimentary ouputs
    PTCON0=0b00001100; // free run,fosc/256,1:1 postscale
    PWMCON0=0b00100000; // pwm0/pwm1 comp mode and enabled
    PTDIR=0; // up count
    PTPERL = 0x1b; // 50Hz;12bit (8bits of PTPERL;4 bits PTPERH)
    PTPERH = 0x06;
    PTEN=1; // time base on
    PWMCON1=1;

    PDC0L=0x00;
    PDC0H=0x0f;
    }

    This sets up a PWM of 20mS period (50Hz). Here what I am getting (on a scope) is
    1) PWMA ON period 12.5mS OFF period 7.5mS
    2) PWMB ON period 7.5mS OFF period 12.5mS
     
  7. atferrari

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,812
    Likes:
    121
    Location:
    Buenos Aires - Argentina
    I am not C conversant. Sorry
     
  8. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Hi, have a look at this page;
    http://www.romanblack.com/one_sec.htm

    About half way down the page under "XTAL-locked 50Hz and 60Hz push-pull inverter" there are a couple of projects with C source code using the very cheap and common PIC 12F675 to do what you need.

    There's even a "PWM sinewave" version further down the page that can use the same simple dual FET output hardware and make a pretty good sinewave in the transformer.
     
  9. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Hi Mr.RB,

    I saw your most interesting site quite some while back.
    Mine would be a closed loop system where I would have to change the duty cycle periodically depending on the load and battery voltage.Could you advice me on if your system can be used to do this and what would be the fastest "feedback loop time" (if that's the correct jargon)?

    TIA

     
  10. Mr RB

    Mr RB Well-Known Member

    Joined:
    Jul 22, 2008
    Messages:
    4,716
    Likes:
    194
    Location:
    Out there
    Hi, it sound like you want to do some closed loop voltage regulation of the final AC voltage. That's probably going to be more difficult than you think, and will require some closed loop feedback from the AC output voltage with the PIC adjusting the PWM.

    If you used my code for the simple PWM->Sine generation, you can adjust the PWM values sent to the PWM module to adjust the output voltage. I wish you luck with the project.
     
  11. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Hi Mr.RB,
    Thanks for your reply.
    Actually, this inverter is for a VFD and needs to operate for about 60 seconds only for a backup situation.So a square wave PWM should probably be enough since the VFD generates the sine wave for driving the motor.
     
  12. dougy83

    dougy83 Well-Known Member

    Joined:
    May 18, 2008
    Messages:
    2,672
    Likes:
    215
    Location:
    Brisbane, Australia
    According to the datasheet (http://www.electro-tech-online.com/custompdfs/2012/11/39616d.pdf Figure 18-18), deadtime and half-bridge mode is available.

    It seems that the deadtime doesn't work in the simulator, but works fine in reality: http://www.microchip.com/forums/m238125.aspx
     
    Last edited: Nov 1, 2012
  13. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Hi Dougy,

    Thanks for your post.I think Half Bridge Drive (Push Pull) PWM is different from Complementary PWM.
    View attachment 68376
    For driving a center tapped transformer, Push Pull PWM would be needed AFAIK.

    There are quite a few modes in the 18F2431,but Push Pull Mode does not seem to be there in the PCPWM module.I would love to be shown wrong ;).
    They also have something called the "independent mode" in addition to the "complementary mode" for PWM0 and PWM1.I checked this also on a scope ( not simulation ), but I get the same waveform on both , as if the pins are tied internally.The duty cycle register for both are the same too.Still trying to figure out the meaning of "independent mode" part.
     
  14. dougy83

    dougy83 Well-Known Member

    Joined:
    May 18, 2008
    Messages:
    2,672
    Likes:
    215
    Location:
    Brisbane, Australia
    Yes, you're quite right: half-bridge and complementary are not the same - though comp. can emulate half-bridge for high duty cycles... not that this will help you.

    Have you thought about using the centre-aligned mode and two separate PWM modules? See attached sketch. One module output is inverted.
     
  15. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    I will try this out and post back here.
     
  16. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Hi,

    Thanks Dougy83.

    I did try this out , and I have a few queries :

    1) This will work only if the PWM is configured in Full Bridge Mode ? So I would be leaving 2 pins of the PWM unconnected ?

    2) Is there anyway to calculate the second duty cycle (PULL waveform's ON time) so that it is the same value as the first duty cycle (PUSH waveform's ON time)?
     
  17. dougy83

    dougy83 Well-Known Member

    Joined:
    May 18, 2008
    Messages:
    2,672
    Likes:
    215
    Location:
    Brisbane, Australia
    You'll use 2 PWM modules, e.g. module 0 and 1 (that's PWM pins 0,1,2,3). Select the option of PWMEN = 110 (just enable PWM pins 1 & 3); I assume this means you have the PWM 0 & 2 pins free to use for whatever else.

    If PWMA and PWMB are the duty cycle register values and PWMTOP is the max value it counts to, the register values would be something like:
    PWMA = PWMTOP - dutyCycleCounts
    PWMB = dutyCyclesCounts
     
  18. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    I think as per your original sketch, I would have to LPOL one of the PWM pins ?On reading the DS,it looks like one cannot LPOL pins in isolation.LPOL would make both pins 1 & 3 (on same side of bridge) act as active low.So i would probably have to use pin 0 and pin 3 and leave pin 1 and 2 idle.Do let me know if I have it right.
    So if it is a 12 bit PWM, it would be PWMA= 4095 - dutyCycleCounts ? I did try this,but I was not getting it right.Let me look at it again,I think I might have made a mistake in my code.

    Thanks for your ideas!!
     
  19. dougy83

    dougy83 Well-Known Member

    Joined:
    May 18, 2008
    Messages:
    2,672
    Likes:
    215
    Location:
    Brisbane, Australia
    Yes, LPOL affects the polarity of all even PWM outputs. I've only glanced at the datasheet, but you seem correct. Perhaps you can use pin 1&2 as spare inputs if their outputs must be assigned to the PWM module.

    That should be pretty close.
     
  20. phaedrus

    phaedrus Member

    Joined:
    Apr 30, 2009
    Messages:
    35
    Likes:
    0
    Oddly enough the total duty cycle counts for PWM value is 6144 instead of 4095.The DS says that it is a 14bit PWM but I am unable to get the correct waveforms for a 12 bit value or a 14bit value.
    If I use 6144 then it seems to work exactly the way I need and I get the waveforms as Dougy83 posted.
     

Share This Page