PDA

View Full Version : syntax error



malc-c
- 20th February 2010, 18:32
Hi,

I'm trying to use 4 pots to provide a range of values to set the temperature set point in the code featured http://www.picbasic.co.uk/forum/showthread.php?t=12712

When I use the following code I get a bad expression syntax error on the SetPoint(ADchan) = POTS(ADchan) line



FOR ADchan = 0 to 3
GOSUB GetADC
POTS(ADchan) = ADvalue
SetPoint(ADchan) = POTS(ADchan)
NEXT ADchan


My logic seems that it gets the adc value, places that in the POTS(0), POTS(1) etc, and then should give SetPoint(0) the same value as POTS(0)

All I really need is a range between 100 and 500 for each SetPoint

Archangel
- 20th February 2010, 18:56
Hi,

I'm trying to use 4 pots to provide a range of values to set the temperature set point in the code featured http://www.picbasic.co.uk/forum/showthread.php?t=12712

When I use the following code I get a bad expression syntax error on the SetPoint(ADchan) = POTS(ADchan) line



FOR ADchan = 0 to 3
GOSUB GetADC
POTS(ADchan) = ADvalue
SetPoint(ADchan) = POTS(ADchan)
NEXT ADchan


My logic seems that it gets the adc value, places that in the POTS(0), POTS(1) etc, and then should give SetPoint(0) the same value as POTS(0)

All I really need is a range between 100 and 500 for each SetPoint
Have you tried [square] brackets ?

Darrel Taylor
- 20th February 2010, 19:08
Hi Malc,

Use ...

Setpoints(ADchan)
<br>

Archangel
- 20th February 2010, 19:25
Hi Malc,

Use ...

Setpoints(ADchan)
<br>Hmmm . . . so (ADchan) is a MATH :eek: operation ? I thought it was an array, if it is, then (brackets) are OK ?

malc-c
- 20th February 2010, 19:35
Hi Malc,

Use ...

Setpoints(ADchan)
<br>


How the hell did I miss that !

Now just got to work out how to get the value with in the range !

Thanks once again Darrel

Archangel
- 20th February 2010, 19:45
How the hell did I miss that !

Now just got to work out how to get the value with in the range !

Thanks once again DarrelHi Malc, I would say pretty darn easy, given the size of this program, I just un zipped it, nice work ! To all involved.

malc-c
- 20th February 2010, 19:57
Thanks, but really the credit for the coding goes to Darrel.

I'm still a rookie in PBP, and it's taking me hours to try and work this out and I'm still having trouble getting the value from the pot to change the set temperature

malc-c
- 20th February 2010, 20:20
Still need help (Darrel ??)



FOR ADchan = 0 to 3
GOSUB GetADC
pots(ADchan) = ADvalue
SetPoints(ADchan) = (Advalue / 100)
if SetPoints(ADchan) <200 then SetPoints(ADchan) = 200
if SetPoints(ADchan) >500 then SetPoints(ADchan) = 500
NEXT ADchan


and



LCDOUT $FE,$C0, DEC pots(0)>>1," "


Gives a value on the LCD of between 1 and 8184 as the pot is turned from one extreme to the other

however


LCDOUT $FE,$C0, DEC SetPoints(0)>>1," "


Gives a static number, of 100 regardless of what position the pot is set to

I would also like to know what to change to get the PC display to show the value of the setpoints - it still remains the same value (26 degrees) set by EE_setpoint value in the initial stages even though I've changed the setmode to manual

malc-c
- 20th February 2010, 20:51
Managed to get this part to work.



FOR ADchan = 0 to 3
GOSUB GetADC
pots(ADchan) = ADvalue/10
SetPoints(ADchan) = pots(ADchan)
if SetPoints(ADchan) <200 then SetPoints(ADchan) = 200
if SetPoints(ADchan) >500 then SetPoints(ADchan) = 500
LCDOUT $FE,$C0, dec pots(0)>>1," "


Now get a value between 0 and 818 when the pot is moved

Darrel Taylor
- 20th February 2010, 21:00
Uno Momento por favor ...

Are you using 14-bit?
<br>

malc-c
- 20th February 2010, 21:14
Maybe I jumped to soon...

strange thing is that whist the lcd is showing a value of 71, which I would assume would give a set point of 7.1 degree, the value on the PC is showing as 14.3 :confused:

malc-c
- 20th February 2010, 21:17
Uno Momento por favor ...

Are you using 14-bit?
<br>

Sorry ?

I'm using the code for the 16F877 we worked on, basically just wanting to sort the analogue pots and menus out.



DEFINE ADC_BITS 10 ' Set-up ADC for fastest 10-bit results
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 5
INCLUDE "DT_Analog.pbp"

MaxSetPoint CON 500 ' Pot fully clockwise
MinSetPoint CON 100 ' Pot fully counter clockwise
ADbits = 14 ' set A/D resolution to 14-bits
CMCON = 7 ' disable Comparators
ADCON1 = %10000010 ' AN0-4 Analog, Right justify

Darrel Taylor
- 20th February 2010, 21:39
I think this should do it.
Set ADchan before GOSUBing ...

Result VAR WORD

GetSetpoint:
GOSUB GetADC
Result = ADvalue*(MaxSetPoint - MinSetPoint)
Result = (DIV32 ADmax) + MinSetPoint
Setpoints(ADchan) = Result
RETURN


hth,

malc-c
- 20th February 2010, 22:04
Darrel, I've tried you code, may not of put it in the right place



Main:
FOR pid_Channel = 0 TO 3 ; cycle thru all sensors
GOSUB SelectSensor
GIE = 0 ; disable interrupts before 1-wire
@ DS1820_Convert ; start a temperature conversion
GIE = 1 ; enable interrupts after 1-wire
NEXT pid_Channel

Result VAR WORD

GetSetpoint:
FOR ADchan = 0 to 3
GOSUB GetADC
Result = ADvalue*(MaxSetPoint - MinSetPoint)
Result = (DIV32 ADmax) + MinSetPoint
Setpoints(ADchan) = Result
LCDOUT $FE,$C0, dec setpoints(0)>>1," "
NEXT ADchan


but the set point displayed in hyper terminal is still twice the value shown on the lcd.

Darrel Taylor
- 20th February 2010, 22:20
LCDOUT $FE,$C0, DEC setpoints(0)/10,".",DEC1 setpoints(0)//10

malc-c
- 20th February 2010, 22:43
LCDOUT $FE,$C0, DEC setpoints(0)/10,".",DEC1 setpoints(0)//10

Thanks.

I tried changing the results value (dividing by 2 and then multiplying by 2) to no avail.

How does dividing by 10 work out then ? If the result value was giving me a setpoints value of 100, but it was displaying 20.0 on the screen, dividing 100/10 gives 10 which would equate to 1.0 degree ??

Just can't get my head round this... maybe I've been at it too long... or had too many glasses of wine !

Darrel Taylor
- 20th February 2010, 23:42
value = 100
value / 10 = 10
value // 10 = 0

DEC value /10,".",DEC1 value//10 = "10.0"<hr>
value = 342
value / 10 = 34
value // 10 = 2

DEC value /10,".",DEC1 value//10 = "34.2"
<br>

malc-c
- 21st February 2010, 09:21
Cheers DT !

malc-c
- 21st February 2010, 21:06
Guys,

Is A/D handled different in an 18F4550 to a 16F877A ?

The development of the 4ch PID thermostat with Darrel got as far as porting the original code to a 18F4550 (mainly as it has a lot more code space). I've copied over the A/D from the 16F code



;----[Analog Settings]------------------------------------------------------
DEFINE ADC_BITS 10 ' Set-up ADC for fastest 10-bit results
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 5
INCLUDE "DT_Analog.pbp"

MaxSetPoint CON 350 ' Pot fully clockwise
MinSetPoint CON 100 ' Pot fully counter clockwise
ADbits = 14 ' set A/D resolution to 14-bits
CMCON = 7 ' disable Comparators
ADCON1 = %10000010 ' AN0-4 Analog, Right justify
ADCON1 = $0F


And have the same routine for using the value to set the set point


GetSetpoint:
FOR ADchan = 0 to 3
GOSUB GetADC
Result = ADvalue*(MaxSetPoint - MinSetPoint)
Result = (DIV32 ADmax) + MinSetPoint
Setpoints(ADchan) = Result
NEXT ADchan


But when viewed on the PC via Hyperterminal the set point is either 10 or 110.

I've tried changing the two values for minsetpoint and maxsetpoint to no avail.