can anyone help me...


Closed Thread
Results 1 to 16 of 16
  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

  9. #9
    Join Date
    Aug 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Thanks lot Darrel,I m very happy to see ur reply.

    can i use the same codings for zerocrossing?bcoz zero crossing will occur every rising or falling edge.plz correct me if i am wrong?

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


    Did you find this post helpful? Yes | No

    Default

    No I'm sorry, but you said the last one was your "Final Question".

    Ok, 1 more.

    If you're waiting for a zero-cross, then you probably don't need to time the event with TMR0.
    Code:
    Wait4ZeroCross                    ; Wait for zero-cross, up or down
        btfss   PORTB,0
        goto    WaitForHigh
    WaitForLow
        btfsc   PORTB,0
        goto    WaitForLow
        goto    ZeroCrossDone
    WaitForHigh
        btfss   PORTB,0
        goto    WaitForHigh
    ZeroCrossDone
    DT

  11. #11
    Join Date
    Aug 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Thank you very much Mr.Darrel.

  12. #12
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Use DT's Instant Interrupt for detecting Zero Cross.

    In a UPS (Offline I suppose) control your primary task would be to monitor mains for abnormality which includes under/over voltage, blackout/brownout. I suggest sampling the mains voltage at 0.5ms intervals. Also a premature zero-cross is a definite indication of mains failure. While I use PORTB.0 INT for the zero cross in asm you may use Instant Interrupt to make your life easier.

    http://www.picbasic.co.uk/forum/showthread.php?t=3251
    Regards

    Sougata

  13. #13
    Join Date
    Aug 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Hi sougata,

    I m using power failure indication for UPS,wen it detects,i should start the inverter,also wen power resumption occur i should turn off the inverter and start with main.

    How can acheive this task,plz give ur ideas to implement,I m using PIC16f72.

    I am waiting for ur reply.

  14. #14
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Try solving one after another

    Hi,

    It has happened in the past that I have committed to help on some specific issues offline of the forum but could not actually keep up to my commitments. So rather than showing you specific pointers it would be better if you cross each hurdle - one at a time. This would ensure that other forum members take interest try to solve your problems. Cause being a one man army I hardly get time to log onto the forum [I visit mostly when I am in trouble - I know sounds selfish ]

    For your project :

    While in mains -->
    Monitor Zero Cross for abnormal timings
    Monitor Mains Voltage (through Sense Transformer)

    To achieve fastest transfer start sampling the mains voltage from the zero cross and validate against a lookup table to be within range every 0.5ms. Your ADC pin should see the mains voltage as a 100Hz fully rectified DC waveform. In a blind sampling can detect zero-crosses within 0.5mS accuracy. With a clock of 20MHz shouldn't be much trouble. Even works at 4MHz Internal Osc. I have done a square wave UPS with a 16F676 internal Osc (In full assembly However)

    While in inverter mode --->

    A periodic sampling (every 1 sec) of the input AC voltage may be enough alone. However if you require valid Frequency range then Zero-Cross might be needed. When found normal you can activate the restore to mains routine. Here you need to take care of output voltage regulation through PWM (software if square wave) and also protect MOSFETs from over-current, besides doing housekeeping such as battery-low, no-load shutdown, PC connectivity (16F73 recommended or any other with Hardware USART)

    Breakup your job in discrete sections. Then assemble the whole when each one is ready.
    Good Luck

    P.S. - It is not that I do not want to share my code. But sometimes legally tied.
    Last edited by sougata; - 27th August 2008 at 10:15.
    Regards

    Sougata

  15. #15
    Join Date
    Aug 2008
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply.

    I will explain u wat i did(using assembly).
    inputs to controller:
    1.Actually main is an analog i/p to M/C.
    2.power failure indication(digital).
    3.volt zero cross and current zero cross are two digital i/p.
    4.Overload and battery i/p are two analog.
    -----------------------------------------------------
    1.first step,i intialised all requirements.then using PA0,i read the mains voltage range.and compared with reference for stabilizer operations.zero crossings are used for stabilizer operation.
    2.if the voltage is outof reference range,i will start the inverter.here i m readin overload and battery i/p.

    plz tell me how can i know whether i/p main is present or not(can use interrupt).which pin need to connect.
    plz correct me,if wrong.If u want i'll give u my code.
    Last edited by kvrajasekar; - 27th August 2008 at 11:36.

  16. #16
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Use zero cross on portb.0

    Hi,

    16F72 has portb.0 interrupt which can be used to detect zero crossing easily. Since the current zero cross would be normally close to the voltage zero cross. It may be detected right within the ISR. However entirely depends on the capacity of the UPS and power factor. You can also use the PORTB.7-PORTB.4 Interuupt on change. Here however you need to decide in the ISR whether it is volt/current zero cross or overload. You can use four different signals here.

    I assume that you are in India from your name. So the nominal line frequency would be 50Hz. That means you should get interrupts after every 10mS. Add to that a range of +/- 5 Hz so your window becomes 45Hz to 55Hz wide. Thus you know when your interrupts are too-late or too-early. This is a definite detection of blackout/brownout. But power sags are cannot be detected by this methods.

    So you can start a AD sampling cycle from each zero cross and continue sampling the input (unfiltered). At the end of the cycle you can detect even the RMS voltage through calculations. But this takes a whole cycle (10mS) which may be too much. So the alternative is to compare each sample with known values. Use a lookup table +/- constants for allowed deviation range. This has its own pros and cons. Almost fail proof mains detection but sometimes false detects too.

    However it entirely depends on the equipment in use. All of the offline UPS in the marker under Rs.1500.00 (USD $36 approx) state that they offer a transfer less than 2ms. Not always. In fact the relays which comes for Rs. 6.00 (USD $0.15) exhibits transfer time more than 7mS themselves. Datasheets lie for chinese products. If the supply is to a PC then the PC SMPS itself withstands 20mS sags. That's why the low cost UPS actually seem to work.

    When I started working on the project (I normally try to get industrial applications) I was frustrated achieving goals. Realized the limitations later that a reduced BOM price achieves less.
    Regards

    Sougata

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