• AVR Freaks

Hot!MCP9700 and PIC16F15313

Author
Andrea_Grosso82
New Member
  • Total Posts : 3
  • Reward points : 0
  • Joined: 2020/01/22 05:17:31
  • Location: 0
  • Status: offline
2021/03/05 10:44:16 (permalink)
0

MCP9700 and PIC16F15313

Hello everybody, 
 
I wrote a program for the PIC16F15313 that has to read an analog value (voltage) from the temperature sensor MCP9700.
The program has to read every 2 seconds temperature and if the temperature is higher than 25 has to turn on a led.
Build the project gave me a positive result (Build succeful).
I can flash without problems the PIC, but seems is not working.
 
Attached you can find the software
I think the problem is the way to assign the variables.
I have to assign all integers because if I tried to assign a float variable I received an error message because I used too much memory. Using the integer does not allow me to manage numbers with the dot.
 
Please let me know where I did wrong.
 
 
#1

4 Replies Related Threads

    ric
    Super Member
    • Total Posts : 30244
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCP9700 and PIC16F15313 2021/03/05 14:19:18 (permalink)
    0
    You are trying to work in volts, which is not going to work without float because the V variable can only be 0, 1, 2, 3, 4, or 5.
    Just swap to using millivolts so you can represent fractions of a volt with integers.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    ric
    Super Member
    • Total Posts : 30244
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCP9700 and PIC16F15313 2021/03/05 15:09:32 (permalink)
    0
    Here's your code
       int Temperatura(void) {
           unsigned short Val_camp;
           int T;
           int V;
           ADC_SelectChannel(Temp);
           ADC_StartConversion();
           ADC_IsConversionDone();
           ADC_GetConversionResult();
           Val_camp = ADC_GetConversion(Temp);
           ADC_TemperatureAcquisitionDelay();
           V = ((Val_camp*5)/1024);
           T = (((V*1000)-500)/10);
           return T;
       }

    I'm curious whyt you used "unsigned short" (same as "unsigned int") for one variable, but "int" for the others.
    "T" is the only  variable that could go negative.
     
    Floating point variables do use a bit of extra code to calculate with (and are slower), but it is trying to use printf() or sprintf() on them that generates lots more code.
     
    post edited by ric - 2021/03/05 15:13:43

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    Andrea_Grosso82
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2020/01/22 05:17:31
    • Location: 0
    • Status: offline
    Re: MCP9700 and PIC16F15313 2021/03/06 07:27:18 (permalink)
    0
    Thank you for your replies.
    1 - I tried to convert everything from V to mV
    2 - The reason because I used this configuration with the variable is that I do not receive any warning during the phase to build the project.
     
    I tested the program in C adding the GUI in order to introduce manual the values to check if the formulas and the math were correct and it is working, but not when I transfer it to the pic. 
     
    I'm still not having the led turns on when the temperature is higher than 25.
     
    I tried to debug the software with MPLAB and the PICkit4 because I want to read how is the value of the analogue input but I'm still receiving an error from the software.
     
    I cannot find anything on internet
     
    #4
    ric
    Super Member
    • Total Posts : 30244
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCP9700 and PIC16F15313 2021/03/06 23:08:59 (permalink)
    0
    Andrea_Grosso82
    2 - The reason because I used this configuration with the variable is that I do not receive any warning during the phase to build the project.

    What sort of warning did you expect?
    The compiler warns about syntax errors, not bad algorithms.

    I tested the program in C adding the GUI in order to introduce manual the values to check if the formulas and the math were correct and it is working, but not when I transfer it to the pic.

    Sorry, I do not understand what yo uare trying to say.

    I'm still not having the led turns on when the temperature is higher than 25.

    You have not shown us what changes you have made, so I cannot comment if you have done it correctly.
     

    I tried to debug the software with MPLAB and the PICkit4 because I want to read how is the value of the analogue input but I'm still receiving an error from the software.

    What error?

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    Jump to:
    © 2021 APG vNext Commercial Version 4.5