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 support@ccsinfo.com

Phase angle control of thyristor w/ PIC18F

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
theredkid



Joined: 27 Aug 2014
Posts: 14

View user's profile Send private message

Phase angle control of thyristor w/ PIC18F
PostPosted: Tue Sep 02, 2014 1:40 am     Reply with quote

Hello,

For the following code, I got some errors:

#include <18F452.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

unsigned char FlagReg;
sbit ZC at FlagReg.B0;

void interrupt(){
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
ZC = 1;
INTCON.INTF = 0;
}
}

void main() {
PORTB = 0;
TRISB = 0x01; //RB0 input for interrupt
PORTD = 0;
TRISD = 0; //PORTD all output
OPTION_REG.INTEDG = 0; //interrupt on falling edge
INTCON.INTF = 0; //clear interrupt flag
INTCON.INTE = 1; //enable external interrupt
INTCON.GIE = 1; //enable global interrupt

while (1){
if (ZC){ //zero crossing occurred
PORTD.B0 = 1; //Send a 1ms pulse
delay_ms(1);
PORTD.B0 = 0;
ZC = 0;
}
}
}




Error list:


Executing: "C:\Program files\PICC\CCSC.exe" +FH "p3.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 48 "p3.c" Line 6(6,10): Expecting a (
*** Error 48 "p3.c" Line 6(12,14): Expecting a (
*** Error 43 "p3.c" Line 6(19,20): Expecting a declaration
*** Error 48 "p3.c" Line 6(20,22): Expecting a (
*** Error 12 "p3.c" Line 9(10,16): Undefined identifier INTCON
*** Error 12 "p3.c" Line 10(12,14): Undefined identifier ZC
*** Error 12 "p3.c" Line 11(9,15): Undefined identifier INTCON
*** Error 12 "p3.c" Line 16(12,17): Undefined identifier PORTB
*** Error 12 "p3.c" Line 17(12,17): Undefined identifier TRISB
*** Error 12 "p3.c" Line 18(12,17): Undefined identifier PORTD
*** Error 12 "p3.c" Line 19(12,17): Undefined identifier TRISD
*** Error 12 "p3.c" Line 20(6,16): Undefined identifier OPTION_REG
*** Error 12 "p3.c" Line 21(6,12): Undefined identifier INTCON
*** Error 12 "p3.c" Line 22(6,12): Undefined identifier INTCON
*** Error 12 "p3.c" Line 23(6,12): Undefined identifier INTCON
*** Error 12 "p3.c" Line 26(16,18): Undefined identifier ZC
*** Error 12 "p3.c" Line 27(15,20): Undefined identifier PORTD
*** Error 12 "p3.c" Line 29(15,20): Undefined identifier PORTD
*** Error 12 "p3.c" Line 30(18,20): Undefined identifier ZC
19 Errors, 0 Warnings.
Build Failed.
Halting build on first failure as requested.
BUILD FAILED: Tue Sep 02 09:56:03 2014


How can I fix the mistakes? I'm open to other code snippets as well.
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Tue Sep 02, 2014 2:27 am     Reply with quote

Seriously, write in CCS....
Read the manual.

What you have is basically assembler, and most of it unwanted.
Also use the code buttons.
Code:

#include <18F452.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

int1 zc=FALSE; //only use all capitals for #defines

#INT_EXT
void interrupt(void)
{
   zc=TRUE;
} //the compiler handles testing what interrupt, and clearing the interrupt

void main(void)
{
    output_b(0); //set port b all low
    output_float(PIN_B0); //RB0 input for interrupt
    output_d(0); //set port d all low
    ext_int_edge(H_TO_L); //falling edge interrupt
    clear_interrupt(INT_EXT); //clear interrupt
    enable_interrupts(INT_EXT);
    enable_interrupts(GLOBAL); //enable interrupt
   
    while (TRUE)
    {
        if (zc)
        { //zero crossing occurred
           output_high(PIN_D0); //1uSec more like it....
           delay_us(1);
           output_low(PIN_D0);
           zc=FALSE;
        }
    }
}

As written this will just pulse the thyristor 'on' a few uSec after the zero point. To actually give dimming, you'd have to delay when the pulse occurs from this point.
theredkid



Joined: 27 Aug 2014
Posts: 14

View user's profile Send private message

PostPosted: Tue Sep 02, 2014 2:44 am     Reply with quote

Sorry, I posted the wrong code. Here comes the actual code:


#include <18F452.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

unsigned char FlagReg;
sbit ZC at FlagReg.B0;

void interrupt(){
if (INTCON.INTF){ //INTF flag raised, so external interrupt occured
ZC = 1;
INTCON.INTF = 0;
}
}

void main() {
PORTB = 0;
TRISB = 0x01; //RB0 input for interrupt
PORTA = 0;
ADCON1 = 7; //Disable ADC
TRISA = 0xFF; //Make all PORTA inputs
PORTD = 0;
TRISD = 0; //PORTD all output
OPTION_REG.INTEDG = 0; //interrupt on falling edge
INTCON.INTF = 0; //clear interrupt flag
INTCON.INTE = 1; //enable external interrupt
INTCON.GIE = 1; //enable global interrupt

while (1){
if (ZC){ //zero crossing occurred
delay_ms(2);
PORTD.B0 = 1; //Send a pulse
delay_us(250);
PORTD.B0 = 0;
ZC = 0;
}
}
}


And error list:


Clean: Deleting intermediary and output files.
Clean: Deleted file "p3.ESYM".
Clean Warning: File "D:\mehmet projeler\p1\p3.o" doesn't exist.
Clean: Deleted file "p3.ERR".
Clean: Deleted file "D:\mehmet projeler\p1\p3.mcs".
Clean: Done.
Executing: "C:\Program files\PICC\CCSC.exe" +FH "p3.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 48 "p3.c" Line 6(6,10): Expecting a (
*** Error 48 "p3.c" Line 6(12,14): Expecting a (
*** Error 43 "p3.c" Line 6(19,20): Expecting a declaration
*** Error 48 "p3.c" Line 6(20,22): Expecting a (
*** Error 12 "p3.c" Line 9(10,16): Undefined identifier INTCON
*** Error 12 "p3.c" Line 10(12,14): Undefined identifier ZC
*** Error 12 "p3.c" Line 11(9,15): Undefined identifier INTCON
*** Error 12 "p3.c" Line 16(12,17): Undefined identifier PORTB
*** Error 12 "p3.c" Line 17(12,17): Undefined identifier TRISB
*** Error 12 "p3.c" Line 18(12,17): Undefined identifier PORTA
*** Error 12 "p3.c" Line 19(13,19): Undefined identifier ADCON1
*** Error 12 "p3.c" Line 20(12,17): Undefined identifier TRISA
*** Error 12 "p3.c" Line 21(12,17): Undefined identifier PORTD
*** Error 12 "p3.c" Line 22(12,17): Undefined identifier TRISD
*** Error 12 "p3.c" Line 23(6,16): Undefined identifier OPTION_REG
*** Error 12 "p3.c" Line 24(6,12): Undefined identifier INTCON
*** Error 12 "p3.c" Line 25(6,12): Undefined identifier INTCON
*** Error 12 "p3.c" Line 26(6,12): Undefined identifier INTCON
*** Error 12 "p3.c" Line 29(16,18): Undefined identifier ZC
*** Error 12 "p3.c" Line 31(15,20): Undefined identifier PORTD
*** Error 12 "p3.c" Line 33(15,20): Undefined identifier PORTD
*** Error 12 "p3.c" Line 34(18,20): Undefined identifier ZC
22 Errors, 0 Warnings.
Build Failed.
Halting build on first failure as requested.
BUILD FAILED: Tue Sep 02 11:43:52 2014
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Tue Sep 02, 2014 2:54 am     Reply with quote

Same comment applies to this.

Look at what I have posted. Just add your 2mSec delay before sending the pulse. 250uSec is still too long. If you need more than 10USec, then there is something badly wrong with the circuit.
temtronic



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

View user's profile Send private message

PostPosted: Tue Sep 02, 2014 5:33 am     Reply with quote

this....

sbit ZC at FlagReg.B0;

... doesn't look correct to me


jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Tue Sep 02, 2014 7:46 am     Reply with quote

Yes, he is using a completely different language, where you define a variable, and then access bit fields in it.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 02, 2014 9:36 am     Reply with quote

Quote:
this....

sbit ZC at FlagReg.B0;

... doesn't look correct to me

He copied the code from here:
http://tahmidmc.blogspot.com/2012_10_01_archive.html

He has also cross posted his question to:
http://www.microchip.com/forums/m819084.aspx

He doesn't realize that CCS != MikroC != XC8, etc.

He thinks he can take code for one compiler and drop it in another
and that it will compile.
Ttelmah



Joined: 11 Mar 2010
Posts: 19451

View user's profile Send private message

PostPosted: Tue Sep 02, 2014 9:54 am     Reply with quote

I hoped he might look at what I posted, and see how the different commands are used. Little hope though....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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