Menu

triac firing angle using PIC12F1840

Help
JANIS
2015-12-11
2015-12-18
1 2 > >> (Page 1 of 2)
  • JANIS

    JANIS - 2015-12-11

    I want build the triac firing angle control for lamp dimmer using PIC (12F1840) and zero crossing detecting circuit.
      Basically I use timer0overflow. The program code is simple and the program is working, but there are nuances. Using analogue input for firing angle reference potentiometer , firing angle remains unstable - in each cycle varies by a few degrees. It can be seen that the lamp does not lit steadily, but little asymmetrical flashes.

    . #chip 12f1840,4
    .#config osc=int
    . #define poti an1
    .#define alpha gpio.5 '' triac firing angle
    .#define sync gpio.4 '' zero crossing detect
    dir alpha out
    dir sync in
    dir poti in
    dir gpio.2 out

    InitTimer0 Osc, PS0_32''
    On Interrupt Timer0Overflow Call impuls
    hpwm 1,150, 127 ''pulse transformer

    main:
    alpha_ref=readad(poti)
    if sync then
    set alpha off
    cleartimer 0
    timer0=alpha_ref
    end if

    wait 10 us '' ????????

    goto main

    sub impuls
    set alpha on
    end sub
    ''==============================
    I assume that the analog inputs the read error occurs and each cycle is changing. I then I tried not to use an analog input, but give a constant angle, the results are much better, but still the lamp is not lit steadily,but also little asymmetrical flashes.

    alpha_ref=150 ''' const

    HPWM is for pulse transformer. I've tried two variants - triac control with pulse transformers and using the optocouple, the results are similar. I understand that the need to use another interrupt.
    I should be grateful for every idea!

     
    • Chuck Hellebuyck

      You could try to use the Zero Cross Detect feature on some of the newer PIC devices.
      Here is a brief description for firing a triac.
      http://microchip.wikidot.com/tip:13

      You would have to switch to a new device such as the 12F1612 that has the ZCD peripheral. I'm not sure if that device is supported in GCB yet. You'll have to check.

       
      • Anobium

        Anobium - 2015-12-11

        12F1612 is supported in v0.95 release (due for release December 2015)

         
  • David Stephenson

    I don't really understand your circuit, but I have made a device to dim then brighten (for chritmas lights).
    It detects the zero cross using an unsmoothed full wave rectifier off a transformer (with a zener to avoid going over 5V).
    Here is the program

     
  • lhatch

    lhatch - 2015-12-11

    David, do not think GPIO 3 can be an output. Do you have a schematic on the circuit. I would like to see it. Also I changed the code and removed the NR's

    Maybe the OP will want to try your way, sounds simpler and cheaper.

     

    Last edit: lhatch 2015-12-16
    • David Stephenson

      Here is the schematic. In my actaul system I have 4 of these circuits running 50 lights each all on different timing cycles. {edited to correct schematic}

       

      Last edit: David Stephenson 2015-12-16
    • David Stephenson

      Just for amusement I compiled your modified program as I suspected it would give exactly the same as mine in ASM. The surprise is it didn't. Indeed as far as I can see we seem to have a loop that seems to be impossible to break out of. Maybe somebody with more experience with ASM can figure out what is going on here. I have marked the suspect loop with !!!!!!!!!!!!!!!!!!!!!!!!.

       

      Last edit: David Stephenson 2015-12-16
      • Anobium

        Anobium - 2015-12-16

        @David. You are using a compiler from (0.94 2015-04-02). Janis is using the latest Release Candidate. The results may be different and will be different. I can let you have the lastest copy if you want to be on the same release.

         
  • JANIS

    JANIS - 2015-12-11

    Many thanks to all! I did not know about the ZCD peripheries. Actually, I need a microcontroller with more ports that can operate with 7-segment display. Are there any examples for ZCD configuration?

     
  • JANIS

    JANIS - 2015-12-11

    In my case can use PIC16F170x family

     
  • JANIS

    JANIS - 2015-12-11

    But it seems to me that GCB does not support pc16f170x series.

     
    • Anobium

      Anobium - 2015-12-11

      GCB does support16f170x devices. From v0.94.

       
  • JANIS

    JANIS - 2015-12-12

    Thank you all for your suggestions !!!
    In attachment is wiring diagramm in order to understand the program code. David Stephenson example does not suit me. Apologies Anobium, the new hot reliese includes files for controllers with ZCD . I think in my case are necessary PIC16F1709. I do not know how to configure the configuration registers ..
    I think that the proper organization of the program code, the scheme need to work correctly.
    May not need to use Timer 0? Now, seeing the scheme, maybe someone can corrections to my code? Soon I'll buy pic16f1709 and will then have to create another program code. But now I need made correct programmcode for this scheme. Help...

     
  • JANIS

    JANIS - 2015-12-12

    I exchange places ports in order to use RA2 for
    Interrupt on rising edge.

    Also, this idea is not working. :(((((

    / #chip 12f1840, 16
    / #config osc=int

    CCP1SEL=1 ''PWM uz gpio.5 APFCON: ALTERNATE PIN FUNCTION CONTROL REGISTER page 112

    / #define poti an1
    /#define alpha gpio.4
    /#define sync gpio.2
    /#define button gpio.0
    dir gpio.5 out
    dir button in
    dir alpha out
    dir sync in
    dir poti in

    dim pushtime as word

    InitTimer0 Osc, PS0_128 ''PS0_32''
    On Interrupt Timer0Overflow Call impuls

    now=0
    prev=0
    pushtime=0
    aa=0

    INTF=0 '' bit 1 INTF: INT External Interrupt Flag bit
    ''''''''1 = The INT external interrupt occurred
    ''''''''0 = The INT external interrupt did not occur

    INTE=1 '' bit 4 INTE: INT External Interrupt Enable bit
    ''''1 = Enables the INT external interrupt
    ''''0 = Disables the INT external interrupt

    GIE=1 ''bit 7 GIE: Global Interrupt Enable bit
    ''''''''1 = Enables all active interrupts
    ''''''''''''0 = Disables all interrupts
    hpwm 1,5, 127 ''HPWM channel, frequency, duty cycle

    INTEDG=1 ' Interrupt on rising edge of RA2/INT/...... pin
    on Interrupt ExtInt0 call ISR

    main:

    if !button then
    pushtime++
    else
    pushtime=0
    end if

    if pushtime =>20000 then aa=0

    now= !button & pushtime<20000
    if now>prev then
    aa++
    end if

    select case aa
    case 0
    alpha_ref=255
    case 1
    alpha_ref=220
    case 2
    alpha_ref=200
    case 3
    alpha_ref=180
    case 4
    alpha_ref=160
    case 5
    alpha_ref=140
    case 6
    alpha_ref=120
    case 7
    alpha_ref=100
    case 8
    alpha_ref=90
    case 9
    alpha_ref=80
    case 10
    alpha_ref=70
    case 11
    aa=0
    end select
    prev=now
    ''wait 10 us
    goto main
    ''==========================

    sub impuls
    set alpha on
    end sub
    ''==========================
    sub ISR
    if INTF then
    set alpha off
    cleartimer 0
    timer0=alpha_ref ''uzstada timer0 laiku
    INTF=0
    end if
    end sub

     
    • Anobium

      Anobium - 2015-12-13

      Hi, what version of GCB compiler are you using? We have improved timers in v0.95 and it me best to get you on the latest release before responding.

      But, try editing "ps0_32" to ps0_32. No quotes.

       
    • Anobium

      Anobium - 2015-12-13

      Hi, what version of GCB compiler are you using? We have improved timers in v0.95 and it me best to get you on the latest release before responding.

      But, try editing "ps0_32" to ps0_32. No quotes.

       
  • JANIS

    JANIS - 2015-12-13

    Thank Anobium. I am using V3.0. What has been improved?
    Prescalers in quotes is because I tried to use different combinations of clock frequency and prescaler. :)))
    ps0_32 works in combination with the frequency of 4MHz and so on.

     
    • Anobium

      Anobium - 2015-12-13

      I would like you to look on the LST for you project. At the top it will show the date etc of te compiler. I would like this information.

      Mine is 'GCASM List File (GCBASIC 0.94 2015-12-08)'

      Evan

       
  • JANIS

    JANIS - 2015-12-13

    Aha. now I understand, Anobium.

    GCB 0.9 11/5/2014

     
    • Anobium

      Anobium - 2015-12-13

      OK. Let us get you on the latest build. Why? We have changed the Timers addresses to improve usage.

      Please send me a Personal Message via SourceForge with your email address. Do not post here.

      When you get the latest build DO NOT overwrite your existing setup. Take a backup etc. Then, use the installer to install the latests build. You WILL have to reconfig your programmer but that is relatively simple.

       
  • JANIS

    JANIS - 2015-12-13

    Anobium, I did not know that personal letters is the limit here. I can not more sent You a personal letter.

     
    • Anobium

      Anobium - 2015-12-13

      Re personal messages. You can only send one response. :-(

       
  • Anobium

    Anobium - 2015-12-13

    @all helping Janis. He now has Release Candidate 031. Therefore, he has the latest and greatest build.

    @janis. Should yoube clearing TMR1IF in method impul?

    sub impuls
    set alpha on
    TMR1IF = 0
    end sub
    
     
  • JANIS

    JANIS - 2015-12-13

    Anobium,
    I do not know what to do now. The program code now is compiled with syncwr and code not complex and running. When measuring with an oscilloscope, everything looks beautiful, as only a very small ripple. Probably I need to find some other solution.....
    If the thyristor is opened fully (alpha ref = 255), then the lamp is burning steadily without ripple. But reducing the opening angle and the lamp remained dark as is visible in a small ripple. In fact, I will be provided for inductive load. Therefore optodiacs is not used, but the pulse transformer.

     
  • JANIS

    JANIS - 2015-12-13

    Thank you! I'll try!

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.