PDA

View Full Version : "Function Generator" Triangular Wave disturb



precision
- 2nd June 2008, 12:58
Every Triangular pulse is disturb.




' chip - PIC18F4620

@ __CONFIG _CONFIG1H, _OSC_HSPLL_1H

@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_ON_3H

DEFINE OSC 40
INCLUDE "modedefs.bas"
include "My_EasyPIC4_LCD.bas"


DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 2

ADCON0 = %00001111
ADCON1 = %00001011


B0 VAR WORD
B1 VAR WORD
B2 VAR WORD
B3 VAR WORD
B4 VAR WORD
B5 VAR WORD
B6 VAR WORD

C0 VAR BYTE
C1 VAR BYTE


PAUSE 1000

LCDOUT $FE,1
PAUSE 1000
TRISB=$00


TRISD=%11110000 'Bits-4,5,6,7 Inputs, & Bits-3,2,1,0 Outputs of PORTD


Keyscane:
LCDOUT $FE, 1
LCDOUT "Scanning"

IF PORTD.4 = 1 THEN SquareWave
IF PORTD.5 = 1 THEN TriangularWave
IF PORTD.5 = 1 THEN SineWave

GOTO Keyscane



SineWave: IF PORTD.5 = 1 THEN SineWave 'Wait for release button

TRISD=$00 'Make PortD an Output Port
LCDOUT $FE, 1
LCDOUT "Sine-Wave"
pause 200



C0=0 'Initialize the Sine Angle
Init_Sine: TRISD=$00 'PortD an Output Port

PORTD=((((SIN C0)+127)/10)*5)+50 '(+127) Removes the Negative Values
'Ampitude (Peak Value) = 1/2 of 5/10
'of the Maximum Output Voltage
'50 Represents the DC Offset
'DC Offset = 1/2 of 50/255
'of the Maximum Output Voltage
'The DC Offset is Measured between Zero
'and the Negative Peak of the Sinewave.
'To Obtain the Maximum Value, Change
'Both the 5 and the 10 to a 1.

pauseus 1 'Pause Allowed between Angle Changes
'This will create, approximately, 100 Hz
C0=C0+1 'Increments the Sine Angle by 1 out of 255

GOTO Init_Sine


SquareWave: IF PORTD.4 = 1 THEN SquareWave
TRISD=$00
LCDOUT $FE, 1
LCDOUT "Square-Wave"
PAUSE 200





Init_Square: TRISD=$00 'PortD an Output Port
PORTD=0 'Square-Wave at PortD
'Starting with Decimal 0 out of 255
'of the Maximum Output Voltage.

PAUSEUS 2 'The Smallest PAUSE Allowed is 5 micro-seconds.




'approximately 46KHz.
PORTD=255
PAUSEUS 2

GOTO Init_Square

TriangularWave: IF PORTD.5 = 1 THEN TriangularWave
TRISD=$00
LCDOUT $FE, 1
LCDOUT "Triangle-Wave"
PAUSE 500





Init_Triangluar: TRISD=$00 'PortD an Output Port
PORTD=0 'Triangle-Wave at PortD
'Starting with Decimal 0 out of 255
'of the Maximum Output Voltage.

PAUSE 1 'The Smallest PAUSE Allowed is 1 micro-second.
'10 micro-seconds, in 1 micro-second steps,



'approximately, 40KHz.
PORTD=25
PAUSEUS 1
PORTD=50
PAUSEUS 1
PORTD=75
PAUSEUS 1
PORTD=100
PAUSEUS 1
PORTD=125
PAUSEUS 1
PORTD=150
PAUSEUS 1
PORTD=175
PAUSEUS 1
PORTD=200
PAUSEUS 1
PORTD=225
PAUSEUS 1
PORTD=255
PAUSEUS 1
PORTD=225
PAUSEUS 1
PORTD=200
PAUSEUS 1
PORTD=175
PAUSEUS 1
PORTD=150
PAUSEUS 1
PORTD=125
PAUSEUS 1
PORTD=100
PAUSEUS 1
PORTD=75
PAUSEUS 1
PORTD=50
PAUSEUS 1
PORTD=25

GOTO Init_Triangluar

END



.

Acetronics2
- 2nd June 2008, 13:14
Hi,

RTFM ...

What is the minimum PASEUS lenght vs frequency ???

Answer is in the Manual ...

Alain

PS ... may be some asm lines to include ... but it's me !!!

Bruce
- 2nd June 2008, 15:03
PAUSEUS 1 should be fine for 1uS running at 40MHz.

skimask
- 2nd June 2008, 16:04
PAUSEUS 1 should be fine for 1uS running at 40MHz.

Book says 2us minimum above 25Mhz on an 18F.

Bruce
- 2nd June 2008, 16:20
Latest PBP manual. Page #113 states 40, 48, 64MHz OSC, "PIC18Xxxxx only" is 1uS.
25, 32, 33MHz is 2uS.

precision
- 2nd June 2008, 16:43
Hi
Thanks sir Bruce.

I am in fault.
i wrote Pause 1 instead of PAUSEUS 1 after "Init_Triangluar:"

Thanks skimask and Acetronics.
I was reading manual. and sir bruce solved .......

There are no enough mind after bonding of straingage on 50 torque sensor in a day ....
Oh...

Thanks again, its working.

Acetronics2
- 2nd June 2008, 16:49
a little spike here,may be ?



PORTD=200
PAUSEUS 1
PORTD=225
PAUSEUS 1
PORTD=255 ... should not be 250 ???
PAUSEUS 1
PORTD=225
PAUSEUS 1
PORTD=200



did you try :



Init_Triangluar: TRISD=$00 'PortD an Output Port
PORTD=0 'Triangle-Wave at PortD
'Starting with Decimal 0 out of 255
'of the Maximum Output Voltage.

PAUSEUS1 'instead of PAUSE 1
'10 micro-seconds, in



PS : didn't notice the 40Mhz Define ... sorry !

precision
- 2nd June 2008, 17:15
Yes Acetronics, Overall Shape is distressed ( in ladder ways ). I thought there is problem in D/A converter or in OP Amp OP07 ?

circuit attached.

Thanks

Acetronics2
- 2nd June 2008, 17:27
Do you have a symmetrical AND > 7 v supply for the OP07 ???

might be compulsory ...

or try a rail/rail AOP ...

Alain

skimask
- 2nd June 2008, 17:38
Latest PBP manual. Page #113 states 40, 48, 64MHz OSC, "PIC18Xxxxx only" is 1uS.
25, 32, 33MHz is 2uS.

Good point! Another update/change I hadn't noticed