PDA

View Full Version : If...then...else



mikebike
- 16th September 2010, 12:33
Why do I get a Syntax Error for the ELSE row?

loop2:
ADCIN 0, involt 'Read channel 0 to involt
PAUSE 100 'Wait 100 ms
IF involt >= 128 THEN GPIO.5 = 0
ELSE GPIO.5 = 1 ENDIF
GOTO loop2
END

PIC12F683 & PBP2.60

mackrackit
- 16th September 2010, 12:44
ELSE likes to be on a line of it's own.
Try


loop2:
ADCIN 0, involt 'Read channel 0 to involt
PAUSE 100 'Wait 100 ms
IF involt >= 128 THEN GPIO.5 = 0
ELSE
GPIO.5 = 1
ENDIF
GOTO loop2
END

mikebike
- 16th September 2010, 13:15
ELSE likes to be on a line of it's own.

No, didn't help:

ERROR Line 30: ELSE without a matching IF..THEN. (ADC1.pbp)
ERROR Line 32: ENDIF without a matching IF..THEN. (ADC1.pbp)

That would suggest that they should all be on the same row, but that was my first attempt.

Acetronics2
- 16th September 2010, 13:18
No, didn't help:

ERROR Line 30: ELSE without a matching IF..THEN. (ADC1.pbp)
ERROR Line 32: ENDIF without a matching IF..THEN. (ADC1.pbp)

That would suggest that they should all be on the same row, but that was my first attempt.


loop2:
ADCIN 0, involt 'Read channel 0 to involt
PAUSE 100 'Wait 100 ms

IF involt >= 128 THEN
GPIO.5 = 0
ELSE
GPIO.5 = 1
ENDIF

GOTO loop2
END


Alain

mikebike
- 16th September 2010, 14:00
Thanks, that worked. But why?

mackrackit
- 16th September 2010, 14:50
IF xxx THEN label
can be on one line because it act as a GOTO.
If not a label the THEN needs to be on a second line.
YUP, I messed up on my first post. Was not paying attention...

Acetronics2
- 16th September 2010, 14:51
Thanks, that worked. But why?

simply because the compiler considers there's no need for ELSE nor ENDIF, if he sees anything on the right side of THEN ... :rolleyes:

Alain

mikebike
- 16th September 2010, 15:04
There is a lot to think of......

But my very first program works just fine now! :)

One LED blinks every second and goes on continously after 9 minutes.
Another LED goes on when the voltage drops below 2.5 Volts....

B.t.w. I understand that there is a calibration factor inside each PIC that shall/could be used to get better clock accuracy.
Is the PBP using this automatically?
My 9 minute timer is accurate within 1 second (two different PICs) just as it is.

mackrackit
- 16th September 2010, 15:13
The calibration on the chip seems to be pretty good from the factory, normally.
PBP does not use it nor control the speed of the chip with the exception of OSCON. PBP code can be used to change the factory setting if needed.

Acetronics2
- 16th September 2010, 16:04
B.t.w. I understand that there is a calibration factor inside each PIC that shall/could be used to get better clock accuracy.
Is the PBP using this automatically?
.

No ... PBP doesn't use it automatically ...

the 683 has a factory calibration value you can't access to. you just have the OSCTUNE register to modify somewhat the osc speed, if you need it.
in INTOSC_HF mode only ....

factory cal is supposed to be good ... but you can trim to your needs ( I did it with a 16F88, to get exact R/C timings with internal OSC . trimming was less than 10 units ... )

@ contrario, The 629 and 675 ( i.e. ) need to fetch the cal data and store it @ poweron ... achieved through DEFINE OSCCAL_1K 1

just read relevant µChip datasheets , OSC Chapter , to see how it works, then PBP manual firsts pages ...

Alain