View previous topic :: View next topic |
Author |
Message |
Spradecom
Joined: 01 Jun 2011 Posts: 19 Location: INDIA
|
Help for Timer0 interrupt |
Posted: Thu Sep 13, 2012 3:29 am |
|
|
I want to control AC phase angle controlling TRIAC gate signal. I am using timer0 interrupt with
Code: |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4);
|
and check adc value from trimpot.
I am using 16F684 with 4MHz internal oscillator,
I had read ADC in and drive MOC3001 using PWM.
ADC value converted from(0-1023) to (0-10) using conversion. As 0-10ms conversion, but I found flickerring at PWM output in oscilloscope & on Load lamp. Either problem from Timer0. Can anyone give any solution to resolve this problem ?
I had checked individually ADC & PWM output without detecting zero-cross detect of AC using optocoupler (EL817D).
& using software delay routine & PWM with zero-cross detect it worked properly. But using zerocross detect, with ADC & PWM, I'm stuck on this problem.
Last edited by Spradecom on Fri Sep 14, 2012 1:41 am; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Thu Sep 13, 2012 9:39 am |
|
|
Quote: | I had checked individually ADC & PWM output without detecting zero-cross detect of AC using optocoupler (EL817D).
& using software delay routine & PWM with zero-cross detect it worked properly. But using zerocross detect, with ADC & PWM, I'm stuck on this problem. | I'm not sure about what you're saying does/doesn't work.
I need a lot more clear, concise detail about what you are actually doing in both hardware and software. You're the one with the board in front of you, we're all having to second guess.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Sep 13, 2012 4:27 pm |
|
|
got a SCHEMATIC??
and your FULL CODE ??
a faulty zero cross detector can make your whole thing bad -
but ???
Quote: |
drive MOC3001 using PWM.
|
How do you SYNC to line rate zero-cross -
?? PWM alone is going to random trigger w/0
sync and isn't going to mean much !!
SO how do you know its the timer and not your program logic??
etc etc etc
better still -how can WE tell w/o any schematic or full code to review?? |
|
![](templates/subSilver/images/spacer.gif) |
Spradecom
Joined: 01 Jun 2011 Posts: 19 Location: INDIA
|
|
Posted: Fri Sep 14, 2012 1:42 am |
|
|
asmboy wrote: | got a SCHEMATIC??
and your FULL CODE ??
a faulty zero cross detector can make your whole thing bad -
but ???
Quote: |
drive MOC3001 using PWM.
|
How do you SYNC to line rate zero-cross -
?? PWM alone is going to random trigger w/0
sync and isn't going to mean much !!
SO how do you know its the timer and not your program logic??
etc etc etc
better still -how can WE tell w/o any schematic or full code to review?? |
My modified code is
Code: | //------------------------------------------------------------------------------
unsigned int8 temp_port_a;
unsigned int8 buff[20]={};
void shift_buff(void);
void shift_adc_buff(void);
//------------------------------------------------------------------------------
#int_TIMER0
void TIMER0_isr(void)
{
disable_interrupts(INT_TIMER0); //disable timer0 interrupt
TRAIC_GATE = 0;
// delay_us(350);
// TRAIC_GATE = 1;
}
//------------------------------------------------------------------------------
#int_RA
void RA_isr(void)
{
TRAIC_GATE = 1;
set_timer0(firing_angle);
enable_interrupts(INT_TIMER0); //Enable timer0 interrupt
temp_port_a = PORTA;
}
//------------------------------------------------------------------------------
void main()
{
setup_adc_ports(sAN5|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_RA);
setup_oscillator(OSC_8MHZ);
initialize_ports();
initialize_variables();
enable_interrupts(GLOBAL);
while(TRUE)
{
STATUS_LED ^= 1;
read_pot_position();
}
}
//------------------------------------------------------------------------------
void initialize_ports(void)
{
output_float(PIN_A0);
output_float(PIN_A1);
output_float(PIN_A2);
output_float(PIN_A3);
output_float(PIN_A4);
output_float(PIN_A5);
output_high(PIN_C0);
output_float(PIN_C1);
output_high(PIN_C2);
output_float(PIN_C3);
output_float(PIN_C4);
output_float(PIN_C5);
}
//------------------------------------------------------------------------------
void initialize_variables(void)
{
unsigned int8 i;
firing_angle = MINIMUM_FIRING_ENGLE;
for(i=0;i<20;i++)
{
buff[i]=firing_angle;
}
}
//------------------------------------------------------------------------------
void read_pot_position(void)
{
unsigned int32 adc_output_data;
unsigned int16 i;
unsigned int8 temp_data;
unsigned int8 fire_data;
unsigned int16 read_data;
set_adc_channel(5);
adc_output_data = 0;
for(i = 0; i <100; i++)
{
adc_output_data += read_adc(ADC_START_AND_READ);
}
read_data=(unsigned int16)(adc_output_data/i);
temp_data = (unsigned int8)(read_data / 7.8);
fire_data = MINIMUM_FIRING_ENGLE + temp_data;
firing_angle =buff[0];
shift_buff();
buff[19]=fire_data;
}
//-----------------------------------------------------------------------------
void shift_buff(void)
{
unsigned int8 j;
for(j=0;j<19;j++)
{
buff[j]=buff[j+1];
}
}
//------------------------------------------------------------------------------
& Configuration as following
#include "16F684.h"
#device adc=10
/********************************************************************************/
// Defining All FUSES
/********************************************************************************/
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES PROTECT //Code not protected from reading
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES CPD //No EE protection
#FUSES PUT //Power Up Timer
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#use delay(clock=8000000)
/********************************************************************************/
// Defining All SFR's
/********************************************************************************/
#BYTE PORTA = 0x05
#BYTE PORTC = 0x07
/********************************************************************************/
// Defining All Ports
/********************************************************************************/
#BIT ICD_2_DATA = PORTA.0 //INPUT
#BIT ICD_2_CLOCK = PORTA.1 //INPUT
#BIT NC_1 = PORTA.2 //INPUT
#BIT ICD_2_RESET = PORTA.3 //INPUT
#BIT ZERO_CROSSING = PORTA.4 //OUTPUT
#BIT NC_2 = PORTA.5 //OUTPUT
#BIT STATUS_LED = PORTC.0 //OUTPUT
#BIT ANALOG_INPUT = PORTC.1 //OUTPUT
#BIT TRAIC_GATE = PORTC.2 //OUTPUT
#BIT NC_3 = PORTC.3 //OUTPUT
#BIT NC_4 = PORTC.4 //INPUT
#BIT NC_5 = PORTC.5 //INPUT
/********************************************************************************/
// Defining All Data
/********************************************************************************/
#define MINIMUM_FIRING_ENGLE 115
#define MAXIMUM_FIRING_ENGLE 245
/********************************************************************************/
// Defining All Variables
/********************************************************************************/
unsigned int8 firing_angle;
/********************************************************************************/
// Defining All Functions
/********************************************************************************/
void initialize_ports(void);
void initialize_variables(void);
void read_pot_position(void); |
|
|
![](templates/subSilver/images/spacer.gif) |
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Fri Sep 14, 2012 2:35 am |
|
|
Still no schematic.
You're keeping us all in the dark.
Mike |
|
![](templates/subSilver/images/spacer.gif) |
|