I don't understand this code!
I am trying to generate a quasi sine wave at 60 hz. The program runs but the waveform is upside down. I could change the circuit to accept the upside down wave, but I would like to know what is going on. This is my simple code:
REM DEVICE = 12F675 '12F629 CAN ALSO BE USED
REM USE INTERNAL OSCILLATOR, OUTPUT IS ON GP4 (PIN 3)
REM CONFIGURATION: INTOSC CLOCKOUT, WDT DISABLED, PWR UP ENABLED,
'MCLR = OUTPUT PIN, BROWN OUT DISABLED, NO PROTECTION
REM 60 HZ OUTPUT IS ON PINS 7 AND 6
REM OSCILLATOR CHOICE: USE 101, INTOSC, CLKOUT
OPTION_REG.5 = 0 'OTHERWISE GPIO.2 IS AN INPUT
TRISIO = %111111 'SETS ALL PORTS TO OUTPUT
ANSEL = 0 'SETS ALL DIGITAL MODE
DEFINE OSCCAL_1K 1 'FOR OSCILLATOR CALIBRATION, DON'T KNOW HOW IT WORKS
HIGH GPIO.0 'INITIAL CONDITIONS
HIGH GPIO.1
START:
LOW GPIO.1
PAUSEUS 4168 ' ON TIME
HIGH GPIO.1
PAUSEUS 4167 'DEAD TIME
LOW GPIO.0 'SETS PIN 7 LOW
PAUSEus 4168 'FOR 4.168 MILLISECONDS
HIGH GPIO.0
PAUSEUS 4167 'DEAD TIME
GOTO START '60 HZ FREQUENCY
END
If I change all highs to lows and all lows to high in the loop, I get the idenical same hex code. I would expect that
high gpio.0
highgpio.1
start:
low gpio.1
would give a different hex code than
high gpio.0
high gpio.1
start:
high gpio.1
Russ
I vote to re-order the code.
Hi Russ,
The waveform and any talk about HIGH / LOW is assumed to be in reference to the (ground / common / Vss) of the PIC. Your LEDs are “referenced” to the plus “rail” of the supply. That would make the LED output appear to be (upside down / negative logic). You could rewire the LEDs or re-order the code.
By the way, it is very interesting to put both LEDs on the single 1k resistor. Causing the voltage to vary differently when one, two or none of the LEDs are on! Getting, the same reading on a true RMS and a cheap 0.7 of peak meter is not an easy task! Where do you measure the voltage?
I vote to re-order the code.:)
-Adam-
your second (inverse) code
Hi Russ,
I think with your original pins (GPIO.0 and GPIO.1), and your second (inverse) code:
LOW GPIO.0 'INITIAL CONDITIONS
LOW GPIO.1
START:
HIGH GPIO.1
PAUSEUS 4168 ' HIGH TIME
LOW GPIO.1
PAUSEUS 4167 'DEAD TIME, BOTH LOW
HIGH GPIO.0 'SETS PIN 7 HIGH
PAUSEus 4168 'FOR 4.168 MILLISECONDS
LOW GPIO.0
PAUSEUS 4167 'DEAD TIME
GOTO START '60 HZ FREQUENCY
END
...and your diodes reversed and the resistor tied to ground (as skimask said).
Your two LEDs will not be on at the same time... (try it)
I still would like to know between which points are you measuring the wave (voltage) from?:)
-Adam-