|
|
View previous topic :: View next topic |
Author |
Message |
theredkid
Joined: 27 Aug 2014 Posts: 14
|
Phase angle control of thyristor w/ PIC18F |
Posted: Tue Sep 02, 2014 1:40 am |
|
|
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: 19518
|
|
Posted: Tue Sep 02, 2014 2:27 am |
|
|
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
|
|
Posted: Tue Sep 02, 2014 2:44 am |
|
|
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: 19518
|
|
Posted: Tue Sep 02, 2014 2:54 am |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Tue Sep 02, 2014 5:33 am |
|
|
this....
sbit ZC at FlagReg.B0;
... doesn't look correct to me
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Sep 02, 2014 7:46 am |
|
|
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
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Sep 02, 2014 9:54 am |
|
|
I hoped he might look at what I posted, and see how the different commands are used. Little hope though.... |
|
|
|
|
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
|