|
|
View previous topic :: View next topic |
Author |
Message |
Macko77
Joined: 01 Dec 2013 Posts: 5
|
Help with project, PIC 18F4550 , regularly spotlight |
Posted: Fri Dec 06, 2013 8:18 am |
|
|
Good , 'm doing a light control system as an integration of matlab and acquisition board with 18F4550 , through matlab the idea is to send a character to the pic then the control part , the card takes off and 3 shares on two campuses and light of one of the enclosures control the first two things are already made but I can not perform the action of light control , the code that I take is as follows:
# include < 18F4550.h >
# fuses HSPLL , MCLR , NOWDT , NOPROTECT , NODEBUG , USBDIV , PLL5 , CPUDIV1 , VREGEN , NOPBADEN , NOLVP
# use delay (clock = 20000000 )
# use fast_io ( A)
# use standard_io (B )
# include " usb_cdc.h " / / USB Function description in quotation marks because it is working on same folder
# include " usb_desc_cdc.h " / / USB device descriptors .
void main () {
int salt1 , sal2 ;
unsigned char datoIN ;
usb_cdc_init ( ) / / Configure the virtual port.
usb_init ( ) / / Initialize the USB stack.
set_tris_A (0xFF ) / / I set port A as inputs
set_tris_B ( 0x00 ) / / I set the output port b
while (! usb_cdc_connected ())
{
Output_high ( PIN_E0 ) ;
Output_low ( PIN_E1 ) ;
Delay_ms (500);
Output_high ( PIN_E1 ) ;
Output_low ( PIN_E0 ) ;
}
/ / Wait to detect a transmission from the PC ( Set_Line_Coding ) .
Output_high ( PIN_E0 ) ;
Output_low ( PIN_E1 ) ;
salt1 = 0 / / initialized alternative Variables
sal2 = 0 / / initialized alternative Variables
do {
usb_task ( ) ;
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
if ( usb_enumerated ())
{ / / Wait for the device to be enumerated by the host.
Output_low ( PIN_E0 ) ;
Output_high ( PIN_E1 ) ;
if ( usb_cdc_kbhit ())
{ / / Pending new characters in the receive buffer .
usb_cdc_getc datoIN = ( ) ;
if ( datoIN == ' a')
{ / / What came was the character a = no movement in the room 1 and was the highest intensity ?
Output_high ( PIN_B0 ) ;
salt1 = 1 / / if, then the lights are turned one room
}
if ( datoIN == ' b')
{ Val = 8;
}
if ( datoIN == ' c')
{ Val = 7;
}
if ( datoIN == ' d')
{ Val = 6;
}
if ( datoIN == ' e')
{ Val = 5;
}
if ( datoIN == ' f' )
{ Val = 4;
}
if ( datoIN == ' g')
{ Val = 3;
}
if ( datoIN == ' h')
{ Val = 2;
}
if ( datoIN == ' i')
{ / / What came was the character b = no movement in the salon 1 ?
Output_low ( PIN_B0 ) ;
}
if ( datoIN == ' j' )
{ / / What came was the character c == no movement in the salon 2 ?
Output_high ( PIN_B1 ) ;
sal2 = 1 / / if, then the lights are lit room 2
}
if ( datoIN == ' k')
{ / / What came was the character d = no movement in the salon 2 ?
Output_low ( PIN_B1 ) ;
}
if ( salt1 == 1 | | sal2 == 1 ) / / ask for variable room
{
Output_high ( PIN_B2 ) / / Runs Led Indicator
}
else
{
Output_low ( PIN_B2 ) / / Runs Led Indicator
}
datoIN = data ;
}
}
} while ( TRUE ) / / infinite loop.
}
The idea is when the data q [b ] b come [/ b] the intensity is 90 % on pin B0 , when you get [b ] c [/ b] the intensity is 80% on pin B0 , when you get [b ] d [/ b] the intensity is 70 % on pin B0 , when you get [b ] e [ / b ] the intensity is 60 % on pin B0 , when you get [b ] f [/ b] intensity is 50% on pin B0 , when you get [b ] g [/ b] the intensity is 40% on pin B0 , when you get [b ] h [/ b] the intensity is 30% in the pin B0 .
I write porq I have tried many things but I do not get what I want , and this is part of my thesis to qualify for the title of telecommunications engineer , and I need it , not if someone could colaborarme or help to implement it.
This is the dogs in general, the moc I use the 3020 q and zero crossing triac BT136
https://drive.google.com/file/d/0Bw7-Do2OdLyGbDdLVHQ1WG01anRCRlF6cFZBOFVXX05KS25v/edit?usp=sharing
I would appreciate a prompt response
regards Fabio
maverick77.fabio @ gmail.com |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Fri Dec 06, 2013 9:23 am |
|
|
1) Learn to use the code buttons.
2) Clock rate is not 20MHz.
This has been posted only a couple of days ago.
If you want to run at 20MHz, then with a 20MHz crystal:
Code: |
# include < 18F4550.h >
# fuses HS , MCLR , NOWDT , NOPROTECT , NODEBUG , USBDIV , PLL5 , CPUDIV1 , VREGEN , NOPBADEN , NOLVP
# use delay (clock = 20000000 )
|
With your settings, the CPU is driven from the USB PLL (which for full speed USB is running at 96MHz. 'CPUDIV1', when running from this route, divides by two, so you are running with a 48Mhz master clock.
3) Study the data sheet. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Dec 06, 2013 3:11 pm |
|
|
Code: | usb_cdc_getc datoIN = ( ) ; | This line makes no sense at all. Does it even compile? |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Fri Dec 06, 2013 3:34 pm |
|
|
There are a bunch of statements missing the terminating semi-colon. I'm wondering just what the compiler does with those ? (most compilers wake up some number of lines after the errors when they realize they are really confused - it takes a while to figure out just where the original confusion started sometimes!! )
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
Macko77
Joined: 01 Dec 2013 Posts: 5
|
|
Posted: Fri Dec 06, 2013 5:26 pm |
|
|
excuse me my mistake was a correct statement is:
datoIN = usb_cdc_getc ();
datoIN is a variable to load the character sent from matlab, the empty characters b, c, d, e, f, g, h, i, are the percentages of intensity of light.
Ie when the character 'b' comes, the light-controlled (pin b0) must be 90%, if it 'c', the percentage should be 80%, if it 'd' the percentage is 70% and so on.
What is not is how to do that! |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Fri Dec 06, 2013 7:08 pm |
|
|
To do the percentage of light you want, you will need to use "phase control" assuming you are working with AC mains. You need to spend some time searching the forum here as well as other resources to figure out how to implement phase control. It involves zero crossing detection as well as delay times.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
|
|
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
|