|
|
View previous topic :: View next topic |
Author |
Message |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Apr 14, 2005 3:02 pm |
|
|
What's the problem? What are you trying to do? It doesn't appear that you posted all the code. But none of this looks right
Code: |
current_value1=valorpwm1[0] ;
current_value2=valorpwm1[0] ;
current_value3=valorpwm1[0] ;//Inicializamos con un valor de duty de 0 -> leds off
|
Show all the current values be initialized to valorpwm1[0]?
Code: |
exit=0;
while (1)
{
if (Check_levels)
{
Check_levels=0;
level1=Rx_Buffer[DMX_512_Offset-1];
level2=Rx_Buffer[DMX_512_Offset];
level3=Rx_Buffer[DMX_512_Offset];
|
What this about? DMX_512_Offset is the DMX channel to start with. With a value of 5, you will not receive channels 1-4. So Rx_Buffer[0] will contain channel 5's level. Your code sets level1 = channel 9 and level2 and level3 = channel 10? I don't think this is what you want.
Code: |
calcul_duty1(level1,current_value1);
calcul_duty2(level2,current_value2);
calcul_duty3(level3,current_value3);
} //cierra check levels
current_value1=new_value1;
current_value2=new_value2;
current_value3=new_value3;
}//cierra while(1)
}//cierra main
|
Don't know what this is for nor to I have the code for it. |
|
|
Guest
|
|
|
vascotech88
Joined: 10 Mar 2009 Posts: 33 Location: Aveiro, Portugal / Lodz, Polska
|
DMX-12 Receiver with error reading packets |
Posted: Tue Mar 10, 2009 8:08 pm |
|
|
Hello, I'm trying to build a DMX-512 receiver with a PIC16F737 (3 PWM modules) to use in a RGB light. Some time ago I have used a piece of code that I have found in this forum. But now I'm having a problem, I used 5 LEDs connected to the PIC so I could see if the program is running correctly, and the program always stop in the loop "WaitForStart" because I always get a framing error. Can you please see what's the problem. Thank you very much!
The PIC16F737 is directly connected to a PIC16C745 in a Oksidizer USB to DMX512 converter (see Elektor magazine) connected to a PC and running Freestyler DMX
The code is:
Code: | #include <16F737.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
//#FUSES INTRC_IO
#FUSES HS
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 4.5V
#FUSES MCLR //Master Clear pin enabled
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOBORSEN //See Datasheet
#use delay(clock=20000000)
#use rs232(baud=250000,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9,LONG_DATA,errors)
#define frame_error (rs232_errors && 0x04)
#define total_channels 3
void main()
{
unsigned long address = 0;
unsigned long value = 0;
unsigned int buffer_pointer = 0;
unsigned int buffer[total_channels]={0};
unsigned int frame_count=0;
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,249,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_ccp3(CCP_PWM);
set_pwm1_duty(128);
set_pwm2_duty(128);
set_pwm3_duty(128);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//setup_oscillator(OSC_8MHZ|OSC_INTRC);
output_low(pin_a0);
output_low(pin_a1);
output_low(pin_a2);
output_low(pin_a3);
output_low(pin_a4);
address=1;
//address=( (input_a()&&0x3F) || ((input_b()&&0x07)<<6) );
MainLoop:
buffer_pointer++;
WaitForBreak:
value=getc();
output_toggle(pin_a0); // Led always ON
if(!frame_error) goto WaitForBreak; // Doesn't loop because framing error is different from 0
WaitForStart:
value=getc();
output_toggle(pin_a1); // Led flashing
if(frame_error) goto WaitForStart; // Always looping here!
if(value) goto MainLoop;
WaitForData:
value=getc();
output_toggle(pin_a2); // Led always OFF
if(frame_error) goto ApplyValues;
frame_count++;
MoveData:
if(frame_count>=address)
buffer[buffer_pointer]=(char)(value>>1);
buffer_pointer++;
output_toggle(pin_a3); // Led always OFF
if(buffer_pointer!=total_channels) goto WaitForData;
buffer_pointer=0;
ApplyValues:
set_pwm1_duty(buffer[address]);
set_pwm2_duty(buffer[address+1]);
set_pwm3_duty(buffer[address+2]);
frame_count=0;
output_toggle(pin_a4); // Led always OFF
goto MainLoop;
}
} |
Thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 10, 2009 9:08 pm |
|
|
Quote: | #define frame_error (rs232_errors && 0x04)
//address=( (input_a()&&0x3F) || ((input_b()&&0x07)<<6) ); |
You are using logical operators when you should be using bitwise operators. |
|
|
vascotech88
Joined: 10 Mar 2009 Posts: 33 Location: Aveiro, Portugal / Lodz, Polska
|
|
Posted: Tue Mar 10, 2009 9:34 pm |
|
|
Thank you PCM programmer!
I solve that problem, but the PIC keeps looping in the same place.
Before i correct the error you've mentioned, the debug leds:
a0 (always on)
a1 (very fast flashing)
a2...a4 (always off)
Now, after i correct that error, the leds:
a0 (very fast flashing)
a1 (slow flashing around 4Hz~6Hz )
a2...a4 (still always off)
Now i think that when the program starts, it loops on WaitForBreak until a frame error is detected (a0 flashing on every loop), then it goes to WaitForStart, read another character from the USART, toggle the a1 led and see that there is always no frame_error and the value readed is always different from zero, so it loops to MainLoop and do the same thing all over again. Now I don't know what to do... Can you help me? Thank you! |
|
|
vascotech88
Joined: 10 Mar 2009 Posts: 33 Location: Aveiro, Portugal / Lodz, Polska
|
|
Posted: Tue Mar 10, 2009 10:04 pm |
|
|
I modified the code to solve the last problem, I don't know if it is correct. But it still doesn't work
Code: |
WaitForStart:
while(!input_state(pin_c7)){};
value=getc();
output_toggle(pin_a1);
if(value) goto MainLoop;
|
DEBUG LEDs:
a0 flash very fast
a1 flash at about 4~6Hz
a2...a4 still off |
|
|
vascotech88
Joined: 10 Mar 2009 Posts: 33 Location: Aveiro, Portugal / Lodz, Polska
|
|
Posted: Sun Mar 22, 2009 10:15 pm |
|
|
Anyone?? Please?... |
|
|
Guest
|
|
Posted: Wed May 27, 2009 5:54 am |
|
|
Hello,
I have the code copied from marquez and wanted to compile it.
Unfortunately CCS reports the following errors:
*** Error 48 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 113(16,20): Expecting a (
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 114(1,2): Expecting a declaration
*** Error 48 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 115(22,30): Expecting a (
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 115(42,43): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 115(42,43): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 116(13,14): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 117(1,5): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 118(6,7): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 119(13,15): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 119(16,17): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 119(17,18): Expecting a declaration
*** Error 48 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 119(18,22): Expecting a (
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 120(17,18): Expecting a declaration
*** Error 48 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 121(26,34): Expecting a (
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 121(28,29): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 121(29,30): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 122(1,3): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 122(3,4): Expecting a declaration
*** Error 48 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 122(4,18): Expecting a (
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 122(20,21): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 122(21,22): Expecting a declaration
*** Error 43 "J:\PICDEM 2 PLUS\DMX_Reciver.c" Line 123(17,18): Expecting a declaration
100 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Wed May 27 13:40:49 2009
can someone help me? |
|
|
vascotech88
Joined: 10 Mar 2009 Posts: 33 Location: Aveiro, Portugal / Lodz, Polska
|
|
Posted: Fri Sep 24, 2010 9:41 pm |
|
|
vascotech88 wrote: | Anyone?? Please?... |
Still nobody to help me? _________________ -----
Vasco Jose Dias Baptista
http://vascotech88.pt.vu/ |
|
|
|
|
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
|