Help on PicBasic Pro serial communication

Discussion in 'Embedded Systems and Microcontrollers' started by ChrisChemist116, Dec 3, 2012.

  1. ChrisChemist116

    Thread Starter Active Member

    Mar 13, 2009
    78
    1
    Hello,

    i've been trying to work on this code for PIC12F675. Its pretty simple. It takes ADC signal on GP0 (LM35 temperature) and then sends it to the computer via GP1 and GP2 ports. The user is to be told to write the sampling time and the scale on serial communication to the computer.

    Here's the problem, i get the message displayed but it just freezes when i should write the sampling time. What's wrong?. Can anybody help me to debug it?.

    My version of PicBasic Pro is 2.60A

    Code ( (Unknown Language)):
    1. INCLUDE "modedefs.bas"
    2.  
    3. DEFINE OSC 4
    4. DEFINE ADC_BITS 10 ' A/D bits
    5. DEFINE ADC_CLOCK 3 ' A/D internal RC clock
    6. DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    7.  
    8. Tsample VAR byte ' Sampling time in sec
    9. Mode VAR Byte ' Mode (C or F)
    10. Dummy VAR Byte
    11. D VAR Byte ' Temperature mode display
    12.  
    13. CMCON=7
    14. RS232_out var GPIO.2
    15. RS232_in var GPIO.1
    16.  
    17. CR CON 13 ' Carriage-return character
    18. LF CON 10 ' Line-feed character
    19.  
    20. Res Var Word  
    21. Temp1 Var Word  
    22. TRISIO.1 = 1 ' GP0 (AN0) is input, GP2 = output, GP1 = input
    23. PAUSE 1000
    24. Again:
    25. SEROUT RS232_out, T2400, [LF,CR, "Digital Thermometer RS232 Output"]
    26. SEROUT RS232_out, T2400, [LF,CR, "=============================="]
    27. Esample:
    28. SEROUT RS232_out, T2400, [LF,LF,CR, "Enter sampling interval in seconds : "]
    29. SERIN RS232_in, T2400, 5000, ESample, #TSample
    30. SEROUT RS232_out, T2400, [#Tsample]
    31. EMode:
    32. SEROUT RS232_out, T2400, [LF,CR, "Degrees C (C) or degrees F (F) : "]
    33. SERIN RS232_in, T2400, 5000, EMode, Mode
    34. SEROUT RS232_out, T2400, [Mode]
    35. Estart:
    36. SEROUT RS232_out, T2400, [LF,CR, "Press ENTER to start..."]
    37. SERIN RS232_in, T2400, 5000, Estart, Dummy
    38. SEROUT RS232_out, T2400, [LF,CR]
    39. TSample = TSample*1000
    40. ADCON0=%00000011
    41. ANSEL=%000000001
    42. More:
    43. D = "C"
    44. ADCIN 0, Res
    45. Temp1 = 48 * Res
    46. Temp1 = Temp1/100
    47. IF Mode = "F" THEN
    48. Temp1 = Temp1 * 18
    49. Temp1 = Temp1 + 320
    50. Temp1 = Temp1 / 10
    51. D = "F"
    52. ENDIF
    53. SEROUT RS232_out, T2400, [LF,CR, #Temp1, D]
    54. PAUSE Tsample
    55. GOTO More
    56. END
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    It's been years since I used PICbasic. I don't remember it having any in circuit debug facility so it's very unfriendly to use, besides other problems such as reporting successful compilation of bad code (loaded but would not run).

    The line:
    TRISIO.1 = 1 ' GP0 (AN0) is input, GP2 = output, GP1 = input

    does not do the action it's comment implies.

    At the problem line why do you SERIN #TSample instead of just TSample? (I could find no listing for what # does in PICbasic, since their web page is non-searchable.)
     
  3. ChrisChemist116

    Thread Starter Active Member

    Mar 13, 2009
    78
    1
    It is alright. The comment is meaningless. In other words it tells the register basically GP1 is input. On lines below is put clear through ANSEL and ADCON GP0 is input as well. I dont think that would be the problem.

    Okay, the following is an excerpt from PBP help file If variable is preceded by a pound sign ( # ), SERIN converts a decimal value in ASCII and stores the result in that variable.

    That being said, Do you guys have any clue? :confused:
     
  4. absf

    Senior Member

    Dec 29, 2010
    1,493
    373
    Try shifting these 2 lines....

    Code ( (Unknown Language)):
    1. ADCON0=%00000011
    2. ANSEL=%000000001
    to

    Code ( (Unknown Language)):
    1. Res Var Word  
    2. Temp1 Var Word  
    3. TRISIO.1 = 1 ' GP0 (AN0) is input, GP2 = output, GP1 = input
    4. --------here---------------
    5.  
    Allen
     
  5. absf

    Senior Member

    Dec 29, 2010
    1,493
    373
    I simulated it on proteus and it works.
     
    ChrisChemist116 likes this.
  6. ChrisChemist116

    Thread Starter Active Member

    Mar 13, 2009
    78
    1
    Thanks i did the change and now it works. By the way, i got two warning messages on Proteus telling me this, do you also experience these issues?

    ADC conversion clock period (5e-07) is possibly invalid for device clock frequency. ADC conversion started before 'wait' time has expired following previous conversion or channel change.
     
  7. absf

    Senior Member

    Dec 29, 2010
    1,493
    373
    Yes, I did get the same warning messages.

    I tried to make

    Code ( (Unknown Language)):
    1. DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us
    higher but it didnt solve the problem.

    I also played with the values of ADCS<2:0> in ANSEL and that also didnt stop the message.

    "5e-07" is 500nS but with the PIC running at 4MHz, may be the ADC cannot operate fast enough (just guessing). Does it work on real hardware?

    I also spotted a minor mistake in your program....

    You defined Tsample as 8 bit var but
    and somewhere in your program, it needs a 16 bit var to hold the value.

    Allen
     
Loading...