|
|
View previous topic :: View next topic |
Author |
Message |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Jul 01, 2014 8:59 am |
|
|
Hi,
anhphong208 wrote: |
...........the voltage is 5V on this pin........."LM35" is connected to AN0.... |
Now, that doesn't seem correct, does it??? You have some sort of a wiring or hardware problem! The LM35 is supposed to output 10mV per degree C. So, at 35C you should see about 0.35V (350mV), right? I know it's hot in Vietnam, but it's NOT that hot!! You need to check your circuit very carefully before continuing!
John |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Tue Jul 01, 2014 10:17 am |
|
|
ezflyr wrote: | Hi,
anhphong208 wrote: |
...........the voltage is 5V on this pin........."LM35" is connected to AN0.... |
Now, that doesn't seem correct, does it??? You have some sort of a wiring or hardware problem! The LM35 is supposed to output 10mV per degree C. So, at 35C you should see about 0.35V (350mV), right? I know it's hot in Vietnam, but it's NOT that hot!! You need to check your circuit very carefully before continuing!
John | .....................thank you very much.........................
...........I checked my circuit...you're right.......AN0 is about 0.35v......I supply for the LM35 is 5v............
...................................................................................................
can you check "#timer1?"........1 second timer overflow....set_timer(46004)??.......46004 is right??? _________________ thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Tue Jul 01, 2014 11:35 am |
|
|
Why set the timer?.
On the PIC30's, you can program the reset point for each timer. Setting the timer to a value is pointless on these chips. He is doing this for Timer2, but not for Timer1.... |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Tue Jul 01, 2014 12:32 pm |
|
|
Ttelmah wrote: | Why set the timer?.
On the PIC30's, you can program the reset point for each timer. Setting the timer to a value is pointless on these chips. He is doing this for Timer2, but not for Timer1.... |
............................................................................................
dspic30f4013 will receive sampling time (time_lay_mau) from PC ...
then sampling temperature (read ADC) and sent temperature values to PC............Sampling time can change.....................
........................................................................................................
so I set timer1 overflow after 1s....when timer1 overflow...(dem++)....until dem=time_lay_mau(sampling time)...is sampling temperature and sent temperature values to PC...........thanks..... _________________ thanks |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jul 02, 2014 7:18 am |
|
|
Hi,
Setting aside the timer issue for the moment, is the A/D actually working as expected? What numeric value is being returned? How are you converting the numeric A/D value to temperature? Are you getting the expected temperature values?
John |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Wed Jul 02, 2014 8:09 am |
|
|
ezflyr wrote: | Hi,
Setting aside the timer issue for the moment, is the A/D actually working as expected? What numeric value is being returned? How are you converting the numeric A/D value to temperature? Are you getting the expected temperature values?
John |
I am converting the numeric A/D value to temperature,:
Code: | tam=read_adc();
nhiet_do_do=tam*0.1221;
..................................................................................................
LM35....10mV-1oC...dspic có ADC=12..................
................temperature = (5.0*analogRead(A0)*100.0/4096.0);
.................................nhiet_do_do=read_adc()*0.1221 |
_________________ thanks |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Wed Jul 02, 2014 8:21 am |
|
|
ezflyr wrote: | Hi,
Setting aside the timer issue for the moment, is the A/D actually working as expected? What numeric value is being returned? How are you converting the numeric A/D value to temperature? Are you getting the expected temperature values?
John |
..................................................................................................
temperature values received:
yk = 14
uk = 250
yk = 15
uk = 250
yk = 13
uk is duty Pc sent to control.............
I am not getting the expected temperature values. it is very small....it isn't right.........
here is code
Code: |
#include <30F4013.h>
#device *=16 ADC=12
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NODEBUG
#use delay(clock=20000000)
#use rs232 (baud=9600, parity=N, xmit=pin_F3, rcv=pin_F2, bits = 8,Errors)
//===================KHAI BAO TONG===================
//===================================================
int trang_thai,nhan_tan_so_lay_mau;
int8 duty,nhiet_do_do,tam,dem,time_lay_mau;
int1 New_Duty_Ready=False,Read_Analog_Ready=False;
//===================================================
//===================================================
void init_port()
{
set_tris_b(0x01);
set_tris_d(0x00);
ENABLE_INTERRUPTS(int_rda);
ENABLE_INTERRUPTS(GLOBAL);
delay_ms(100);
SETUP_ADC(ADC_CLOCK_INTERNAL); //khai bao ti hieu analock
SETUP_ADC_PORTS(sAN0); //khai bao post doc du lieu.
SET_ADC_CHANNEL(0);
delay_ms(100);
}
//================CHUONG TRINH RS232=================
//===================================================
#int_rda
void rad_isr ()
{
int data;
data = getc();
switch (data)
{
case 's': //253
{
trang_thai=0;
duty=0;
disable_interrupts(INT_TIMER1);
printf("s");
break;
}
case 'a': //255
{
printf("a");
break;
}
case 'b': //254
{
trang_thai=1;
enable_interrupts(INT_TIMER1);
setup_timer1(TMR_DIV_BY_1 | TMR_INTERNAL);
break;
}
case 'c': //252
{
nhan_tan_so_lay_mau=1;
printf("c");
break;
}
default:
if (trang_thai == 1)
{
duty = data;
New_Duty_Ready = True;
}
if (nhan_tan_so_lay_mau == 1)
{
time_lay_mau = data;
nhan_tan_so_lay_mau =0;
printf("f");
}
break;
}
}
#INT_TIMER1
void ngattimer()
{
set_timer1(46004); // tran 1ms
dem++;
if(dem==time_lay_mau)
{
Read_Analog_Ready=True;
dem=0;
}
}
void main()
{
init_port();
duty=0;
///continuous pulse modulation at RD0
SETUP_TIMER2(TMR_INTERNAL | TMR_DIV_BY_1,0xFFC0); //f =76hz
SETUP_COMPARE(1,COMPARE_PWM|COMPARE_TIMER2);
delay_us(30);
while(true)
{
if(New_Duty_Ready)
{
SET_PWM_DUTY(1,duty*64);
New_Duty_Ready = False;
}
if(Read_Analog_Ready)
{
tam=read_adc();
nhiet_do_do=tam*0.1221;
putc(nhiet_do_do);
Read_Analog_Ready=False;
}
}
} | [/quote] _________________ thanks |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jul 02, 2014 10:19 am |
|
|
Hi,
You've got to learn to troubleshoot. I've been helping you along the way with the hopes that you would do more and I would do less. So far that isn't happening. I understand the language issues, but regardless this forum is not intended to spoon feed you at every step of your program.....
I asked you what the numeric value is that is being returned by the A/D converter. I *know* you are converting to temperature, but you are jumping too far ahead. You must verify the basics first by validating what the A/D converter is returning!
Your temperature measurement code has a lot of problems. The primary problem is that all your variables are 8 bit (int8), when you really need larger ones (int16 or int32).... Also, you are using 'putc' to display the result. That is going to take whatever you've got and truncate it into an 8 bit result.....
Add this to your code:
Code: |
int16 tam = 0; //this needs to be a 16 bit variable to utilize the full resolution of the A/D
tam=read_adc();
printf("A/D Numeric Result: %Lu\n\r", tam); //add this line after you read the A/D
|
So, what numeric value do you read on the A/D? What is the applied voltage on pin AN0? Based on the applied voltage does the numeric value make sense? Is the numeric value steady?
John |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Wed Jul 02, 2014 11:44 am |
|
|
ezflyr wrote: | Hi,
You've got to learn to troubleshoot. I've been helping you along the way with the hopes that you would do more and I would do less. So far that isn't happening. I understand the language issues, but regardless this forum is not intended to spoon feed you at every step of your program.....
I asked you what the numeric value is that is being returned by the A/D converter. I *know* you are converting to temperature, but you are jumping too far ahead. You must verify the basics first by validating what the A/D converter is returning!
Your temperature measurement code has a lot of problems. The primary problem is that all your variables are 8 bit (int8), when you really need larger ones (int16 or int32).... Also, you are using 'putc' to display the result. That is going to take whatever you've got and truncate it into an 8 bit result.....
Add this to your code:
Code: |
int16 tam = 0; //this needs to be a 16 bit variable to utilize the full resolution of the A/D
tam=read_adc();
printf("A/D Numeric Result: %Lu\n\r", tam); //add this line after you read the A/D
|
So, what numeric value do you read on the A/D? What is the applied voltage on pin AN0? Based on the applied voltage does the numeric value make sense? Is the numeric value steady?
John | ...............................................................
what numeric value do you read on the A/D?
yk = 101
yk = 114
yk = 105
.......................................................................................
What is the applied voltage on pin AN0? 0v (set_tris_b(0x01)). the Pin AN0 is input.....................
........................................................................................................
Is the numeric value steady?............yes... _________________ thanks |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jul 02, 2014 11:58 am |
|
|
Hi,
I think I'm going to give up on this thread. The first time I asked what was the voltage being applied to AN0, you said '5V', and it was supplied by an LM35. I pointed out that this was most likely a hardware error, and it should really be 0.35V or thereabouts...... You came back and agreed that the value really was 0.35V. Now, the voltage is suddenly '0V'. Personally, I don't think you have any concept of troubleshooting or problem solving, or working in a step-by-step linear manner to solve problems. This is a issue that transcends the language difficulty, it's just the way you approach problems in general. Rather, you seem to be all over the place with what you are trying to do - one step forward, and two steps back for no good reason at all. I gave it my best shot, but I'm throwing in the towel. Perhaps there are others here that may want to help?
Good Luck,
John |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Wed Jul 02, 2014 12:06 pm |
|
|
ezflyr wrote: | Hi,
I think I'm going to give up on this thread. The first time I asked what was the voltage being applied to AN0, you said '5V', and it was supplied by an LM35. I pointed out that this was most likely a hardware error, and it should really be 0.35V or thereabouts...... You came back and agreed that the value really was 0.35V. Now, the voltage is suddenly '0V'. Personally, I don't think you have any concept of troubleshooting or problem solving, or working in a step-by-step linear manner to solve problems. This is a issue that transcends the language difficulty, it's just the way you approach problems in general. Rather, you seem to be all over the place with what you are trying to do - one step forward, and two steps back for no good reason at all. I gave it my best shot, but I'm throwing in the towel. Perhaps there are others here that may want to help?
Good Luck,
John |
.............................................................................................
I am sorry...thanks you very much..........5v power supply for the LM35......If I connect the LM35 in AN0 pin voltage 0.35 ........
if I do not connect LM35, AN0 is 0v. _________________ thanks |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Wed Jul 02, 2014 12:11 pm |
|
|
ezflyr wrote: | Hi,
I think I'm going to give up on this thread. The first time I asked what was the voltage being applied to AN0, you said '5V', and it was supplied by an LM35. I pointed out that this was most likely a hardware error, and it should really be 0.35V or thereabouts...... You came back and agreed that the value really was 0.35V. Now, the voltage is suddenly '0V'. Personally, I don't think you have any concept of troubleshooting or problem solving, or working in a step-by-step linear manner to solve problems. This is a issue that transcends the language difficulty, it's just the way you approach problems in general. Rather, you seem to be all over the place with what you are trying to do - one step forward, and two steps back for no good reason at all. I gave it my best shot, but I'm throwing in the towel. Perhaps there are others here that may want to help?
Good Luck,
John |
.................................................I am sorry...I I understand the right not to answer you .... so wrong ................
...............................................
I connect the LM35 in AN0 pin voltage 0.35 ........ _________________ thanks |
|
|
anhphong208
Joined: 23 Jun 2014 Posts: 29 Location: viet nam
|
|
Posted: Thu Jul 03, 2014 7:15 am |
|
|
ezflyr wrote: | Hi,
I think I'm going to give up on this thread. The first time I asked what was the voltage being applied to AN0, you said '5V', and it was supplied by an LM35. I pointed out that this was most likely a hardware error, and it should really be 0.35V or thereabouts...... You came back and agreed that the value really was 0.35V. Now, the voltage is suddenly '0V'. Personally, I don't think you have any concept of troubleshooting or problem solving, or working in a step-by-step linear manner to solve problems. This is a issue that transcends the language difficulty, it's just the way you approach problems in general. Rather, you seem to be all over the place with what you are trying to do - one step forward, and two steps back for no good reason at all. I gave it my best shot, but I'm throwing in the towel. Perhaps there are others here that may want to help?
.........................................thanks you very much..........I slove problem
Good Luck,
John |
_________________ thanks |
|
|
|
|
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
|