Illegal switch

tiscando

Senior Member
I have got the bas800 to do some assembler programming for fast signal manipulation which the PICAXE can't do.

I needed to adapt the p12f627.inc, looking at the memory organisation section in the datasheet, for the pic12f683, so I created the p12f683.inc file.
After working out all the registers I need to initialise, it only took me 3 downloads to perfect a 5-LED button-controlled runner using the PIC12F683. For one of them, I realized that the WDT resets the PIC if the 'clrwdt' instruction is not executed in a short time, which I think is actually otherwise useful when the program goes into a poll without setting it up correctly, when it might get stuck at the poll. I saw 'clrwdt' instructions in 'Wait.inc'. I've decided it is not required for this program so I turned it off in the config word. I was using the internal HFINTOSC at 4MHz. I always had the PIC datasheet up on the screen.


Now I want to use a 20MHz external oscillator module to eventually feed 3 PICs in a row. Problem: I apparantly found that in the PIC programmer software, the EC clock source option stays greyed out no matter what PIC I select from the menu, even on a PIC which supports EC (including the 12F683). :confused:

I apparantly found that the programming editor does have the option to download to PIC after I click the 'assemble' button, so I used it and it works great for the above. Problem: I have _EC_OSC in the configuration of another program (testing my bitbang serial code) I want to run, with an external oscillator module.
The program compiles OK, then when I click 'yes' for the 'assembly complete' message, and at the same time as the programming progress bar pops up, I get an error message saying 'Illegal switch' and titled 'Programming failed...' The progress bar seems to be downloading the program to the PIC the way I've seen before, :eek: but after it has finished verifying, the 'success' or 'failure' message like i've seen before does not appear. Here, I don't want to take the PIC out of the programmer in case it has the wrong oscillator setting. I have PE's PIC type set to PIC12F683.

The programmer software version is 4.3.12 and the Programmer (brought from Rapid) firmware version is v3.1. I've got PE 5.2.7.

I'll try programming the PIC with my LED flasher program, only with the _EC_OSC in the configuration bit instead of the other, making it 4 LEDs.

Code:
 __CONFIG _CP_OFF & _WDT_OFF & _EC_OSC & _PWRTE_ON & _BODEN_OFF & _MCLRE_OFF
 
In the include file:
 
_FCMEN_ON                    EQU     B'11111111111111'
_FCMEN_OFF                   EQU     B'11011111111111'
_IESO_ON                     EQU     B'11111111111111'
_IESO_OFF                    EQU     B'11101111111111'
_CPD_ON                      EQU     B'11111101111111'
_CPD_OFF                     EQU     B'11111111111111'
_CP_ON                       EQU     B'11111110111111'
_CP_OFF                      EQU     B'11111111111111'
_BODEN_ON                    EQU     B'11111111111111'
_BODEN_ON_SLEEPOFF           EQU     B'11111011111111'
_BODEN_CONTROLLABLE          EQU     B'11110111111111'
_BODEN_OFF                   EQU     B'11110011111111'
_MCLRE_ON                    EQU     B'11111111111111'
_MCLRE_OFF                   EQU     B'11111111011111'
_PWRTE_OFF                   EQU     B'11111111111111'
_PWRTE_ON                    EQU     B'11111111101111'
_WDT_ON                      EQU     B'11111111111111'
_WDT_OFF                     EQU     B'11111111110111'
_LP_OSC                      EQU     B'11111111111000'
_XT_OSC                      EQU     B'11111111111001'
_HS_OSC                      EQU     B'11111111111010'
_EC_OSC                      EQU     B'11111111111011'
_INT_OSC_IO                  EQU     B'11111111111100'
_INT_OSC_CLKOUT              EQU     B'11111111111101'
_RC_OSC_IO                   EQU     B'11111111111110'
_RC_OSC_CLKOUT               EQU     B'11111111111111'

Update: the LED flasher modified for EC OSC programmed normally, with the 'sucsess' message at the end. So I'll probably need to check the suspect program, including the size.

U2: The program is only 400 commands, still under 2048 allowed according to the datasheet. So I'm not sure what 'illegal switch' means, when it pops up after the 'assembly complete' message. I'll try setting the oscillator to INT_OSC_IO and see.

U3: I have changed to _INT_OSC_IO in the suspect program and this time, a warning message titled 'wrong path...' pops up saying 'ErrorInvalid procedure call or argument', again after I click yes to the 'assembly complete' message. The file name is 683-ser-relay-t1.asm. I'll try changing it in case it shouldn't start with a number.

U4: Still the same error message popping up.

U5: The invalid call error popped up on the programs that did work before, so I restarted the programmer, then the LED flasher downloaded correctly. After this, I tried the suspect program with the _INT_OSC_IO, and the 'illegal switch' message popped up again, so now I know it must be something else! (I am using the same .inc file as in the LED flasher program which works).

U6: What?! I have (keeping the original file) stripped the suspect program right down to it's template stuff, and that 'illegal switch' message still appears!
That is so wierd, taking into account the start is now exactly the same as the start of the flasher program.

U7: Now I found it - it is the filename! I changed the dashes to spaces (also altering the filename a bit) and it programs properly. Then I put the dashes back on and then the 'illegal switch' message appears.

Therefore, all I have to do now is rid the filenames of dashes and I won't see this message again. Finally I can see if I can download the next full program.
Edit: It seems that the Illegal switch error pops up because the dashes mean the start of DOS command switches. The MPASM programs seem to parse switches like DOS did.

U8: the bitbang serial in/out relay test program works.
 
Last edited:

tiscando

Senior Member
But then I looked on my oscilloscope on the oscillator pins and found a CLKOUT signal on GP4/OSC2, when the datasheet says in EC mode, GP4/OSC2 is a general purpose IO. So I think it is set to the default RC_CLKOUT mode (111) rather than EC mode (011) as I specified in the __CONFIG line. (At least I have resistors on both oscillator pins.)

Why does the PIC programmer never allow EC_OSC mode, even when the PIC12F683 and numerous others can do it*?

Code:
[U].inc file:[/U]
_EC_OSC                      EQU     B'11111111111011'
 
[U]program:[/U]
;External clock source from an oscillator module & wdt on
; __CONFIG _CP_OFF & _WDT_ON & _EC_OSC & _PWRTE_ON & _BODEN_OFF & _MCLRE_OFF
 
;I am going to have to use RC_IO mode because the programmer doesn't allow EC_OSC
 __CONFIG _CP_OFF & _WDT_ON & _RC_OSC_IO & _PWRTE_ON & _BODEN_OFF & _MCLRE_OFF
*According to their datasheets.
 
Last edited:

tiscando

Senior Member
Why does the PIC programmer never allow EC_OSC mode even when the PIC12F683 and numerous others can do it* ??? :confused:
I'll take this as "The programmers or developers forgot to specify on which PIC chip modes the EC_OSC radio button is greyed out or not."

Is there any workaround to enable the EC_OSC setting?

Nevertheless, the PIC programmer has been working very well.

Problem: I apparantly found that in the PIC programmer software, the EC clock source option stays greyed out no matter what PIC I select from the menu, even on a PIC which supports EC (including the 12F683). :confused:
 

hippy

Ex-Staff (retired)
Staff member
I'm not familiar with using BAS800 but I would guess that PICDEF.INI needs to be edited to enable the EC Oscillator option.

I'm not sure what settings you will need to add to that file or how major the change would need to be to ensure EC Oscillator did not become available for other devices which are related to the 12F683 but don't support EC Oscillator ( if there are any ).

However it looks to me like adding EC=0,3FFB or EC=1,3FFB in the [12F683] section would be a good starting point.
 

tiscando

Senior Member
I have opened picdef.ini: under [12F683], I changed "EXTCLK=1,3FFB" to "EC=1,3FFB", then I've saved it as picdef1.ini, changed the original's filename to "picdef_o1" then moved picdef1 and changed its filename to "picdef.ini".

Then I opened the BAS800 program, selected 12f683 from the menu, then I saw the EC radio button being available for the first ever time! :D That was so obvious!

It seems that at this point, someone may have confused between EC and EXTCLK, but in the program it is EC, so i might as well change all EXTCLK to EC in the picdef.ini file. But just in case though, I'll probably have EC and EXTCLK in the file at the same time, with the same parameter.

Is this OK?
 
Last edited:

hippy

Ex-Staff (retired)
Staff member
It seems that at this point, someone may have confused between EC and EXTCLK

That will be down to Microchip who are often inconsistent in naming conventions between PICmicro devices.
 

tiscando

Senior Member
Yep - I get that point...

More examples:
EEDAT and EEDATA
RC_IO and RC_NO_CLKOUT

Although thats all I could think of in a minute.
 

tiscando

Senior Member
Update 9

There may be another setup file that needs to be changed to allow EC when PE downloads to the PIC itself. When I download to the PIC through PE, it is set to RC_CLKOUT rather than EC, so I opened the PIC programmer software, loaded the HEX program file, selected EC and programmed only the configuration word onto the PIC, which already has the main program. This way, I saw that the PIC is definitely set to EC mode - and that means no more unneccessary stress on the oscillator module. :)
 
Top