ALERTLINKS
Advanced Member level 4
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.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
duty variable machine made a noise
'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.
Antorbd04
"Ok. I completely done."
If u don't mind, can you please share your Basicpro code?PHP:
how I calculate CCPR1L & CCPR1H register
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?
#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
}
}
#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)
{
}
}