• AVR Freaks

Hot!voltage inverter with pic 16f628a with ASM code

Author
jose16f
New Member
  • Total Posts : 4
  • Reward points : 0
  • Joined: 2020/01/21 13:21:05
  • Location: 0
  • Status: offline
2020/01/22 06:34:50 (permalink)
0

voltage inverter with pic 16f628a with ASM code

friends of the forum a cordial greeting and a happy year

  I come to you to request please if you can help me make some modifications of my program for a voltage inverter using pic 16f28a square wave and frequency of 60 Hz.
in the University for a final work they asked me to modify the initial program with which I did to obtain the square wave and the frequency of 60 hz, and my professor put me the challenge of modifying the program to have the sine wave and frequencies of 50Hz and 60Hz, that is a sine wave program with a frequency of 50 Hz and another program with a sine wave with a frequency of 60 Hz and the amplifier stage for power transistors and voltage transformer.
Well I attached an image of the circuit in the simulation of proteus and the program code in mplab
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;inverter Program
; 4 MHz internal oscillator

;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

LIST P = 16F628A
INCLUDE <P16F628A.INC>
ERRORLEVEL -302

;--------------------------------------------------------------------------------------
; Bit's de configuración

__CONFIG _INTOSC_OSC_NOCLKOUT&_WDT_OFF&_PWRTE_ON&_MCLRE_ON&_BODEN_ON&_LVP_OFF&DATA_CP_OFF&_CP_OFF

;--------------------------------------------------------------------------------------
;
RAMbase EQU H'20' ; 

;--------------------------------------------------------------------------------------
;

#DEFINE SALIDA_A PORTB,0 ; Pines a usar con el LCD
#DEFINE SALIDA_B PORTB,1

;--------------------------------------------------------------------------------------
; Definición de RAM's
cblock RAMbase
TIMER1,TIMER2
endc

;--------------------------------------------------------------------------------------
;Definición de macros
BANCO_0 macro
bcf STATUS,RP0
bcf STATUS,RP1
endm

BANCO_1 macro
bsf STATUS,RP0
bcf STATUS,RP1
endm


;--------------------------------------------------------------------------------------
ORG .0 ; Vector de RESET
BANCO_0
clrf INTCON
goto INICIO

ORG .4 ; Vector de interrupciones
return

;######################################################################################
INICIO ; Programa Principal

movlw .7
movwf CMCON
bsf STATUS,RP0
movlw B'11111111'
movwf TRISA
movlw B'11111100'
movwf TRISB
bcf STATUS,RP0

RE_INI
bsf SALIDA_A
call DEMORA_4.33
bcf SALIDA_A
call DEMORA_4
goto $+1

bsf SALIDA_B
call DEMORA_4.33
bcf SALIDA_B
call DEMORA_4

goto RE_INI

;--------------------------------------------------------------------------------------
DEMORA_4.33 ; Rutinas de demoras varias
movlw .13
goto $+2
DEMORA_4 ; Rutinas de demoras varias
movlw .12
movwf TIMER1
LOOP_1
movlw .110
movwf TIMER2
LOOP_2
decfsz TIMER2,F
goto LOOP_2
decfsz TIMER1,F
goto LOOP_1
return

;--------------------------------------------------------------------------------------
ORG 0x2100 ; Memoria EEPROM

Data H'00' ;

;--------------------------------------------------------------------------------------

END

I hope you can help me
thanks




 

Attached Image(s)

#1

15 Replies Related Threads

    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/22 16:05:54 (permalink)
    +1 (1)
    You haven't actually asked a question.
    What do you want a know? Plainly we are not going to do your assignment for you.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    jose16f
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2020/01/21 13:21:05
    • Location: 0
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/22 19:03:18 (permalink)
    0
    that is to say, I need to modify the initial program to obtain a sine wave at 60Hz and 50 Hz, well I did the program previously and I obtained a square wave with a frequency of 60Hz, on this same program I want to make a modification for a sine wave at 60Hz and 50Hz .
      which would be the necessary modifications of my initial program to obtain a sine wave at 60Hz and 50Hz.
    I wait for your kind answers and thanks
    José
    #3
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/22 19:18:18 (permalink)
    +2 (2)
    If you submitted this code as your final version, I personally would be unlikely to give you a pass.
    It is missing vital comments saying what each bit does.
    I can see "Rutinas de demoras varias" meaning "various delay routines", but not much more.
    That means anyone looking at this code has no idea how long each delay is meant to be, without reverse engineering your code. You really need to improve your coding practices and properly comment your code if you want anyone else to look at it.
    This is crucial is real life (i.e. when you do this as a job). The "someone else" would include yourself more than 6 months after you wrote the initial code.
     
    Next, you have two challenges. Do you know what is required to produce a sine wave with a digital output signal?
    Finding out is obviously what your teacher wants you to do.
    Changing from 60 Hz to 50Hz would be trivial if the code was properly commented.
    Outputting sine instead of square is a much bigger challenge.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    jose16f
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2020/01/21 13:21:05
    • Location: 0
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/22 21:23:19 (permalink)
    0
    I explain better, I know that to make a voltage inverter there are many electronic circuits such as 555, cd 4047, so I have replaced these circuits with an asm program, when I started programming in this language the programming lines were extended to me, Now I am studying other CCS compilers, Mikroc etc.
    I know that my program gives me a square wave with a frequency of 60 Hz, I have tested this circuit on a protoboard with a 40W transformer.
    and my teacher wants this same program to generate a sine wave at 60 Hz and then make other modifications to the program so that it generates a sine wave at 50 Hz.
    Anyway, thank you for responding and I will continue studying the mplab more, well it is a way to have distraction since I suffer from leukemia and received daily chemotherapy, for my leukemia I am studying for distance and virtual education.
    José
    #5
    PStechPaul
    Super Member
    • Total Posts : 2506
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/22 23:58:23 (permalink)
    +1 (1)
    Generating a sine wave is usually accomplished by using PWM, and that is typically done with a full H-bridge and four PWM signals with appropriate drivers. The PIC16F628A has only one PWM channel, so it would be difficult to use this device for that purpose. There are many "modified sine wave" inverters which use a rectangular waveform which can be used for many AC appliances.
     
    If you must use an old, simple PIC, the PIC16F684 has up to four PWM channels which can drive an H-bridge to achieve your goal.
     
    Another way to produce a sine wave is by means of a DAC, which is available on more recent PICs like the PIC16LF1508, but that is not very practical for AC power.
     
    There should be many posts in this forum about generating sine waves using various methods, and a general internet search will show many more.
     
    A good place to start: https://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en567897
     

     
    #6
    jose16f
    New Member
    • Total Posts : 4
    • Reward points : 0
    • Joined: 2020/01/21 13:21:05
    • Location: 0
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/23 04:51:52 (permalink)
    0
    friend thanks for helping me with your clearest explanation, I inform you about the pic PIC16F684 that on the next microchip sales page, is available for purchase.
    https://www.microchipdire.../search/all/PIC16F684, now the next step is to make the necessary modifications to my program to get the sine wave with the H bridge, something else I learn more about this pic than ever I had studied and programmed it.
    Could you help me make the necessary modifications to my program with pic 16f684 and bridge h to get the sine wave?
    thanks
      José
    #7
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/23 12:14:56 (permalink)
    +1 (1)
    jose16f
    I inform you about the pic PIC16F684 that on the next microchip sales page, is available for purchase.
    https://www.microchipdire.../search/all/PIC16F684,

    Every single PIC16F device Microchip have ever made is still available for purchase. That doesn't mean it is a good idea to use them.
    If you go to the PIC16F684 product page on the Microchip website
    https://www.microchip.com/wwwproducts/en/PIC16F684
    it says right at the top you'd be better using a PIC16F18324
    https://www.microchip.com/wwwproducts/en/PIC16F18324
     

    now the next step is to make the necessary modifications to my program to get the sine wave with the H bridge,

    The "necessary modifications" will be a total rewrite.
    Did you read about PWM, and have a look at the link that Paul gave you?
    This is not just a matter of tweaking a few lines of code.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    1and0
    Access is Denied
    • Total Posts : 10346
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/23 12:59:57 (permalink)
    +1 (1)
    Sound like someone wants to run before he can crawl. ;)
    #9
    PStechPaul
    Super Member
    • Total Posts : 2506
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/23 14:23:21 (permalink)
    +1 (1)
    The link I provided for AN1660 has the source code and other design files needed for a PIC16F1509. As this is homework, and intended to make you do research and think independently for this and future designs, it would be counterproductive for any of us to do your work for you. It is a huge leap from generating a simple square wave as you have done, to producing a PWM sine wave. I would suggest that you first design and build a DC motor controller, or even an LED driver, using PWM to adjust speed or brightness. Then you can figure out how to adjust the PWM according to a sine function. If you at least make an attempt to do this on your own, and get stuck, show us your code and what you have tried to debug the code. Also, please use [ code] [ /code] tags (without spaces) to make your code more readable, and, as suggested, include detailed comments to show what you are trying to do.
     
    As an example of what will be needed, here is the main() code from the AN1660. It is just a small fraction of the complete project:
    void main(void) {
        bool finished;
        MAIN_STATES mainState;

        /**
         * Main Loop
         *
         * Take a sample of the SPEED_POT and CURRENT_PINCH_POT at a rate of REFRESH_RATE
         */
        mainState = INIT;
        while (1) {
            /**
             * Tasks
             *
             * 1. Get speed input and adjust V/F profile when NOT in Soft-Start
             * 2. Perform Soft-Start for short duration
             * 3. Blink LED in relation to the motor speed
             * 4. Take current sense measurment
             *
             * Much of the CPU is spent in the modulation function, else it is taking ADC
             * measurement of the POTs. It is vital to ensure that the modulation function
             * takes LESS time to complete than the PWM period!!
             */

            switch (mainState) {
                case INIT:
                    Init();
                    MotorStop(false);
                    mainState = IDLE;
                    break;
                case IDLE:
                    if (isSW1()) {
                        // SW1 pressed
                        MotorStart(); // Motor ON
                        mainState = MOTOR_STARTING;
                    } else if (isSW2()) {
                        // SW2 pressed
                        MotorStart(); // Motor ON
                        mainState = MOTOR_STARTING;
                        //                    MotorStart(); // Motor ON
                        //                    SoftStart(); // Set Motor to 0Hz
                        //                    SoftStart(); // Set Motor to MODULATION_MIN
                        //                    SoftStart(); // Start now
                        //                    MOTOR_LED_OUT = 1;
                    }
                    break;
                case MOTOR_STARTING:
                    finished = SoftStart();
                    BlinkMotor();
                    if (finished == true) {
                        finished = false;
                        mainState = MOTOR_ON; // SoftStart has finished
                    }
                    break;
                case MOTOR_ON:
                    MeasSpeed();
                    MeasCurrentPinch();
                    BlinkMotor();
                    if (IsOverCurrent()) {
                        MotorStop(false); // Stop motor if overcurrent
                        // Blocking code
                        for (uint8_t i = 0; i != 5; i++) {
                            TRIP_LED_OUT ^= 1;
                            __delay_ms(300);
                        }
    #if(REV_NUM != 3)
                        TRIP_LED_OUT = 1;
    #else
                        TRIP_LED_OUT = 0;
    #endif
                        mainState = MOTOR_STOPPING;
                    }
                    if (isSW1()) {
                        // SW1 pressed
                        MotorStop(true);
                        mainState = MOTOR_STOPPING; // Stop the Motor
                    } else if (isSW2()) {
                        // SW2 pressed
                        MotorStop(true);
                        mainState = MOTOR_STOPPING; // Stop the Motor
                        NOP();
                    }

                    if (isAUX1()) {
                        // AUX1 input ACTIVE
                    } else if (isAUX2()) {
                        // AUX2 input ACTIVE
                    } else if (isAUX3()) {
                        // AUX3 input ACTIVE
                    } else if (isAUX4()) {
                        // AUX4 input ACTIVE
                    }
                    break;
                case MOTOR_STOPPING:
                    finished = SoftStop();
                    BlinkMotor();
                    if (finished == true) {
                        finished = false;
                        MotorStop(false); // Keep motor at 50% duty cycle (not turning - idle)
                        MOTOR_LED_OUT = 0;
                        mainState = IDLE; // SoftStop has finished
                    }
                    break;
                default:
                    break;

            }

            /**
             * Now Service any interrupts that may have occured
             *
             * @note Do not service this inside of ISR in order to preserve
             *       the sine wave accuracy
             */
            if (flags.TMR1OVF) {
                // Instead, perform this inside of ISR
                // TMR1Inc(); // Keept time
                // flags.TMR1OVF = false;
            }
            if (flags.auxSharedIOC) {
                ReadSharedAuxInputs();
                flags.auxSharedIOC = false;
            }
            if (flags.auxDedicatedIOC) {
                ReadDedicatedAuxInput();
                flags.auxDedicatedIOC = false;
            }
            if (flags.buttonsIOC) {
                ReadSharedButtons();
                flags.buttonsIOC = false;
            }
        }

    }


     
    #10
    pcbbc
    Super Member
    • Total Posts : 1507
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/24 01:39:52 (permalink)
    0
    1and0Sound like someone wants to run before he can crawl. ;)

    Unfortunately this could easily be the fault of the tutor. We don’t know the quality of the course material the student has been provided with.
     
    But from the choice of microprocessor (which has most likely been supplied/mandated by the course) we can take a wild guess that it may not be great. Certainly it hasn’t been updated in years. Not that that is necessarily a problem per se, but I wouldn’t say it’s a great sign.

    Your tutor really ought to be giving you more helpful advice as well. If you were my student at this level I would have got you to use PWM to generate your 50/60Hz signal first (instead of bit banging) so you get an understanding of the hardware. The fact that they seem to have skipped this obvious “baby step” is telling. Were the principles of PWM and the hardware even covered in the course I wonder? I also wouldn’t be recommending a project which is wholly unsuitable for the students hardware (insufficient PWM outputs).
    #11
    Mysil
    Super Member
    • Total Posts : 3642
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/24 06:04:54 (permalink)
    0
    Hi,
    With Transformer output as shown in diagram in message #1,
    H-bridge circuit is not needed.
    The existing circuit diagram may be used as it is.
     
    While it is true that PWM peripheral hardware in a microcontroller is usually used for sine wave modulation of
    voltage inverters and motor control,
    It is possible to do it all in program code in the PIC16F628:
    Instead of only one ugly long square pulse driving each transformer winding, 
    make many short pulses for one transformer winding to make a half wave. 
    Start with short pulses with longer interval, then make longer pulses on with shorter time off,
    until full on. Then reduce pulse length again until zero, for one half period 10 millisecond.
    Then same procedure for the other transformer winding, for the other half period of a sine wave, 10 milliseconds for 50 Hz output.
     
    To get better resolution on pulse length, you may use crystal oscillator 20MHz, for 5 million instructions/s.
     
        Mysil
    post edited by Mysil - 2020/01/24 06:24:20
    #12
    PStechPaul
    Super Member
    • Total Posts : 2506
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/24 12:38:27 (permalink)
    0
    Here is an illustration of how a PWM pulse train can produce a reasonable sine wave, after some filtering (which may not be needed for many AC loads):

    I am generating the PWM signal in the simulator by comparing a true sine wave signal V1 with a triangle wave V4 which has a frequency of 5 kHz. The PIC would need to use software to accomplish the same thing. However, the PIC is limited to positive voltages, so in this case the output would be shifted by 1/2 Vdd. Capacitor coupling could remove the DC component, but a better way is by using a center tap push-pull circuit or an H-bridge.

     
    #13
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/24 13:07:15 (permalink)
    0
    PStechPaul
    ...
    However, the PIC is limited to positive voltages, so in this case the output would be shifted by 1/2 Vdd. Capacitor coupling could remove the DC component, but a better way is by using a center tap push-pull circuit or an H-bridge.

    As Mysil just mentioned, the OP's circuit already has a centre-tap push pull circuit on the transformer primary.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #14
    PStechPaul
    Super Member
    • Total Posts : 2506
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/24 13:17:46 (permalink)
    0
    Your circuit:

    A push-pull output into a center tapped transformer may not give the results you want. You have to provide some dead time between turning off one driver and turning the other on. The following simulation shows a 10 kHz square wave with 2 uSec dead time, into a transformer driving a resistive load.


     
    #15
    PStechPaul
    Super Member
    • Total Posts : 2506
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: voltage inverter with pic 16f628a with ASM code 2020/01/24 13:40:03 (permalink)
    0
    Adding commutating diodes on the primary eliminates the overshoot and ringing, but for reasonable loads, the output waveform becomes a triangle wave.

     

     
    #16
    Jump to:
    © 2020 APG vNext Commercial Version 4.5