"Function Generator" Triangular Wave disturb


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89

    Default "Function Generator" Triangular Wave disturb

    Every Triangular pulse is disturb.

    Code:
    ' 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
    .

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    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 !!!
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    PAUSEUS 1 should be fine for 1uS running at 40MHz.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    PAUSEUS 1 should be fine for 1uS running at 40MHz.
    Book says 2us minimum above 25Mhz on an 18F.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Latest PBP manual. Page #113 states 40, 48, 64MHz OSC, "PIC18Xxxxx only" is 1uS.
    25, 32, 33MHz is 2uS.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Smile

    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.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    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 :

    Code:
    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 !
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    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
    Attached Images Attached Images  

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Lightbulb

    Do you have a symmetrical AND > 7 v supply for the OP07 ???

    might be compulsory ...

    or try a rail/rail AOP ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    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

Similar Threads

  1. how to generate triangular wave.....
    By kvrajasekar in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th September 2008, 18:16

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts