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

signal phase dimmer code
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lindoudaM2



Joined: 09 Oct 2012
Posts: 13
Location: Tunisie

View user's profile Send private message AIM Address

PostPosted: Sat Oct 13, 2012 12:56 pm     Reply with quote

I haven't test it yet but I just wanted to know your opinion about the changes I made to the code.
Thank you all.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sat Oct 13, 2012 2:55 pm     Reply with quote

ameliorated? i don't think so........

alter-rated only .....
maybe further deteriorated?

pro-rated?

i can accept even being excoriated.

Very Happy Very Happy Very Happy Very Happy Very Happy
Mike Walne



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

View user's profile Send private message

PostPosted: Sat Oct 13, 2012 3:01 pm     Reply with quote

Quote:
I haven't test it yet but I just wanted to know your opinion about the changes I made to the code.
We are not impressed.

If we do the work, you learn nothing.

Tell us what you think your code should do and we will try to help.

You have still not presented a schematic.

Mike
lindoudaM2



Joined: 09 Oct 2012
Posts: 13
Location: Tunisie

View user's profile Send private message AIM Address

PostPosted: Mon Oct 15, 2012 5:35 pm     Reply with quote

Here is the last version of my code
Code:

#include<16F877A.h>
#define adc 0x04;
#use delay (clock =20000000)
#fuses HS,NOWDT, NOPROTECT,  PUT, NOLVP

unsigned int alpha=1180;
byte x;

void init ()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_2);
set_adc_channel(0);
setup_CCP1(CCP_PWM);
setup_timer_2 (T2_Div_by_1,255,1);
setup_timer_1(T1_internal);
set_tris_b(0xFE);
}

#int_ext
void ext_isr()
{

if(input(pin_B0))
  {
   ext_int_edge(H_to_L);
  }
}


void main()
{
init();

enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);

while (1)
  {
   delay_ms (10);

   x=read_adc();
   alpha = x*(1250/1024);
   set_pwm1_Duty(alpha);

   delay_ms(10);
  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 15, 2012 6:01 pm     Reply with quote

Your program has a large number of things that are wrong in the coding
and in the design. Here are just a few of them:

1.
Quote:
unsigned int alpha=1180;

2.
Quote:
#use delay (clock =20000000)
setup_adc(ADC_CLOCK_DIV_2);

3.
Quote:
alpha = x*(1250/1024);


Why don't you research these and try to find what is wrong in each one.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Oct 16, 2012 5:38 am     Reply with quote

I give up.
Several people have remarked that PWM is a wrong method for controlling a triac. I don't mind people being stubborn and continuing on their quest to a 'new super advanced new controlling method that works in ISIS', but when ignoring my advice I like to receive a response about why my advice is ignored. A good discussion, instead of this one way communication.

The topic starter has no clue as to what he is doing. Randomly throws us new versions of the program that are not tested because he 'just wanted to know your opinion'. Meanwhile ignoring all our advice on improvements.

I've wasted my time here. Bye.
lindoudaM2



Joined: 09 Oct 2012
Posts: 13
Location: Tunisie

View user's profile Send private message AIM Address

PostPosted: Tue Oct 16, 2012 11:56 am     Reply with quote

Now the firing angle doesn't work. I think I have a problem in the interruption of TIMER1. PLZ help
Here is the code
Code:

#include<16F877A.h>
#define adc=10
#use delay (clock =20000000)
#fuses HS,NOWDT, NOPROTECT,  PUT, NOLVP

unsigned int alpha=1180;
unsigned int x;
long int cycles;
#bit TMR1IF = 0x0C.0

void init ()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_internal);
Set_adc_channel(0);
setup_CCP1(CCP_PWM);
setup_timer_2 (T2_Div_by_1,255,1);
set_tris_b(0xFE);
}

#int_timer1      // Cette fonction est appelee à chaque
void clock_isr1(void) {     // débordements du timer1 (65535->0).

   setup_timer_1(T1_DISABLED);  // Arret pour le chargement
   cycles = get_timer1();       // Temps de latence
   cycles = cycles + 3038;      // (65535-62500)=3035+(25/div8)=3038
   set_timer1(cycles);
   setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 );
}

#int_ext
void ext_isr()
{
if(input(pin_B0))
  {
   ext_int_edge(H_to_L);
  }
}


void main()
{
init();

TMR1IF=0;        // Reset de l'indicateur d'int. du timer1
enable_interrupts(int_timer1);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
set_timer1(3038);

while (1)
  {
   x=read_adc();
   alpha = cycles +((unsigned int)(1250*(long)x)/1023);
   set_pwm1_Duty(alpha);
   delay_ms(10);
  }
}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Oct 16, 2012 1:27 pm     Reply with quote

Quote:

Now the firing angle doesn't work

I don't think it ever DID or ever will work right for that matter.

I have said it before:

PWM does not work as needed to accurately trigger a triac

(unless miraculously you had a phase lock to the mains , at just the right frequency multiple for a PWM firing protocol. WHICH YOU CLEARLY DO NOT !!!! )


And not one change that others suggested,
has made it into your MESS of an alleged program.

Since you have still not bothered to post a schematic -
consider me all done as well.

adios amigo.
Mike Walne



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

View user's profile Send private message

PostPosted: Wed Oct 17, 2012 2:04 am     Reply with quote

This is getting to be like "The Dragon's Den". You've already lost two experts.

Quote:
Now the firing angle doesn't work.
This statement means nothing to us. In what way does it not work?

Despite several requests you have still not given us a schematic.

I've already outlined the sequence needed for phase angle control. Please explain how you think your code achieves phase angle control.

I'm assuming that you have taken previous advice, have ditched ISIS, and are now working with real hardware.


I suggest you work on the KISS principal.

You're making things too complicated by controlling from an ADC. The ADC output my be very noisy and causing some issues. You could eliminate this as a problem by either:-

1) Ramping the phase angle up and down over a period of several seconds.
2) Using two buttons to increase/decrease phase angle.

OR

3) Simplest of all work at a fixed phase angle of say 90 degrees.

Mike

EDIT Thinking about it. Your design is so far out, doing option 3 would be quite a significant step forward.
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 Previous  1, 2
Page 2 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