can anyone help me...


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    22

    Default can anyone help me...

    Hi,

    1.I am doin UPS control operations using 16f72(assembly).I want to connect main supply to pic PORTA,this contains adc inbuilt.my confusion is how to these analog pins.to use it as digital,first should config porta as digital i/o.but to receive analog inputs can i directly use the pins without any settins.

    2.PIC operates on 5v.if i connect with 230v main is required any modifications in s/w side,I think this will be taken care by h/w.

    Plz correct me,if i m wrong.

  2. #2


    Did you find this post helpful? Yes | No

    Default Stop

    Do not try to connect directly to mains! you will instantly fry the pic, probably start a fire, and possibly kill yourself. to measure mains voltage you need to run through a transformer to lower the voltage. it also needs to be rectified. the pics inputs must be 5v max or less if running at lower voltage. and they cannot handle negative voltages. as far as using analog inputs you set it all up. you can make pins digital or analog on a per pin basis. you'll need to reference the data sheet to see which pins the adc uses, and what registers need to be set up.

  3. #3
    Join Date
    Aug 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Thanx mr.nomad,

    It is very useful,i followed ur statement and did the followin,tell me is it correct?

    movlw b'00000000' ; select PORTA,0
    movwf ADCON0
    movlw b'00000001' ;switch on ADC
    movwf ADCON0
    here btfss ADCON0,2 ;checking whether conversion is in process or not
    goto here
    movf ADRES,0
    movwf volt_val

  4. #4
    Join Date
    Aug 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    and also tell me,i need to follow the above step for all analog ports?

  5. #5


    Did you find this post helpful? Yes | No

    Default sorry

    that was about the extent of what I know about it. ( I don't know assembly either.)

    Anyone?

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kvrajasekar View Post
    ... did the followin,tell me is it correct?

    movlw b'00000000' ; select PORTA,0
    movwf ADCON0
    movlw b'00000001' ;switch on ADC
    movwf ADCON0
    here btfss ADCON0,2 ;checking whether conversion is in process or not
    goto here
    movf ADRES,0
    movwf volt_val
    Well, since it's a PicBasic forum, first I'll say that all you need to do is
    Code:
    ADCIN  0, volt_val
    Or the ASM version...
    Code:
        movlw b'10000001' ;FOSC32, AN0, ADC ON
        movwf ADCON0
        movlw   0x07      ; 21us @ 4mhz
        movwf   Delay    
    DLY1 decfsz  Delay,1  ; acquisition time
        goto DLY1    
        bsf   ADCON0, 2   ; Start an A/D conversion
    here btfss ADCON0,2   ;checking whether conversion is in process or not
        goto here
        movf ADRES,0
        movwf volt_val
    Note: The volt_val and Delay variables must be in BANK0 to work.
    DT

  7. #7
    Join Date
    Aug 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Thanks lot,
    Plz tell me, why u select FOSC32,whynot FOSC8.

    and my final ques is how to find the rising edge(tON) and Falling Edge(tOFF).I used the following code to find this,
    This is a digital i/p,
    go_vol1
    btfss PORTB,0 ;checking whether porta pin is set or not
    goto go_vol1 ;waiting
    clrf TMR0
    Duty_vol1
    btfsc PORTB,0 ;keep monitoring rising edge
    goto Duty_vol1
    movf TMR0,0
    movwf volt_val

    Plz give me ur suggestion to use this code,If it is correct my work will get finish.

    And also i m using LCD interface.wat should be the minimum delay b/w the commands to LCD.

    -thanks.
    Last edited by kvrajasekar; - 26th August 2008 at 07:35.

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by kvrajasekar View Post
    Hi Darrel,

    Thanks lot,
    Plz tell me, why u select FOSC32,whynot FOSC8.
    I chose FOSC32 because I didn't know what crystal you were using.
    If you had a 20mhz crystal FOSC8 would probably not work.
    But even with a 4mhz crystal, FOSC32 will still work fine.

    and my final ques is how to find the rising edge(tON) and Falling Edge(tOFF).I used the following code to find this,
    This is a digital i/p,
    go_vol1
    btfss PORTB,0 ;checking whether porta pin is set or not
    goto go_vol1 ;waiting
    clrf TMR0
    Duty_vol1
    btfsc PORTB,0 ;keep monitoring rising edge
    goto Duty_vol1
    movf TMR0,0
    movwf volt_val

    Plz give me ur suggestion to use this code,If it is correct my work will get finish.
    The code shown will wait for a rising edge, then measure the duration of the high pulse. if you add the same thing again for the low pulse, you'll have both values.
    Code:
    go_vol1
    		btfss 	PORTB,0   ; Wait for rising edge 
    		goto 	go_vol1
    		clrf	TMR0      ; clear TMR0 for high pulse
    Duty_vol1
    		btfsc	PORTB,0	  ; keep monitoring high pulse
    		goto	Duty_vol1
    		movf	TMR0,0    ; put TMR0 value in W reg
    		clrf    TMR0      ; clear TMR0 for low pulse
    		movwf	tON       ; save timer value to variable
    
    Duty_vol2
    		btfss	PORTB,0	  ; keep monitoring low pulse
    		goto	Duty_vol2
    		movf	TMR0,0    ; put TMR0 value in W reg
    		movwf	tOFF      ; save timer value to variable
    > And also i m using LCD interface.wat should be the minimum delay b/w the commands to LCD.

    It varies from display to display. I think the average is around 1.6ms, but some are as high as 2.5ms for commands. 2.0ms is standard with 50us DATA delay.

    hth,
    DT

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