Does VSM simulate external crystal oscs on PIC?

Discussion on both general simulation and Proteus VSM microcontroller simulation.
Post Reply
Hurricane
Professional User
Posts: 2
Joined: Thu 2006-10-05 20:47

Does VSM simulate external crystal oscs on PIC?

Post by Hurricane »

I cannot get the external oscillator attached to a 12F675 in VSM to work. I have played about with the CONFIG settings in Proton+ Basic but it makes no odds whether the 32K Crystal is attached or not.

A response on the picbasic forum suggested that VSM does not sim external oscillators, just reads the XTAL = declaration at the top of the source code. Is this true?

Ultimately I want to run the PIC from its own internal RC osc, but use a 32k crystal to clock Timer1 and use the overflow interupt to wake the PIC from sleep.

Source code and VSM board are attached in zip file.

Many thanks
Attachments
timer_675.zip
(13.12 KiB) Downloaded 76 times
Hurricane
rberek
Expert User
Posts: 45
Joined: Wed 2006-03-08 13:16
Location: Ottawa, Canada

Post by rberek »

VSM doesn't read the source code, as you are loading a COFF or HEX file into the simulation.

The processor clock speed is set when you right-click the PIC component you have placed and the Edit Component dialog pops up. There is a place to enter the processor clock frequency.

You don't even need to connect up a crystal if you don't want to.

Since VSM is mixed mode, I'm sure it would simulate the crystal just fine, I just don't think its output would affect the PIC, but I've never tried this to check.
Ettore
Labcenter Staff
Posts: 2932
Joined: Fri 2006-03-03 11:56
Location: Milan
Contact:

Re: Does VSM simulate external crystal oscs on PIC?

Post by Ettore »

If the source code comes from PROTON basic then VSM does support the .bas source code being loaded directly in the PROGRAM property, provided that .HEX and .LST files are in the same project directory. We indeed recommend that .BAS source - instead of .HEX - being loaded because of debugging support offered. PROTON basic does not generate any .cof file upon compilation, though.
Hurricane wrote:I cannot get the external oscillator attached to a 12F675 in VSM to work. I have played about with the CONFIG settings in Proton+ Basic but it makes no odds whether the 32K Crystal is attached or not. A response on the picbasic forum suggested that VSM does not sim external oscillators, just reads the XTAL = declaration at the top of the source code. Is this true?
That's correct. As we said several times, the oscillator circuitry is not modelled with simulated processors for reason of efficiency. If we were going to simulate oscillator then all resources of your PC would have been entirely spent just to see a nice square wave on a crystal ! All clocks are generated internally to the PIC model and you are required to set the clock frequency with the property 'Processor Clock Frequency'.
Hurricane wrote: Ultimately I want to run the PIC from its own internal RC osc, but use a 32k crystal to clock Timer1 and use the overflow interupt to wake the PIC from sleep.
From Microchip documentation, in order to set Timer1 being clocked with LP oscillator having the main internal RC oscillator enabled, you need to set :
a) INTRC_OSC_NOCLKOUT in config control word
b) T1OSCEN and TMR1CS in INTCON register.

So, in PROTON basic, you need to initialize:

Config INTRC_OSC_NOCLKOUT,PWRTE_ON,WDT_OFF,BODEN_ON,CP_OFF

Symbol TMR1CS = T1CON.1 ' Timer1 Clock Source Select
Symbol T1OSCEN = T1CON.3 ' Timer1 Oscillator Enable Control


and then somewhere in the main code:

T1OSCEN = 1 ' LP oscillator is enabled for Timer1 clock
TMR1CS = 1 ' External clock from T1OSO/T1CKI pin (on the rising edge)


TMR1CS must be enabled because of Figure 5-1 of datasheet, in which either any external clock on the pin GP5/T1CKI/OSC1 or from LP oscillator are selected from this bit.

Then, you'll need to trick a little the circuit (attached). Apparently nothing changes in your circuit, but place your mouse pointer over the crystal and press CTRL-C (CTRL-X to return in your circuit). You should see a digital generator which I set to 32KHz and this simulates LP oscillator. This modification is required because Timer1 in PIC12F675 model supports external clocks but not the Timer1 Oscillator Enable Control bit as yet.
In any case the effect is the same.

Additionally, C1 has been excluded from simulation (edit C1 to see how I've set property). This is to prevent any simulation overhead at CP5/T1CK/OSC1 caused from the clock generator embedded now in X1.
Attachments
12f675 SERIAL_REVISED.zip
(33.02 KiB) Downloaded 100 times
Kind regards,
Ettore Arena - Labcenter Electronics.
Post Reply