Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C Programing problem. RGB controller with PIC16F690.

Status
Not open for further replies.

DavidLindh

New Member
Ok, rewrote the blending with pwm and it works fine except one thing.

I have 3 leds, one red, green and blue connected to RC0 - 2.
I also have 2 pots connected to RA0 and 1 that controls the speed of the fade between colors and how long it should stay on that color.

**broken link removed**

By turning the active led on, then fade in the new color and when the fade is done I turn the new color on and start to fade the old one out.
Fore some reason there is a delay when both leds are turned on. If the speed variable is bigger the delay gets longer.
 
Last edited by a moderator:
I having some problems with my code controlling the fade between colors.

It seems to jump from 0% to 25% fade to 75% and then jump to 100%.

It's kind of hard to see. How is speed declared? Is it changed somewhere else?

What does DelayUS do?

Do you really have a function called "longDealy"?

What does checkTrim() do?

Brad
 
Last edited:
Do the LED's in the video represent the output of the port?

You will need to post your full code and compiler and version of compiler, is it MikroC?

You will also need to provide a description of what you are trying to achieve, i.e, PORTC BIT 0 fade to PORTC BIT 1, PORTC BIT 1 fade to PORTC BIT 2 etc.

Your fade sequence looks like from 00000001 to 00000010 then from 00000010 to 00000100 then from 00000100 to 00000001, so PORTC bit 0 to bit 1, to bit 2, then back to bit 0, is this correct?

I'm not quite sure how you are "fading" are you using PWM?
 
I realized the problem.

1. I totally messed up my code trying different combinations without commenting.
2. The code is working but the turning the first color on for 255us and the second color on for 0us is not enough.
3. I control the speed from the wrong place in the code. (speed is set by a pot and goes from ~ 0 to 255).

I started this project without any knowledge what so ever about programing a micro controller. I was reading about PWM after I wrote the code that controls the blend that worked if i call the blend function 10 times and manually changed the input.
Now it seems like a good idea to rewrite the blending between colors and use PWM.

I come back to you soon.
 
Ok, rewrote the blending with pwm and it works fine except one thing.

By turning the active led on, then fade in the new color and when the fade is done I turn the new color on and start to fade the old one out.
Fore some reason there is a delay when both leds are turned on. If the speed variable is bigger the delay gets longer.
 
So you start to fade the colour then turn the LED on once the fade is complete? So you disable PWM and turn on the port bit? Or drive the PWM to make the LED constantly lit?
Or are you using 2 PWM channels to fade one out and one in? I presume once the fade out is complete you switch the port bit off?

How long is the delay when both LED's are turned on?

Are you using hardware or software PWM, and how many channels?

Wilksey
 
Right now there is an additive fade just like you described it. And I think the different between a duty cycle on 200 and 255 is to small for the eye to see when both leds are glowing.
Therefor I want to try make a cross fade when one led is fading in and the other out.

Is there possible to have 2 different duty cycles? I need one for each led when doing a cross fade.

I'm using the built in PWM in the PIC16F690. Define channels?

/David
 
I presume if you have enough hardware PWM channels you can control them independantly?

Or, one other option is as you are adding to the PWM of the second LED, subtract from the first.

So if you increment PWMDuty, set PWMDuty on Channel 2, and set Channel 1 less PWMDuty, if you see what I mean?

Wilksey
 
I see what you mean but I don't know how to do it in practice. This is what I came up with but it's not working.

Code:
for(i = 255 ; i > 0 ; i--)
{
	checkTrim();		
	PSTRCON = from;		
	CCPR1L = i;
	PSTRCON = dest;		
	CCPR1L = 255-i;
	DelayMs(speed);		
}

I cant find anything about the pwm modes, now Im using single pwm mode and that don't sound right if Im trying to use 2 channels.
 
Does that particular chip have 2 hardware PWM modules onboard?

For example, if one PWM channel is 255 and you start to increase PWM channel 2, just decrease PWM channel 1 by that amount.

for(i = 0; i <255; i++)
{
CCPR2L = i; //Second PWM Channel
CCPR1L -= i; //Take away i from PWM Channel 1
}

Something like the above?

Is this something that could be done?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top