asking
Full Member level 5
- Joined
- Sep 21, 2010
- Messages
- 279
- Helped
- 6
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 1,298
- Activity points
- 3,377
Hi,
I am trying to make one Time Switch which enables only after specific light conditions and keep running for predefine timer (Free running counter).
I have used 2 ADC Channels 1 for Adj for POT (Preset for light sensing) and 2nd ADC channel for LDR input from a low pass filter of 75HZ (to avoid noise). Now issue is when i set something value to near to the actualy lighting condition. The output jitter's small flicker.. How to avoid jittering ? i just want to keep that about preset of around 7pm at night the output should energize the relay direction no jittering.... how to do that.
mikroc code by me for my LDR Light switch. Please suggest some solution.
Thanks
- - - Updated - - -
I am trying to make one Time Switch which enables only after specific light conditions and keep running for predefine timer (Free running counter).
I have used 2 ADC Channels 1 for Adj for POT (Preset for light sensing) and 2nd ADC channel for LDR input from a low pass filter of 75HZ (to avoid noise). Now issue is when i set something value to near to the actualy lighting condition. The output jitter's small flicker.. How to avoid jittering ? i just want to keep that about preset of around 7pm at night the output should energize the relay direction no jittering.... how to do that.
mikroc code by me for my LDR Light switch. Please suggest some solution.
Thanks
Code:
unsigned int ADC_LUX, ADC_ADJ;
unsigned long int TCOUNT;
unsigned short var1, var2;
// Interrupt Handler
void interrupt()
{
// Timer0 Interrupt - Freq = 15.26 Hz - Period = 0.065536 seconds
if (INTCON.TMR0IF == 1) // timer 0 interrupt flag
{
TCOUNT = TCOUNT + 1;
if (TCOUNT > 100) //332300 COUNT EQUALS TO 8 HOURS
//var1 = 0;
TCOUNT = 0;
// GPIO.GP4 = ~GPIO.GP4; // Toggle PORTB bit0 LED
INTCON.TMR0IF = 0; // clear the flag
INTCON.TMR0IE = 1; // reenable the interrupt
TMR0 = 0; // reset the timer preset count
}
}
void main() {
ADC_Init();
ADCON0 = 0x00;
ANSEL = 0X03; // AN0 & AN1 CONFIGURED AS ANALOGUE INPUT
TRISIO = 0b00000011;
//GPIO = 0X00;
CMCON = 0x07;
var1 = 0;
var2 = 0;
//Timer0 Registers Prescaler= 256 - TMR0 Preset = 0 - Freq = 15.26 Hz - Period = 0.065536 seconds
OPTION_REG.T0CS = 0; // bit 5 TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
OPTION_REG.T0SE = 0; // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
OPTION_REG.PSA = 0; // bit 3 Prescaler Assignment bit...0 = Prescaler is assigned to the Timer0
OPTION_REG.PS2 = 1; // bits 2-0 PS2:PS0: Prescaler Rate Select bits
OPTION_REG.PS1 = 1;
OPTION_REG.PS0 = 1;
TMR0 = 0; // preset for timer register
// Interrupt Registers
INTCON = 0; // clear the interrpt control register
INTCON.TMR0IE = 1; // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt
INTCON.TMR0IF = 0; // bit2 clear timer 0 interrupt flag
INTCON.GIE = 1; // bit7 global interrupt enable
while(1)
{
ADC_ADJ = ADC_READ(0);
ADC_ADJ = ADC_ADJ/1; // divide by 1 for maximum sensitivity @ 10 bit resolution
ADC_LUX = ADC_Read(1);
ADC_LUX = ADC_LUX/1;
}
- - - Updated - - -