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
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.
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.