View previous topic :: View next topic |
Author |
Message |
atai21
Joined: 30 Dec 2010 Posts: 31
|
comment on work |
Posted: Thu Apr 14, 2011 10:39 pm |
|
|
hello all,
I'm planning to do the data logger for current, voltage, irradiation and temperature for my solar PV module. I have create the schematic using Altium and the code for it but not yet tested it. Can anybody give a comment for my work so that I won't make any mistake when I start developing the hardware. Thank you very much. Further info, the temperature sensor is DS18B20, voltage sensor is LV25, current sensor is LA55 and irradiation sensor is PY66625.
http://www.2shared.com/photo/DAC2YeBm/Capture.html
Code: | #include <18F4550.h>
#device *=16
#device adc=8
#define BPW21R PIN_AN0
#define LV25 PIN_AN3
#define LA55 PIN_AN2
#use delay(clock=20000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, invert)
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES PUT //Power Up Timer
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOPROTECT //Code not protected from reading
void main()
{
int16 adc_value;
float volts;
setup_adc_ports(AN0);
setup_adc_ports(AN3);
setup_adc_ports(AN2);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(20);
set_adc_channel(1);
delay_us(20);
set_adc_channel(2);
delay_us(20);
while(1)
{
result = read_adc(AN0);
printf ("\n");
// put equation later
delay_ms(50);
result = read_adc(AN3);
printf ("\n");
delay_ms(50);
result = read_adc(AN2);
printf ("\n");
delay_ms(50);
}
}
#define DQ PIN_B0 // One Wire Bus pin assignment
#define LED PIN_B2 // Status LED
// Software usart will be used with "invert" option.
// so direct connect without interfaces to PC is available
|
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Apr 15, 2011 5:19 am |
|
|
1) always add 'erors' to the use rs232(..) options...
2) # device *=16 , don't think you need it with 18 series PICs
3) setup_adc_ports(AN0 | AN2 | AN3);
I think what you have done will only allows the last AN pin to be set, the onscreen manual( F11) will explain.
4)To access the ADC you
a) select the desired pin(set_adc_channel(1);) NOT ...channel(AN0)
b) delay a few useconds(delay_us(20);)
c) read the result ( answer=read_adc(); )
ADC has either 8 bit or 10 bit mode, the default is 8 bit.
just a start for you...
look at the examples CCS kindly gives in the examples folder as well as the onscreen help (F11). |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Fri Apr 15, 2011 6:27 am |
|
|
There is another problem here.
'Invert' is not supported on the hardware UART. Hence a software UART _will_ be used. ERRORS won't then do anything worthwhile.
'Direct connection without interface'. No. You _still_ need a minimum of a input voltage limiting resistor, and clamp diodes. Reliability for anything over a very short connection will be poor, and is _not_ guaranteed to work with all input ports. It doesn't actually 'meet' the RS232 requirements, but often "get's away" with this...
Re-think this. If you want this to really work, with anything approaching reliability, look either adding a proper MAX232, or a simple circuit to provide the inversion and voltage shifting. Then add ERRORS....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 15, 2011 1:42 pm |
|
|
If you do want to use the cheap RS-232 connection (without the Max232),
make sure that you use the series resistor between the PIC's Rx pin
and the PC's Tx pin. This thread explains it:
http://www.ccsinfo.com/forum/viewtopic.php?t=38314
Normally this method is only done for quick debugging on a PIC board
that doesn't have a Max232 on it. At least, that's the only time I ever do it.
This one shows a photo. He also has a 470 ohm resistor on the PIC's Tx
pin. I don't think that's needed.
http://www.romanblack.com/bitbangserial.htm
The 22K resistor is also shown on page 12 of this document, in a little
circled inset. It's shown as a substitute for an MC1489.
http://www.tech-tools.com/files/picapp.pdf |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Fri Apr 15, 2011 3:00 pm |
|
|
You can also use a MAX488 to substiute for a MAX232 and 4 caps. Takes up less room, fewer pins, no caps needed but costs a little more. |
|
![](templates/subSilver/images/spacer.gif) |
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Sun Apr 17, 2011 10:45 pm |
|
|
thank you all...i will take notes and post here when i finish setup the hardware. ![Wink](images/smiles/icon_wink.gif) |
|
![](templates/subSilver/images/spacer.gif) |
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Wed May 18, 2011 1:47 am |
|
|
hello again all,
i've done a little bit modification with the circuit and code but i have no idea on how to send the reading from LA55, LV25 and BPW21R to rs 232...please help
Code: | #include <18F4550.h>
#device adc=8
#define BPW21R PIN_A2
#define LV25 PIN_A0
#define LA55 PIN_A1
#FUSES NOWDT, HS, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
#include<1wire.c>
#include<ds1820.c>
void main()
{
float temperature;
int16 adc_value;
float volts;
setup_adc_ports(0);
setup_adc_ports(1);
setup_adc_ports(2);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(20);
read_adc(0);
set_adc_channel(1);
delay_us(20);
read_adc(1);
set_adc_channel(2);
delay_us(20);
read_adc(2);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
while (1)
temperature = ds1820_read();
printf("Temperature= %3.1f\n\r",temperature);
delay_ms (1000);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Wed May 18, 2011 5:59 am |
|
|
Look in the 18F4550.h file for the proper setup_adc_ports() parameters.
You are performing a read_adc() and not assigning it to anything. The
proper format is value=read_adc(x).
I would suggest you read at the manual and follow the examples given for
both of the above items. _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Wed May 18, 2011 6:35 am |
|
|
Code: | setup_adc_ports(0);
setup_adc_ports(1);
setup_adc_ports(2);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
delay_us(20);
value=read_adc(0)
set_adc_channel(1);
delay_us(20);
value=read_adc(1)
set_adc_channel(2);
delay_us(20);
value=read_adc(2)
|
you mean like this?but the error come out say:
*** Error 12 "main.c" Line 29(1,6): Undefined identifier value
*** Error 12 "main.c" Line 32(1,6): Undefined identifier value
*** Error 12 "main.c" Line 35(1,6): Undefined identifier value
3 Errors, 0 Warnings. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Wed May 18, 2011 7:11 am |
|
|
hmm...
value=read_adc(0)
value=read_adc(1)
value=read_adc(2)
Undefined identifier value
Undefined identifier value
Undefined identifier value
...maybe because you didn't declare 'value' as a variable like you did
int16 adc_value;
at top of main().. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 18, 2011 12:00 pm |
|
|
You were told to fix this 2 times. You should do that, or people will stop
trying to help you.
Quote: | void main()
{
float temperature;
int16 adc_value;
float volts;
setup_adc_ports(0);
setup_adc_ports(1);
setup_adc_ports(2);
|
|
|
![](templates/subSilver/images/spacer.gif) |
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Thu May 19, 2011 7:10 pm |
|
|
Code: | #include <18F4550.h>
#device adc=8
#define BPW21R PIN_A2
#define LV25 PIN_A0
#define LA55 PIN_A1
#FUSES NOWDT, HS, PUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,)
#include<1wire.c>
#include<ds1820.c>
void main()
{
int16 LA55_res,LV25_res,BPW21R_res;
float temperature;
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(VREF_LOW|-2);
while (1)
temperature = ds1820_read();
printf("Temperature= %3.1f\n\r",temperature);
delay_ms (1000);
set_adc_channel(0);
LV25_res =read_adc();
printf("Voltage= %2.1f\n\r",LV25);
delay_ms(1000);
set_adc_channel(1);
LA55_res =read_adc();
printf("Current= %2.1f\n\r",LA55);
delay_ms(1000);
set_adc_channel(2);
BPW21R_res =read_adc();
printf("Irradiation= %2.1f\n\r",BPW21R);
delay_ms(1000);
} |
i'm sorry but this time i have delete it..sorry
i try to build my code but it gives error like this:
** Error 114 "main.c" Line 40(33,34): Printf format type is invalid ::
*** Error 114 "main.c" Line 45(33,34): Printf format type is invalid ::
*** Error 114 "main.c" Line 50(39,40): Printf format type is invalid ::
3 Errors, 1 Warnings. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Thu May 19, 2011 7:24 pm |
|
|
Quote: | printf("Voltage= %2.1f\n\r",LV25); |
%2.1f tells printf the variable you specified is a float.
You actually used a define instead of the variable you intended which is an int16, not a float. _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Thu May 19, 2011 8:18 pm |
|
|
thanks dyeatman |
|
![](templates/subSilver/images/spacer.gif) |
|