Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How Can I generate clock pulses for 50Hz square wave inverter using TMR2 and PR2

Status
Not open for further replies.
duty variable machine made a noise

Use filter capacitor on ADC input pin. Make response slow that means slow down the rate of change of PWM. This is a hardware problem.
 
Antorbd04

"Ok. I completely done."
PHP:
If u don't mind, can you please share your Basicpro code?
 

Another improvement is to change PWM on only one half cycle. The other half cycle follow the same. This will avoid flux imbalance in transformer.
 
ALERTLINKS
There are three Variables 1. main 2. battery and 3. PWM control . What is the function of Main in Real life Inverter operation?


Mithun_K_Das

There are Five Variables 1.PWM 2. AC 3. o/l 4. Dc and 5. Amp control . What is the function of 2. AC and 5. Amp control in Real life Inverter operation?
 

'Battery' is input to monitor 12V battery voltage.
"PWM" is monitoring output AC voltage. When voltage rise, duty cycle will of will be automatically reduced and vice versa.
"MAINS" is input for 220V-AC (mains) input to display voltage on LCD.
 
'Battery' is input to monitor 12V battery voltage.
"PWM" is monitoring output AC voltage. When voltage rise, duty cycle will of will be automatically reduced and vice versa.
"MAINS" is input for 220V-AC (mains) input to display voltage on LCD.

Hi,
how I calculate CCPR1L & CCPR1H register????

Thanks.

- - - Updated - - -

Antorbd04

"Ok. I completely done."
PHP:
If u don't mind, can you please share your Basicpro code?

sorry. I just complete only PWM section code not full code.
 

how I calculate CCPR1L & CCPR1H register

If a timer1 interrupt is required after 50000 instruction cycles, which is equal to 10mS with 20MHz crystal, then
CCPR1H= 50000/256 = 195 = 0xC3
CCPR1L= remainder = 80 = 0x50
In interrupt routine, the count of instruction cycles to reach this code is lessened to correct the timing.
 
Here is my picbasic code and its working properly. but when I add this to my 7 segment Inverter then I got this from proteus: 1[03-13-51].jpg

proteus showing many msg.......

plz help!!!

Code:
DEFINE OSC 10
ON INTERRUPT GOTO UPDATE

FLAG VAR BIT
TMR1IF var PIR1.0 ' TMR1 interrupt flag
TMR1IE VAR PIE1.0
TMR2IF var PIR1.1 ' TMR2 interrupt flag
TMR2IE VAR PIE1.1
CCP1IE var PIE1.2 
CCP1IF VAR PIR1.2
GIE VAR INTCON.7     ' Global Interupt Enable
PEIE VAR INTCON.6    ' Perif. Eq. Interupt Enable
PWM1 VAR PORTC.5 ' Alias servo pin1
PWM2 VAR PORTC.6 ' Alias servo pin2

TRISC = 0 ' Configure PORTC as outputs 
PORTC = 0 ' Clear PORTB 

'********************* Initiate the interrupt 
  FLAG = 1
  T2CON = $36
  PR2 = 223
  TMR2IE = 1
  INTCON = $C0
  CCP1CON = %00001010
  CCP1IE = 1
  CCPR1H = $49
  CCPR1L = $A8
  T1CON = $01
  TMR1IF = 0

MAIN:

GOTO MAIN

DISABLE
UPDATE:
IF CCP1IF = 1 THEN
CCP1IF = 0
PWM1 = 0
PWM2 = 0
ENDIF
IF TMR2IF = 1 THEN
TMR2IF = 0
TMR1H = 0
TMR1L = 0
IF FLAG = 1 THEN
PWM1 = 1
TOGGLE FLAG
ELSE
PWM2 = 1
TOGGLE FLAG
ENDIF
ENDIF                           
RESUME
ENABLE
 

The code does not contain your seven segment routines. Disaplay is working in picture. What is the problem?
 
The code does not contain your seven segment routines. Disaplay is working in picture. What is the problem?

My problem is solved.

Now I face a another problem. Can you help me?

How I charge SLA battery with PWM & how to determine full charge?
Can you tell me how PWM charging work?

Thanks.
 

Brother ALERTLINKS, If you don't mind can you please , help me to convert below pic12f code to pic16F72 code

code:
Code:
#define tx         GPIO.GP5

unsigned TMR1    absolute   0x0E;

char current_dim = 0;
char done_flag = 0;

unsigned preload_time[10] = {65535,63823,63082,62481,61925,61370,60814,60259,59656,58916};

//******************************************************************************
//*** interrupt-on-change when zero-crossing occur, pre-load timer1 value
//*** turn on timer1 to perform delay before gate trigger
//*****************************************************
     if(INTCON.GPIF){
        tx = 1;
        TMR1 = preload_time[current_dim];       //preload_time into Timer1
        T1CON.TMR1ON = 1;                          //start timer1
        INTCON.GPIF = 0;
      }
//******************************************************************************
//*** perform gate trigger, turn off itself
//******************************************************************************
     if(PIR1.TMR1IF){
        T1CON.TMR1ON = 0;          //stop timer1
        tx = 0;                    //turn on triac
        delay_us(150);
        tx = 1;                    //turn off triac
        PIR1.TMR1IF = 0;           //clear interrupt flag
     }
}
 
Last edited by a moderator:

How start and stop CCP 50Hz osc by switch?
 

Switch control on portc, bit4.

Code:
 #define   switch   RC4_bit	// input switch on/off
 #define   Clock1   RC5_bit	// PWM output#1
 #define   Clock2   RC6_bit	// PWM output#2
// #define Switch_Pin 4		//enable switch input
// #define Switch_Port PORTC
// #define Debounce_Time 20
 char flag;			// regiter for flags
 int duty;			//16bit register for duty cycle
sbit flag1 at flag.B0;		//flag for selecting period or duty cycle
sbit phase at flag.B1;		//flag for selecting alernate phase
sbit enable at flag.B2;		//flag to monitor input switch to enable inverter
void interrupt()
{
    if(CCP1IF_bit)
    {
    if(flag1)			//duty cycle selection
     {
      Clock2 = 0;		// PWM2 output is switched off
      Clock1 = 0;		// PWM1 output is switched off
      flag1=0;
      CCPR1L = 0x03; 		// Load values in 16 bit register for 10000
      CCPR1H = 0x27;		// 1/2 duty cycle  period. 10mS at 4 MHz
//      if (Button(&Switch_Port, Switch_Pin, Debounce_Time, 0))
//
    if(PORTC.F4 == 0)   //If the switch is pressed
	{		//read switch
	enable=1;		// flag to enable inverter output
      }
    else
       {
	enable=0;		// flag to enable inverter output
        }
      {
      TMR1H = 0x00;		// Clear/Reset  timer1  register
      TMR1L = 0x00;		//its 16bit

      CCPR1H = duty/256;
      CCPR1L = duty-CCPR1H*256;       //Load value for PWM duty cycle from "duty" register
      flag1=1;			// select next interupt for duty cycle selection
        }
      if 	(enable)
       	{		// if inveter is enabled otherwise skip
     if (phase)			// selct phase1
     {
      asm nop;
      Clock1 = 1;		// PWM1 is set high
     phase=0;			// select next interupt for phase2

      }
      else
      {
        Clock2 = 1;		// PWM2 is set high
        phase=1;		// select next interupt for phase1
       asm nop;
       }
	}
//    }
     CCP1IF_bit = 0;		// clear interupt flag
     	}
} // ISR ends...
 }

void main()
{
   TRISC = 0b00010000; 		// PORTC All Outputs except pin#4
   PORTC = 0x00;	 	// portc, all bits zero
   flag1=1;			// first select interupt for duty cycle
   CCP1CON = 0b00001010;	// trigger special event
   CCP1IE_bit = 1;
   TMR1IF_bit = 0;
   GIE_bit = 1;
   PEIE_bit = 1;
   T1CON = 0x01;
   duty=6666;			// setduty cycle for 66.6%

   while(1)
    {
   }
}

See simulation video


 

Attachments

  • inv-en.rar
    385.2 KB · Views: 166
Please , I needs wiring diagram of IPS / Inverter / UPS . Schematic with Transformer , relay , battery and circuit connection .
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top