Zero crossing using PIC18F45K50

Discussion in 'Embedded Systems and Microcontrollers' started by Qual, Sep 6, 2016.

  1. Qual

    Thread Starter New Member

    Aug 5, 2016
    26
    0
    Hi all,

    I am using PIC1845K50 to control fan and i want to start controlling PWM signal whenever PIC detects the zero.
    As per data sheet there is no zero crossing facility by this micro controller.
    Can any one suggest me how to do this in coding with out any extra hardware.
     
  2. Kjeldgaard

    Member

    Apr 7, 2016
    73
    17
    It was very little information.
    Do you have a schematic, you will share with us?
     
  3. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,941
    383
    It depends what hardware you already have. The pic will need some representation of the AC supply waveform to be able to determine the zero crossing point.
     
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,542
    2,369
    See the Fairchild app note AN-3006.
    As already mentioned you will need some way of monitoring the AC waveform for zero crossing.
    How do you intend controlling the AC waveform with PWM?
    Max.
     
  5. Qual

    Thread Starter New Member

    Aug 5, 2016
    26
    0
    well i am using resistive circuit to bring down the AC voltage and then feeding to a op amp (using differential amplifier)
    the output of the op amp is connected to the analog pin of pic.

    Here i am using traic to control the PWM signal...

    But through coding i want to detect zero crossing and then start pwm signal controlling through triac.
     
  6. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,941
    383
    So what is the voltage on that analog pin at the AC input zero-crossing point? Then just wait until the adc gives that reading.
    If you don't know that voltage then we will need the schematic to be able to work it out for you.
     
  7. Sensacell

    Well-Known Member

    Jun 19, 2012
    1,130
    266
    A fan motor will typically be an induction motor, these don't like phase angle control.

    It might "work", but it will be very unstable and non-linear in it's response.
     
    Qual and AlbertHall like this.
  8. Qual

    Thread Starter New Member

    Aug 5, 2016
    26
    0
    Well the voltage on ADC pin will be within 0 to 5 V and i want to start controlling PWM once pic detects zero crossing...

    Now this op amp based Differential amplifier with resistive circuit ( Values are in Mega ohms) is used to bring down AC voltage to mV and then fed to op amp to give differential output.

    So Voltage on ADC pin is within 0 to 5V.
     
  9. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,941
    383
    You need to know the voltage on the ADC pin at the zero crossing point. If you can't work that out then attach the schematic and we will work that out for you.
     
  10. Qual

    Thread Starter New Member

    Aug 5, 2016
    26
    0
    In schematic i have indicated MC at output of Op amp means to say it is going to ADC pin of PIC.
     
    • Fan.jpg
      Fan.jpg
      File size:
      72.2 KB
      Views:
      12
  11. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,941
    383
  12. dannyf

    Well-Known Member

    Sep 13, 2015
    1,809
    361
    Hardware zero crossing detection is certainly a solution. Alternatively, you can do software zero crossing detection: run the ADC continuously on the AC input. Depending on your MCU but 50kps or higher is possible. That means a resolution of 0.36 degrees for 50hz AC. Or 0.7v AC in the 110v world.
     
  13. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,542
    2,369
    How do you intend commutating the Triac using PWM if it is switching the AC line?
    Turning on just after zero crossing?
    Max.
     
  14. Qual

    Thread Starter New Member

    Aug 5, 2016
    26
    0

    Well i would like detect zero crossing without hardware !!!
    Because as of now i cant do changes in hardware!!

    Yes as you said i am running ADC continuously here i am using 24Mhz crystal and configured to get 250 samples.
    But i am not able detect zero crossing exactly...
     
  15. Qual

    Thread Starter New Member

    Aug 5, 2016
    26
    0
    Yes Turn on PWM after detecting Zero crossing.
     
  16. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,542
    2,369
    My question/point is if you turn on the Triac switching an AC signal at zero crossing point it will stay on until the next crossing point, i.e. the PWM will have no effect unless you have a means of commutating it off.
    Unless I am missing something?
    In such as VFD's the AC is 'Manufactured' and switched in frequency and PWM's with IGBT switching transistors.
    Max.
     
  17. AlbertHall

    Well-Known Member

    Jun 4, 2014
    1,941
    383
    For controlling the fan (probably an induction motor which doesn't work well with PWM) it might be better to switch whole cycles - 1 cycle on then 1 cycle off etc.
     
  18. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,542
    2,369
    The common phase angle controlled Triac 'dimmer' style controller is usually OK on the average fan which is generally a shaded pole motor, larger motors with varying loads are not suitable.
    If this method is used with a μp then the zero crossing point detection is still required.
    Max.
     
  19. dannyf

    Well-Known Member

    Sep 13, 2015
    1,809
    361
    Because you are doing it wrong.

    Btw, ADC isn't the only way to do it. You can use the digital input structure of the pin, or the comparator, to trigger a logic high or low, depending on your design, that signals zero crossings.
     
    ErnieM likes this.
  20. dannyf

    Well-Known Member

    Sep 13, 2015
    1,809
    361
    here is how PAM can be done via a GPIO pin:

    Code (Text):
    1.  
    2.         while (IO_GET(IN_PORT, IN)) continue;    //wait for zero crossing
    3.         //zero crossing has taken place
    4.         //optional delay - not implemented
    5.         OUT_ON();                            //turn on the output
    6.         tmr1_dly(OUT_DLY);                    //waste some time
    7.         OUT_OFF();                            //turn off the output
    8.         while (IO_GET(IN_PORT, IN) == 0) continue;    //wait out the negative cycle
    9.  
    10.  
    This little piece detects the zero crossing in the negative cycle, and flip the output pin upon the ZCD for a period of time specified by OUT_DLY (=40ms in this case) and then turn it off.

    The following graph shows the routine in action. V110v is a 110Vrms 50hz signal. it feeds into the GPIO0 pin through a current limit resistor (R1). The output is on GPIO1.

    The resolution is 1us, or for this case, about 15.6 digits.

    In a real program, you will need to put the whole thing through an interrupt like structure but the basic gist is the same. The advantage here is that it can be implemented on a mcu without adc. 12f675 pam_gpio.PNG
     
Loading...