Continue to Site

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.

  • 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.

Changing 50hz to 60hz on an existing code w/ 16f628a

Status
Not open for further replies.

solarvolt

New Member
Being my first post here, I'll say that my experience in electronics is quite lengthy, however, my coding experience is so old, that I doubt it will help much (Fortran days). I picked up a diagram that I've attached, and the hex code that was given for a 50hz signal. What would be the best way for me to start figuring this out. Basically I have no idea where to start.

Any directions you could give will be more than appreciated!
 

Attachments

  • SVP-Power Inverter - Driver Stage.jpg
    SVP-Power Inverter - Driver Stage.jpg
    76.4 KB · Views: 1,857
  • FYUZEM6HAQ35NKG.hex
    2.6 KB · Views: 655
The easiest way would be to use a 24MHz crystal - a little overclocked though. However, feeding 24V into a 12V winding doesn't seem like a good idea. I also don't see how you get a pure sine wave using a pic like that!

Mike.
 
Do you really need 24mc's to get a sine output.
With a simple filter on the o/p of the pic you ought to be able to get a nice clean sine esp at 50 cycles.
pomms has a point, your schem would give 440v, I think you mean a 48v transformer, ie 24-0-24, as when you swing a tranny either side of the centre tap like your doing you effectively double the ingoing voltage.
They tried to teach me fortran at school, but I was more interested in listening to heavy metal.
 
You don't need 24MHz to get a sign wave but to use 50Hz code at 60Hz you need to clock the pic faster - changing the crystal does this without even knowing what the code does. To switch two digital pins to produce a pure sine wave is quite tricky and the hex file seems too small for that. I wouldn't be surprised if the pic just outputs two anti-phase square waves.

Mike.
 
I wouldn't be surprised if the pic just outputs two anti-phase square waves.
That' what the scope showed

Here the code
Code:
;-----------------------------------
;PIC DISASSEMBLER LISTING
;Label  Instruction
;-----------------------------------
	GOTO L1
	ADDLW 0xFF
	ADDLW 0xFF
	ADDLW 0xFF
L9:	MOVLW 0x00
	BCF STATUS,RP1
	BCF STATUS,RP0
	BTFSC CMCON,C2OUT
	MOVLW 0x01
	MOVWF 0x071
	MOVF 0x071,W
	XORLW 0x01
	BTFSS STATUS,Z
	GOTO L2
	MOVLW 0x01
	MOVWF 0x020
	BCF PORTA,3
	GOTO L3
L2:	BSF PORTA,3
L3:	RETURN
L13:	BCF STATUS,RP1
	BCF STATUS,RP0
	CLRF 0x021
	CLRF 0x022
L6:	MOVF 0x02F,W
	SUBWF 0x022,W
	BTFSS STATUS,Z
	GOTO L4
	MOVF 0x02E,W
	SUBWF 0x021,W
L4:	BTFSC STATUS,C
	GOTO L5
	INCF 0x021,F
	BTFSC STATUS,Z
	INCF 0x022,F
	GOTO L6
L5:	RETURN
	RETLW 0x35
	RETLW 0x00
	RETLW 0x3B
	RETLW 0x00
	RETLW 0x2F
	RETLW 0x00
	RETLW 0x41
	RETLW 0x00
	RETLW 0x2A
	RETLW 0x00
	RETLW 0x46
	RETLW 0x00
	RETLW 0x24
	RETLW 0x00
	RETLW 0x4C
	RETLW 0x00
	RETLW 0x1F
	RETLW 0x00
	RETLW 0x51
	RETLW 0x00
	RETLW 0x1A
	RETLW 0x00
	RETLW 0x56
	RETLW 0x00
	RETLW 0x15
	RETLW 0x00
	RETLW 0x5B
	RETLW 0x00
	RETLW 0x11
	RETLW 0x00
	RETLW 0x5F
	RETLW 0x00
	RETLW 0x0D
	RETLW 0x00
	RETLW 0x62
	RETLW 0x00
	RETLW 0x09
	RETLW 0x00
	RETLW 0x66
	RETLW 0x00
	RETLW 0x06
	RETLW 0x00
	RETLW 0x68
	RETLW 0x00
	RETLW 0x04
	RETLW 0x00
	RETLW 0x6B
	RETLW 0x00
	RETLW 0x02
	RETLW 0x00
	RETLW 0x6C
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6D
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6E
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6E
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6D
	RETLW 0x00
	RETLW 0x01
	RETLW 0x00
	RETLW 0x6C
	RETLW 0x00
	RETLW 0x03
	RETLW 0x00
	RETLW 0x6A
	RETLW 0x00
	RETLW 0x05
	RETLW 0x00
	RETLW 0x67
	RETLW 0x00
	RETLW 0x08
	RETLW 0x00
	RETLW 0x64
	RETLW 0x00
	RETLW 0x0B
	RETLW 0x00
	RETLW 0x61
	RETLW 0x00
	RETLW 0x0F
	RETLW 0x00
	RETLW 0x5D
	RETLW 0x00
	RETLW 0x13
	RETLW 0x00
	RETLW 0x58
	RETLW 0x00
	RETLW 0x17
	RETLW 0x00
	RETLW 0x53
	RETLW 0x00
	RETLW 0x1C
	RETLW 0x00
	RETLW 0x4E
	RETLW 0x00
	RETLW 0x22
	RETLW 0x00
	RETLW 0x49
	RETLW 0x00
	RETLW 0x27
	RETLW 0x00
	RETLW 0x44
	RETLW 0x00
	RETLW 0x2D
	RETLW 0x00
	RETLW 0x3E
	RETLW 0x00
	RETLW 0x32
	RETLW 0x00
	RETLW 0x38
	RETLW 0x00
	RETLW 0x38
	RETLW 0x00
	RETLW 0x32
	RETLW 0x00
	RETLW 0x3E
	RETLW 0x00
	RETLW 0x2D
	RETLW 0x00
	RETLW 0x44
	RETLW 0x00
	RETLW 0x27
	RETLW 0x00
	RETLW 0x49
	RETLW 0x00
	RETLW 0x22
	RETLW 0x00
	RETLW 0x4E
	RETLW 0x00
	RETLW 0x1C
	RETLW 0x00
	RETLW 0x53
	RETLW 0x00
	RETLW 0x17
	RETLW 0x00
	RETLW 0x58
	RETLW 0x00
	RETLW 0x13
	RETLW 0x00
	RETLW 0x5D
	RETLW 0x00
	RETLW 0x0F
	RETLW 0x00
	RETLW 0x61
	RETLW 0x00
	RETLW 0x0B
	RETLW 0x00
	RETLW 0x64
	RETLW 0x00
	RETLW 0x08
	RETLW 0x00
	RETLW 0x67
	RETLW 0x00
	RETLW 0x05
	RETLW 0x00
	RETLW 0x6A
	RETLW 0x00
	RETLW 0x03
	RETLW 0x00
	RETLW 0x6C
	RETLW 0x00
	RETLW 0x01
	RETLW 0x00
	RETLW 0x6D
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6E
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6E
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6D
	RETLW 0x00
	RETLW 0x00
	RETLW 0x00
	RETLW 0x6C
	RETLW 0x00
	RETLW 0x02
	RETLW 0x00
	RETLW 0x6B
	RETLW 0x00
	RETLW 0x04
	RETLW 0x00
	RETLW 0x68
	RETLW 0x00
	RETLW 0x06
	RETLW 0x00
	RETLW 0x66
	RETLW 0x00
	RETLW 0x09
	RETLW 0x00
	RETLW 0x62
	RETLW 0x00
	RETLW 0x0D
	RETLW 0x00
	RETLW 0x5F
	RETLW 0x00
	RETLW 0x11
	RETLW 0x00
	RETLW 0x5B
	RETLW 0x00
	RETLW 0x15
	RETLW 0x00
	RETLW 0x56
	RETLW 0x00
	RETLW 0x1A
	RETLW 0x00
	RETLW 0x51
	RETLW 0x00
	RETLW 0x1F
	RETLW 0x00
	RETLW 0x4C
	RETLW 0x00
	RETLW 0x24
	RETLW 0x00
	RETLW 0x46
	RETLW 0x00
	RETLW 0x2A
	RETLW 0x00
	RETLW 0x41
	RETLW 0x00
	RETLW 0x2F
	RETLW 0x00
	RETLW 0x3B
	RETLW 0x00
	RETLW 0x35
	RETLW 0x00
	RETURN
L12:	BCF STATUS,RP1
	BCF STATUS,RP0
	MOVF 0x024,W
	MOVWF PCLATH
	MOVF 0x025,W
	MOVWF PCL
	RETURN
L19:	BCF INTCON,GIE
	MOVLW 0x03
	BCF STATUS,RP1
	BSF STATUS,RP0
	MOVWF PORTB
	BCF STATUS,RP0
	CLRF PORTB
	BCF CMCON,C2INV
	BSF CMCON,CIS
	BCF CMCON,CM2
	BSF CMCON,CM1
	BCF CMCON,CM0
	MOVLW 0xE4
	BSF STATUS,RP0
	MOVWF PORTA
	BCF STATUS,RP0
	BSF PORTA,3
	BSF STATUS,RP0
	BSF CMCON,C2OUT
	BCF CMCON,C1OUT
	BCF CMCON,C2INV
	BSF CMCON,CIS
	BCF CMCON,CM2
	BCF CMCON,CM1
	BSF CMCON,CM0
	RETURN
L20:	BCF STATUS,RP1
	BCF STATUS,RP0
	CLRF 0x020
	MOVLW 0x1E
	MOVWF 0x026
	MOVLW 0x00
	MOVWF 0x027
	CLRF 0x028
	CLRF 0x029
	CLRF 0x02A
	RETURN
L21:	BCF STATUS,RP1
	BCF STATUS,RP0
	CLRF 0x02B
L17:	MOVLW 0x00
	XORWF 0x027,W
	BTFSS STATUS,Z
	GOTO L7
	MOVF 0x026,W
	XORWF 0x02B,W
L7:	BTFSS STATUS,Z
	GOTO L8
	CALL L9
L8:	BSF PORTB,6
	BCF PORTB,5
	MOVLW 0x01
	MOVWF 0x074
	MOVF 0x02B,W
	MOVWF 0x070
	CLRF 0x071
	MOVF 0x074,W
L11:	BTFSC STATUS,Z
	GOTO L10
	RLF 0x070,F
	RLF 0x071,F
	BCF 0x070,0
	ADDLW 0xFF
	GOTO L11
L10:	MOVLW 0x25
	ADDWF 0x070,F
	MOVLW 0x00
	BTFSC STATUS,C
	ADDLW 0x01
	ADDWF 0x071,F
	MOVF 0x070,W
	MOVWF 0x025
	MOVF 0x071,W
	MOVWF 0x024
	MOVF PCLATH,W
	MOVWF 0x023
	CALL L12
	MOVWF 0x02E
	MOVF 0x023,W
	MOVWF PCLATH
	INCF 0x025,F
	BTFSC STATUS,Z
	INCF 0x024,F
	CALL L12
	MOVWF 0x02F
	MOVF 0x023,W
	MOVWF PCLATH
	CALL L13
	INCF 0x02B,F
	BCF PORTB,6
	BSF PORTB,5
	MOVLW 0x01
	MOVWF 0x074
	MOVF 0x02B,W
	MOVWF 0x070
	CLRF 0x071
	MOVF 0x074,W
L15:	BTFSC STATUS,Z
	GOTO L14
	RLF 0x070,F
	RLF 0x071,F
	BCF 0x070,0
	ADDLW 0xFF
	GOTO L15
L14:	MOVLW 0x25
	ADDWF 0x070,F
	MOVLW 0x00
	BTFSC STATUS,C
	ADDLW 0x01
	ADDWF 0x071,F
	MOVF 0x070,W
	MOVWF 0x025
	MOVF 0x071,W
	MOVWF 0x024
	MOVF PCLATH,W
	MOVWF 0x023
	CALL L12
	MOVWF 0x02E
	MOVF 0x023,W
	MOVWF PCLATH
	INCF 0x025,F
	BTFSC STATUS,Z
	INCF 0x024,F
	CALL L12
	MOVWF 0x02F
	MOVF 0x023,W
	MOVWF PCLATH
	CALL L13
	INCF 0x02B,F
	MOVF 0x02D,W
	SUBLW 0x00
	BTFSS STATUS,Z
	GOTO L16
	MOVF 0x02C,W
	SUBWF 0x02B,W
L16:	BTFSS STATUS,C
	GOTO L17
	RETURN
L18:	MOVLW 0x78
	BCF STATUS,RP1
	BCF STATUS,RP0
	MOVWF 0x02C
	MOVLW 0x00
	MOVWF 0x02D
	RETURN
L1:	CALL L18
	CALL L19
	CALL L20
L27:	CALL L21
	INCF 0x029,F
	BTFSC STATUS,Z
	INCF 0x02A,F
	MOVLW 0x00
	XORWF 0x02A,W
	BTFSS STATUS,Z
	GOTO L22
	MOVLW 0x32
	XORWF 0x029,W
L22:	BTFSS STATUS,Z
	GOTO L23
	CLRF 0x029
	CLRF 0x02A
	GOTO L24
L25:	MOVLW 0x01
	MOVWF 0x028
	BSF PORTB,7
	GOTO L23
L26:	CLRF 0x028
	BCF PORTB,7
	GOTO L23
L24:	MOVF 0x028,W
	XORLW 0x00
	BTFSC STATUS,Z
	GOTO L25
	MOVF 0x028,W
	XORLW 0x01
	BTFSC STATUS,Z
	GOTO L26
L23:	GOTO L27
L28:	GOTO L28
	ADDLW 0xFF
	ADDLW 0xFF
	ADDLW 0xFF
	ADDLW 0xFF
	ADDLW 0xFF
	ADDLW 0xFF
	ADDLW 0xFF
 
Well Dr P...you didn't miss anything & I was into (and still am) into metal tunes. Actually, what I plan on doing is winding my own tranny. A 18-0-18 with a 120-0-120 secondary @ 1kva. I thought I might check with some of you to see what
your opinion would be on this guy's design. It looked interesting though, and with a nice and cheap chip. I actually had thought of putting a slightly higher rated crystal in, but this guy said the crystal didn't have anything to do with the current signal. That
in of itself got me to wonder about his design. I'll put this together and let you all know what happens. We're looking at building our own brand of power inverters, and I'm out doing a little fishing.

Thanks!
 
Someones mixed up, the crystal controls the rate at which the program runs, and is critical to the o/p freq, as pomms says changing the xtal by a % changes the o/p freq by the same %.

If its moddified sine wave (all those retlw's in the code would suggest that its either pwm or r2r), or should I say crude square wave you'll have issues with start up current, you'll probably need some sort of soft start to keep startup current down, unless its a fancy tranny.
 
We're looking at building our own brand of power inverters, and I'm out doing a little fishing.

Gads, that's scary... You're thinking about borrowing someone else's design without knowing anything about it and using it in your commercial product?
 
It's not a sine wave. And I seen it before I posted one something like that it's some where on here
 
no....no....no Not by a long shot. I'm only picking up on ideas. I'm actually an electro-mechanical design engineer, with roughly 40 years under my belt. As always....one thing I hate doing is re-inventing the wheel, but it's always
good to see what's out there first. Right now, I'm looking at low cost but good quality MCU's and other components to come up with a design that's relatively easy, while maintaining the quality. BTW, I designed our brand solar modules
from the ground up, and we warranty for life. They put out 95% of new wattage after simulating 175 years if use. Thanks for your concern though!
 
Last edited:
Maybe its an approximation of a sine or something.

I've never attempted anyhting like this, cheap chinese imports make it unrealistic.
 
Hi be80be

Is that 60Hz code for Nick inverter?
If I am correct PIC is chopping sine into PWM pulses.
I though of using 24mhz crystal, but it is to fast for PIC 20Mhz max.
Can I use 16HV540 for it supply voltage 3-15v and drive single mosfet per side of transformer for 300W.
 
Last edited:
zvizdic,

Yes.....that is the code from Nick's post. I went ahead and tried the 24mhz crystal, and it seemed to work fine. The wave is really pretty smooth for a fax pwm, and comes in at just under 60hz. I just have not posted this either on this forum or on Nick's Inscrutable yet. I am working on the hex file, and should have something soon, as I wouldn't put a lot of weight on using the circuit as is. There is a fellow named Tim Nolan that put together a nice set up, using an Atmel MCU....one of the AT90PWM's and a ATTiny-45. Just put his name in a search and add the words grid connect. He's got all the code there, and they look very good.
 
Output circuit is a bit odd. NPN transistors Q1 and Q2 have their collectors directly connected to the 12 volt output from U1, but their bases are driven directly from the PIC output so the emitters can never be at a voltage higher than Vdd-Vbe.

Unless I'm missing something the 12 volt supply serves no purpose, the collectors of Q1 and Q2 may as well connect to the 5 volt output of U2 :confused:
 
Yep, and the TIP122 are a darlington i think so the output stage is a "trilington" with emitter at ground, so the PIC output would have plenty of voltage and current to directly drive the output trilingtons.

R3 and R6 have to need at all to be 100 ohms to drive trilingtons! It looks like someone has adapted from another circuit and not known how it works.
 
Status
Not open for further replies.

Latest threads

Back
Top