CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC18F4550 PWM Issue
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PIC18F4550 PWM Issue
PostPosted: Tue Jun 25, 2013 10:46 am     Reply with quote

Dear All,

I am designing a lighting controller 0-10V and I made the setup (HF Ballast and T5 lamp). I also interfaced the PIC18F4550 and the LM358 op-amp circuit to convert the PWM signals to 0-10V. The circuit can be found here:

http://forums.parallax.com/showthread.php/123572-0-10v-lighting-control

when I powered the circuit the voltage on the DMM started to go up slowly. I suspected that something is wrong. I remove the green cable (between the PIC Micro and 10K input resistor) and the voltage still continues to rise until reaches 10V! I started to test the code on the demo compiler of CCS 5.05 recently released. I made the code that on start-up the signal will immediately goes to ~6V (dims the ballast to 60%). But still no luck! Strictly speaking this is my first time that I am using PWM and I am very looking forwad to work with this circuit.

The photos can be found: http://share.pho.to/2jMRx

One idea/suggestion, to dim 0-10V over long distance, can I use Digital Potentiometers or I2C DACs? Some forums say it is not ideal and some says that PWM configuration is not a good idea. Really thanks for your reply.

My Main Program is:

Code:
#include <pwm_new.h>

int16 value, count;



void main()
{
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //104 ms overflow
   enable_interrupts(GLOBAL);
   
   setup_ccp1(CCP_PWM);
   
   
   while(TRUE)
   {
      pwm_on();
      set_pwm1_duty(600);
           
     
   }

}


My .h file:
Code:
#include <18F4550.h>
#device ADC=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(crystal=20000000)
#use pwm(CCP2,TIMER=2,FREQUENCY=10000,DUTY=25)
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jun 25, 2013 11:49 am     Reply with quote

stuff to consider...
1) without a 'bleed' resistor across the 1uf input cap of the opamp, and PIC not connected the op amp will eventually 'saturate',going 'full on'.

2) what is a 'long distance'? inches, feet, a mile or two? If more than say 2 feet, consider using a second PIC( master-slave) similar to DMX512 protocol(which was designed for this operation !)

hth
jay
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Tue Jun 25, 2013 12:21 pm     Reply with quote

I can't figure out where is the problem. Do someone has a circuit which I can try?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 25, 2013 12:42 pm     Reply with quote

Quote:
#use pwm(CCP2,TIMER=2,FREQUENCY=10000,DUTY=25)

setup_ccp1(CCP_PWM);

Why are you mixing the two styles of PWM setup ? Why do you first
setup to use CCP2, but then decide to use CCP1 ?

This thread has some examples of how to setup pwm for an 18F2550
(and will also work for an 18F4550):
http://www.ccsinfo.com/forum/viewtopic.php?t=48575
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Tue Jun 25, 2013 12:49 pm     Reply with quote

Dear Temtronic, the distance could be 100-200 meters long. How come you mixed DMX with 0-10V dimming techniques? DMX is based on RS485 hardware and from my knowledge that was the reason that it is more capable for longer distances? Do you have any circuit which you can explain better?
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Tue Jun 25, 2013 1:01 pm     Reply with quote

PCM Programmer, thanks. It worked fine. I noticed that I had the clock parameters not good. When I replaced that line, it worked perfect as wanted. The last issue is the hardware because I needed for long distance. Is it possible to solve the problem by using Mosfet technology?
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jun 25, 2013 1:58 pm     Reply with quote

The 'slave' PIC would receive a command from the 'master' PIC and convert it into the 0-10V signal your lamp/ballast unit requires.
I said 'DMX' as it's a well known standard for remote lighting control.
Any serial communications 'protocol' would work for 200m. Current loop, RS232,RS485,DMX,etc. though you have to work out the details of speed vs distance.
As for the 10V control, depending on the resolution(# of bits/step), you could use a PIC port and make your own DAC with R-2R ladder network.

How you proceed depends upon your skill level, design requirements,etc.

hth
jay
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Tue Jun 25, 2013 10:04 pm     Reply with quote

Thanks for your reply. But when pm is better than dac and vice versa regarding 0-10v dimming?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Jun 26, 2013 3:04 am     Reply with quote

aaronik19 wrote:
But when pm is better than dac and vice versa regarding 0-10v dimming?

PWM / DAC considerations apply to any application, not just yours.
The pros and cons are the same.

You have to weigh up:-

a) Cost.
b) Accuracy.
c) Speed.
d) Resolution.
e) Real estate.
f) The list goes on

It's up to you to do the analysis in each case.

Do the research.

Mike
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Thu Jun 27, 2013 5:53 am     Reply with quote

thanks to all of you guys. at the moment i am going to stick with the op-amp technique. i would like to add the feature of "Fade-In Time". for example i want to set_pwm_percent(400) witin 5 seconds.

First I tried to vary the frequency using the forumlae T=1/f; set_pwm_frequency(). Make a routine to keep this frequency for 5 seconds, but the still did not work. Do someone has any idea how I can implement this?
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Thu Jun 27, 2013 6:09 am     Reply with quote

You need to fade in by changing the duty cycle, not the frequency.

The RC filter you have in the opamp solution is a fixed value, and will not work properly with changing frequency.
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Thu Jun 27, 2013 6:25 am     Reply with quote

thanks. do you mean that I need to use the set_duty_cycle() before set_pwm_percent()? At the moment I can't recognize it...sorry
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Thu Jun 27, 2013 6:45 am     Reply with quote

aaronik19 wrote:
thanks. do you mean that I need to use the set_duty_cycle() before set_pwm_percent()? At the moment I can't recognize it...sorry


duty cycle and pwm percent are basically the same thing.

Du you understand what you are doing with the pwm?

There are only 2 things you can control: The duty cycle, and the frequency.

You set the frequency once at initialisation to suit the value of your rc filter. After that you ONLY change the duty cycle to make the lights brighter or dimmer.
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Thu Jun 27, 2013 7:25 am     Reply with quote

Ok now we are on the same line...

Yes i am using duty cycle to dim and bright. So far so good. Now my problem is that i need to make a sort of ramp-up or ramp-down. For example bright from 58% to 80% in 5seconds.
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Thu Jun 27, 2013 8:06 am     Reply with quote

aaronik19 wrote:
Ok now we are on the same line...

Yes i am using duty cycle to dim and bright. So far so good. Now my problem is that i need to make a sort of ramp-up or ramp-down. For example bright from 58% to 80% in 5seconds.


That's not in any way difficult. There are many ways to do it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group