Sonic Depth Meter code & Math problems 12F683


Results 1 to 14 of 14

Threaded View

  1. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Sonic Depth Meter code & Math problems 12F683

    Quote Originally Posted by johnnylynx View Post
    So, I need to convert the 92 and 364 to 1% or 100% respectively and apply to 127 to get a new tap setting.

    John
    You can do this with a simple lookdown2 table, but there is 1 gotcha, in order to have more than 85 values you need to use an 18F series pic
    here is the table you basically need.
    Code:
    lookdown2 temp,<[9200,9414 ,9628 ,9842 ,10056,10270,10484,10698,10912,11126,11340,11554,11768,11982,12196,12410,_
                    12624,12838,13052,13266,13480,13694,13908,14122,14336,14550,14764,14978,15192,15406,15620,15834,_
                    16048,16262,16476,16690,16904,17118,17332,17546,17760,17974,18188,18402,18616,18830,19044,19258,_
                    19472,19686,19900,20114,20328,20542,20756,20970,21184,21398,21612,21826,22040,22254,22468,22682,_
                    22896,23110,23324,23538,23752,23966,24180,24394,24608,24822,25036,25250,25464,25678,25892,26106,_
                    26320,26534,26748,26962,27176,27390,27604,27818,28032,28246,28460,28674,28888,29102,29316,_
                    29530,29744,29958,30172,30386,30600,30814,31028,31242,31456,31670,31884,32098,32312,32526,32740,_
                    32954,33168,33382,33596,33810,34024,34238,34452,34666,34880,35094,35308,35522,35736,35950,36164,_
                    36378,36592],b
    Put it in an 18F and it will count to 127 in a 16F it will count to 85
    in fact here is my whole code written for a 16F690 demo board and a PICKIT2 using it's uart window to watch it count
    Code:
    @MyConfig = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON  
    @MyConfig = MyConfig & _MCLRE_OFF & _BOR_OFF & _FCMEN_OFF & _IESO_OFF 
    @ __config  MyConfig 
    
    DEFINE OSC 4
    DEFINE DEBUG_MODE  0    ' Debug sending True serial data
    DEFINE DEBUG_REG_PORTA  ' Debug Port = PortA as required by PICKIT2 USART Monitor
    DEFINE DEBUG_BIT 0      ' Debug.bit = PortA.0
    DEFINE DEBUG_BAUD 9600  ' Default baud rate = 9600
    DEFINE DEBUGIN_REG PORTA' Debug Port = PortA as required by PICKIT2 USART Monitor 
    DEFINE DEBUGIN_BIT 1    ' Debugin bit PortA.1
    DEFINE DEBUGIN_BAUD 9600' Default baud rate = 9600
    DEFINE DEBUGIN_MODE 0   ' Debugin receiving data true = 0 inverted = 1
    DEFINE NO_CLRWDT 1
    ;INDF             
    ;TMR0             
    ;PCL              
    ;STATUS           
    ;FSR              
    ;PORTA = %00000000           
    ;PORTB = 0 
    ;PORTC = %00000000          
    ;PCLATH           
    ;INTCON           
    ;PIR1             
    ;PIR2             
    ;TMR1L            
    ;TMR1H            
    ;T1CON            
    ;TMR2             
    ;T2CON            
    ;SSPBUF           
    ;SSPCON           
    ;CCPR1L           
    ;CCPR1H           
    ;CCP1CON = %10001100 ;Dual PWM 10xx11xx P1A/RC5 P1B/RC4 RC3/AN7 RC2/AN6
             
    ;RCSTA            
    ;TXREG            
    ;RCREG            
    ;PWM1CON ;PROGRAMMABLE DEAD BAND DELAY
    ;PSTRCON = %00000011         
    ;ECCPAS           
    ;ADRESH           
    ADCON0 = 0 ; analog 1 dig 0          
    
    ;-----Bank1------------------
    
    
    ;OPTION_REG = %00000000  ;RABPU,INTEDG,T0CS,T0SE,PSA,PS,PS,PS
    ;bit 7 RABPU: PORTA/PORTB Pull-up Enable bit
    ;1 = PORTA/PORTB pull-ups are disabled
    ;0 = PORTA/PORTB pull-ups are enabled by individual port latch values 
    ;JoeNote: may lock up cpu if all ports set as outputs and WPU are enabled  by experience!
    ;bit 6 INTEDG: Interrupt Edge Select bit
    ;1 = Interrupt on rising edge of RA2/AN2/T0CKI/INT/C1OUT pin
    ;0 = Interrupt on falling edge of RA2/AN2/T0CKI/INT/C1OUT pin
    ;bit 5 T0CS: TMR0 Clock Source Select bit
    ;1 = Transition on RA2/AN2/T0CKI/INT/C1OUT pin
    ;0 = Internal instruction cycle clock (CLKOUT)
    ;bit 4 T0SE: TMR0 Source Edge Select bit
    ;1 = Increment on high-to-low transition on RA2/AN2/T0CKI/INT/C1OUT pin
    ;0 = Increment on low-to-high transition on RA2/AN2/T0CKI/INT/C1OUT pin
    ;bit 3 PSA: Prescaler Assignment bit
    ;1 = Prescaler is assigned to the WDT
    ;0 = Prescaler is assigned to the Timer0 module
    ;bit 2-0 PS<2:0>: Prescaler Rate Select bits      
    
    ;bits  TMR0     WDT
    ;2:0  Rate      Rate
    ;000  1 : 2     1 : 1
    ;001  1 : 4     1 : 2
    ;010  1 : 8     1 : 4
    ;011  1 : 16    1 : 8
    ;100  1 : 32    1 : 16
    ;101  1 : 64    1 : 32
    ;110  1 : 128   1 : 64
    ;111  1 : 256   1 : 128 
    
    TRISA = %00000000           
    TRISB = %00000000           
    TrisC = %00000000          
    ;PIE1  :peripheral interrupt enable           
    ;PIE2             
    PCON  = 0 ; shut off brownout
    ; * * * * * * * * * make sure OSC DEFINE Agrees with OSCCON * * * * * * * * *           
    OSCCON = %01100000 
    ;  000 = 31kHz
    ;  001 = 125kHz
    ;  010 = 250kHz
    ;  011 = 500kHz
    ;  100 = 1MHz
    ;  101 = 2MHz
    ;  110 = 4MHz (default)
    ;  111 = 8MHz         
    ;* * * * * * * * * OSCTUNE * * * * * * * * * * * * * * * * * * * * * * * * * *
    
    OSCTUNE = 0       ; factory calibration = 0 
    
    ;bits 7:5 are unimplemented
    ;bit 4:0 TUN<4:0>: Frequency Tuning bits
    ;01111 = Maximum frequency
    ;01110 =
    ;•
    ;•
    ;•
    ;00001 =
    ;00000 = Oscillator module is running at the calibrated frequency.
    ;11111 =
    ;•
    ;•
    ;•
    ;10000 = Minimum frequency        
    
    
    
    ;PR2              
    ;MSK              
    ;SSPADD           
    ;SSPMSK           
    ;SSPSTAT          
    ;WPUB  = 0             
    ;WPUA = 2            
    ;IOC              
    ;IOCA             
    ;WDTCON           
    ;TXSTA            
    ;SPBRG            
    ;SPBRGH           
    ;BAUDCTL          
    ;ADRESL  = %00000000
    ADCON0  = %00000000          
    ADCON1  = %00000000
    
    ;EEDAT            
    ;EEDATA           
    ;EEADR            
    ;EEDATH          
    ;EEADRH          
    WPUB = 0  ; WEAK PULLUPS PORT B          
    ;IOCB   ;INTERRUPT ON CHANGE PORT B         
    ;VRCON            
    CM1CON0 = 0        
    CM2CON0 = 0     
    CM2CON1 = 0       
    ANSEL   = 0         
    ANSELH  = 0        
    
    main:
    index var word
    b var word 
    temp var word
    ;DEBUGIN [temp]
    ;index = ~~temp
        for index = 92 to 364 step 1
            temp =(index * 100)
    ;if  temp < 92 then main
    
    
    
    lookdown2 temp,<[9200,9414 ,9628 ,9842 ,10056,10270,10484,10698,10912,11126,11340,11554,11768,11982,12196,_
        12410,12624,12838,13052,13266,13480,13694,13908,14122,14336,14550,14764,14978,15192,15406,15620,_
        15834,16048,16262,16476,16690,16904,17118,17332,17546,17760,17974,18188,18402,18616,18830,19044,_
        19258,19472,19686,19900,20114,20328,20542,20756,20970,21184,21398,21612,21826,22040,22254,22468,_
        22682,22896,23110,23324,23538,23752,23966,24180,24394,24608,24822,25036,25250,25464,25678,25892,_
        26106, 26320,26534,26748,26962,27176,27390,27604,27818,28032,28246,28460,28674,28888,29102,29316,_
        29530,29744,29958,30172,30386,30600,30814,31028,31242,31456,31670,31884,32098,32312,32526,32740,_
        32954,33168,33382,33596,33810,34024,34238,34452,34666,34880,35094,35308,35522,35736,35950,36164,36378,36592],b
        
        ;debug dec b, "," 
        pause 200
    next index
    
    b = (b/100)
    debug dec b, " ,"
    
    
    
    goto main
    Ignore any line that is commented out
    Last edited by Archangel; - 31st October 2013 at 06:13.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. Replies: 0
    Last Post: - 27th March 2011, 20:10
  2. PIC 12f683 AD/PWM Problems:
    By surfer0815 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th December 2005, 16:48
  3. math problems (again)
    By lab310 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2005, 22:43
  4. 12F683 Comparator Problems
    By morethanenuf in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th September 2005, 15:36
  5. math problems - large numbers
    By Tomasm in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th February 2004, 07:48

Members who have read this thread : 0

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