RGB pool light project help with inputs

Thread Starter

mystiquesbs

Joined Jan 4, 2009
5
Hi,

The project I am currently undertaking is an RGB pool light.

Inputs: 3 buttons, one for left, one for right and one for enter.

Display: LCD screen

PIC chips = 2 x PIC16f628a

So basically when you turn the thing on the LCD welcomes you with a screen saying "pool light now on" and it immediatly switches on all three led's. It has a five second delay and then the LCD screen switches to "please press enter to continue" you push enter and the screen changes to "choose option with 8 numbers below it 1-8 and an arrow initially pointing at 1. when enter is pushed the arrow dissapears and reappears with a slight delay in between. when left or right is pushed the arrows moves to the corresponding number.

I want numbers 1-4 when pushed to change the lights to different constant colours.

I want numbers 5-7 when pushed to change the lights to different fading colour combinations.

Number 8 changes the lcd screen to a manual setting where you can individually change the R,G,B led's.

Any way at this point i've got the lcd screen working fine that is running off of one PIC16F628a.

I've got all the PWM colour changing and such working fine individually on another PIC16F628a.

The problem i'm having at the moment is that when I toggle through the numbered options the lights will have a flicker which seems to be a couple of ms long. Then when I push enter on various options it works for like 1-7 sometimes but then will mess up pretty quickly and when I push enter on 4 it will do what it should for 1 and when I push 7 it will do what it should for 3 and that sort of thing.

I'm polling the inputs and not using interrupts. I might give interrupts a go tonight and see how I go. But i'm also wondering if I should debounce my switches as I havn't done that at the moment.

Hopefully that will fix the numbers from messing up when I push left and right but I'm not sure that this will fix the flickering.

Any thoughts would be much appreciated.

I will add more when I get home and have my code handy.

Cheers
Brent
 

beenthere

Joined Apr 20, 2004
15,819
Sounds like a hardware problem involving contact bounce in the switch. The problem can be dealt with in hardware or in software.
 

Thread Starter

mystiquesbs

Joined Jan 4, 2009
5
yeh i'm thinking that aswell. I will add a debounce circuit tonight.

Although I did have this as a semi debounce software but maybe its not really:

loop:

btfss porta,1 ;wait for switch to be pushed.
goto doyourthing
goto loop

doyourthing:

btfsc porta,1 ;wait for switch to be unpushed.
goto continue
goto doyourthing:

continue: ;continue

But i'll chuck in a hardware debouncer tonight and hopefully that fixes the misfire problem but i don't think that will fix the flickering but we will soon see.

Cheers for your reply :) much appreciated
 

Thread Starter

mystiquesbs

Joined Jan 4, 2009
5
Sweet,

I put in the debounce circuit which just comprises a quad schmitt trigger a few caps and resistors. I thought it was going to be rather simple but frustrated me for a while as the micro needs a pull up resistor so I had to use a voltage divider to get it to work.

But any way that worked and seemed to solve the switch bouncing problem messing with the counting.

But I have encountered an interesting little problem. As I move left and right if a constant light setting is used then no flickering can be observed but if I have a fading light setting chosen then if I press left or right the lights flicker.

I fair this is due to the code where I wait for the button to be depressed before the instruction can be carried out. However if I do not use this then it will jump back to the program and the button may still be pressed and the count will be increased many times over.

Any ideas on what I could do to solve this problem?
 

tumadre

Joined Jan 5, 2009
5
As a teacher once said to me: if you can solve the problem in software, then solve it in software. You save components and therefore money. Besides debouncing in software is old story.

Check your PWM code.
 

Thread Starter

mystiquesbs

Joined Jan 4, 2009
5
Yeh I just used the hardware to debounce as it was pretty simple and only cost NZ$1 so about 50c US.

But I used some mega code to get the flickering to stop while moving from left to right. This is the code I used: It's insanely long but I've got a heap of memory to use so it doesn't matter much.

This is just for the right button but is mirrored for the left just with variables changed of course.

EDIT: I did add the code but it looked ugly and I havn't commented it AHHHHH I know I'm lazy i'll go back over it once i'm done. Hopefully I can still remember what it all does. Then I'll post it in the final project and maybe someone with the knowledge can help me clean it up.

Now for the final part of coding, EEPROM storage and manual PWM changing and then i'll be done. So close......... I can smell it
 
Top