Help on PicBasic Pro serial communication

Thread Starter

ChrisChemist116

Joined Mar 13, 2009
79
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

Rich (BB code):
INCLUDE "modedefs.bas"

DEFINE OSC 4
DEFINE ADC_BITS 10 ' A/D bits
DEFINE ADC_CLOCK 3 ' A/D internal RC clock
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in us

Tsample VAR byte ' Sampling time in sec
Mode VAR Byte ' Mode (C or F)
Dummy VAR Byte
D VAR Byte ' Temperature mode display

CMCON=7
RS232_out var GPIO.2
RS232_in var GPIO.1

CR CON 13 ' Carriage-return character
LF CON 10 ' Line-feed character

Res Var Word  
Temp1 Var Word  
TRISIO.1 = 1 ' GP0 (AN0) is input, GP2 = output, GP1 = input
PAUSE 1000
Again:
SEROUT RS232_out, T2400, [LF,CR, "Digital Thermometer RS232 Output"]
SEROUT RS232_out, T2400, [LF,CR, "=============================="]
Esample:
SEROUT RS232_out, T2400, [LF,LF,CR, "Enter sampling interval in seconds : "]
SERIN RS232_in, T2400, 5000, ESample, #TSample
SEROUT RS232_out, T2400, [#Tsample]
EMode:
SEROUT RS232_out, T2400, [LF,CR, "Degrees C (C) or degrees F (F) : "]
SERIN RS232_in, T2400, 5000, EMode, Mode
SEROUT RS232_out, T2400, [Mode]
Estart:
SEROUT RS232_out, T2400, [LF,CR, "Press ENTER to start..."]
SERIN RS232_in, T2400, 5000, Estart, Dummy
SEROUT RS232_out, T2400, [LF,CR]
TSample = TSample*1000 
ADCON0=%00000011
ANSEL=%000000001
More:
D = "C"
ADCIN 0, Res 
Temp1 = 48 * Res 
Temp1 = Temp1/100
IF Mode = "F" THEN 
Temp1 = Temp1 * 18
Temp1 = Temp1 + 320
Temp1 = Temp1 / 10
D = "F"
ENDIF
SEROUT RS232_out, T2400, [LF,CR, #Temp1, D]
PAUSE Tsample
GOTO More
END
 

ErnieM

Joined Apr 24, 2011
8,377
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.)
 

Thread Starter

ChrisChemist116

Joined Mar 13, 2009
79
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.)
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:
 

absf

Joined Dec 29, 2010
1,968
Try shifting these 2 lines....

Rich (BB code):
ADCON0=%00000011
ANSEL=%000000001
to

Rich (BB code):
Res Var Word  
Temp1 Var Word  
TRISIO.1 = 1 ' GP0 (AN0) is input, GP2 = output, GP1 = input
--------here---------------
Allen
 

Thread Starter

ChrisChemist116

Joined Mar 13, 2009
79
I simulated it on proteus and it works.
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.
 

absf

Joined Dec 29, 2010
1,968
Yes, I did get the same warning messages.

I tried to make

Rich (BB code):
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....

Tsample VAR byte ' Sampling time in sec
You defined Tsample as 8 bit var but
and somewhere in your program, it needs a 16 bit var to hold the value.

TSample = TSample*1000
Allen
 
Top