<root>
<document scada='0' schema='102' license='1,79829088,X1MNCF' title='SQW Generator (Prototype)' description='Get CWG peripheral runnign is first step..' fcversion='590080' target='PIC.16F.BL0080' >
	<config data='!0,3f8c!10,37fd!20,3f92!30,1fff!40,3fff%0,4%4,0%8,1%b,1%d,1%10,1%11,0%15,1%16,3%19,1%1a,1%1b,0%1c,1%1d,1%20,12%25,0%28,7%2b,7%30,3%3c,1%3d,0%40,1%41,1' clkspd='32000000' simspd='1' usewdt='0' constif='0' Use3V3='1' />
	<plugins >
		<dll_models enabled='1' />
	</plugins>
	<supplement use='0' head='' body='' />
	<debug />
	<traces >
		<trace digital='1' displayname='CWG1' portdata='16908288' scopetype='1' showtrace='1' autonamed='0' channel='0' />
		<trace digital='1' displayname='$PORTB.7' portdata='117571585' scopetype='1' showtrace='1' autonamed='1' channel='1' />
	</traces>
	<ghost >
		<FK2 >
			<data name='FK2D0' port='4294967295' pin='4294967295' />
			<data name='FK2D1' port='4294967295' pin='4294967295' />
			<data name='FK2D2' port='4294967295' pin='4294967295' />
			<data name='FK2D3' port='4294967295' pin='4294967295' />
			<data name='FK2D4' port='4294967295' pin='4294967295' />
			<data name='FK2D5' port='4294967295' pin='4294967295' />
			<data name='FK2D6' port='4294967295' pin='4294967295' />
			<data name='FK2D7' port='4294967295' pin='4294967295' />
			<data name='FK2D8' port='4294967295' pin='4294967295' />
			<data name='FK2D9' port='4294967295' pin='4294967295' />
			<data name='FK2D10' port='4294967295' pin='4294967295' />
			<data name='FK2D11' port='4294967295' pin='4294967295' />
			<data name='FK2D12' port='4294967295' pin='4294967295' />
			<data name='FK2D13' port='4294967295' pin='4294967295' />
			<data name='FK2D14' port='4294967295' pin='4294967295' />
			<data name='FK2D15' port='4294967295' pin='4294967295' />
			<data name='FK2A0' port='4294967295' pin='4294967295' />
			<data name='FK2A1' port='4294967295' pin='4294967295' />
			<data name='FK2A2' port='4294967295' pin='4294967295' />
			<data name='FK2A3' port='4294967295' pin='4294967295' />
			<data name='FK2A4' port='4294967295' pin='4294967295' />
			<data name='FK2A5' port='4294967295' pin='4294967295' />
		</FK2>
		<ICD >
			<data name='AnalogPrescaleValue' value='19' />
			<data name='DigitalSampleRate' value='100000' />
			<data name='BreakpointCount' value='8' />
			<data name='CallStackDepthCount' value='8' />
			<data name='ClockPort' value='1' />
			<data name='ClockPin' value='6' />
			<data name='DataPort' value='1' />
			<data name='DataPin' value='7' />
			<data name='UseDefaultPins' value='1' />
			<data name='WrapEnabled' value='1' />
			<data name='CommsDelayOverridden' value='0' />
			<data name='CommsDelay' value='6' />
			<data name='CalculatedCommsDelay' value='6' />
			<data name='AnalogEB2PrescaleValue' value='2' />
			<data name='DigitalEB2SampleRate' value='500000' />
		</ICD>
		<pins >
			<digital A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
			<analog A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
		</pins>
	</ghost>
	<components >
		<settings autoimg='0' center='1' unitscale='0' fixedscale='0' fixedx='1' fixedy='1' fixedz='1' headcode='0' />
		<definition guid='d431d64d-cb21-4215-9422-b6e16e8effb2' vstate='40' vmin='0' vmaj='1' srcleaf='' visiblename='' description='' category='' category2='' category3='' bIs2dOnly='0' catenable='1' author='' manuname='' manucode='' sysinfo='0' keywords='' dynamic='1' scadaCompatible='0' embeddedCompatible='1' iconpath='' />
		<gdiopts FullContainer='1' FullTransparency='1' ShowGdi='1' ShowOpengl='1' />
		<component class_type='root' codename='panel' x='0' y='0' z='0' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' scadavisible='1' interactive='1' solid='1' layer='0' poslock='0' comp2dType='0' >
			<resources />
			<properties />
			<values />
			<events />
			<apis />
			<variables >
				<variable public='0' >
					<def class_type='variable' name='false' type='b1' description='' isconst='1' isHidden='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='true' type='b1' description='' isconst='1' isHidden='0' isinit='1' usrinit='1' setinit='1' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='PinInitialise' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<command class_type='native' title='C Code' ccode='/** LATx registers
    */
    LATE = 0x00;
    LATD = 0x00;
    LATA = 0x00;
    LATB = 0x80;
    LATC = 0x00;

    /**
    TRISx registers
    */
    TRISE = 0x07;
    TRISA = 0xFD;
    TRISB = 0x7F;
    TRISC = 0xFF;
    TRISD = 0xFF;

    /**
    ANSELx registers
    */
    ANSELD = 0xFF;
    ANSELC = 0xFF;
    ANSELB = 0x7F;
    ANSELE = 0x07;
    ANSELA = 0xFF;

    /**
    WPUx registers
    */
    WPUD = 0x00;
    WPUE = 0x00;
    WPUB = 0x00;
    WPUA = 0x00;
    WPUC = 0x00;

    /**
    ODx registers
    */
    ODCONE = 0x00;
    ODCONA = 0x00;
    ODCONB = 0x00;
    ODCONC = 0x00;
    ODCOND = 0x00;

    /**
    SLRCONx registers
    */
    SLRCONA = 0xFF;
    SLRCONB = 0xFF;
    SLRCONC = 0xFF;
    SLRCOND = 0xFF;
    SLRCONE = 0x07;

    /**
    INLVLx registers
    */
    INLVLA = 0xFF;
    INLVLB = 0xFF;
    INLVLC = 0xFF;
    INLVLD = 0xFF;
    INLVLE = 0x0F;
    	
    RB4PPS = 0x05;   //RB7-&gt;CWG1:CWG1A;    
    RA1PPS = 0x19;   //RA1-&gt;NCO1:NCO;

//' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='SetNCO' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='val' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='native' title='C Code' ccode='// Set the NCO to the options selected in the GUI
    // N1EN disabled; N1POL active_hi; N1PFM FDC_mode; 
    NCO1CON = 0x10;
    // N1CKS FOSC; N1PWS 1_clk; 
    NCO1CLK = 0x00;
    // 
    NCO1ACCU = 0x00;
    // 
    NCO1ACCH = 0x00;
    // 
    NCO1ACCL = 0x00;
    // 
    NCO1INCU = 0x00;
/*    // 10kHZ
    NCO1INCH = 0x02;
    // 
    NCO1INCL = 0x8f;
  // 25kHz
    NCO1INCH = 0x06;
    // 
    NCO1INCL = 0x66;
*/
    NCO1INCH = FCL_VAL &gt;&gt; 8;
    NCO1INCL = FCL_VAL;

    // Enable the NCO module
    NCO1CONbits.N1EN = 1;' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='OscillatorInitialise' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<command class_type='native' title='C Code' ccode='// NOSC HFINTOSC; NDIV 1; 
    OSCCON1 = 0x60;
    // CSWHOLD may proceed; 
    OSCCON3 = 0x00;
    // MFOEN disabled; LFOEN disabled; ADOEN disabled; EXTOEN disabled; HFOEN disabled; 
    OSCEN = 0x00;
    // HFFRQ 32_MHz; 
    OSCFRQ = 0x06;
    // MFOR not ready; 
    OSCSTAT = 0x00;
    // HFTUN 0; 
    OSCTUNE = 0x00;' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='Sweep' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<param name='low' type='u16' description='Timings for NCO low to high' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='high' type='u16' description='Timings for NCO low to high' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<param name='time' type='u16' description='time to sweep over in ms' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='step' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='delay' type='u16' description='Require 1500 steps (10Hz increment)' isconst='0' isHidden='0' isinit='1' usrinit='0' setinit='0' />
						<local name='v10khz' type='s16' description='' isconst='1' isHidden='0' isinit='1' usrinit='645' setinit='0x285' />
						<local name='v25khz' type='s16' description='' isconst='1' isHidden='0' isinit='1' usrinit='1638' setinit='0x666' />
						<local name='freq' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='u16' description='' isconst='0' isHidden='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' >
							<exp exp='.step = (.v25khz - .v10khz)' />
							<exp exp='.freq = .v10khz' />
						</command>
						<command class_type='loop' title='Loop' cmdcolor='1336547' cmdcolor_sec='7915775' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' type='2' forvar='.i' exp='996' >
							<flowline >
								<command class_type='calculation' title='Calculation' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' >
									<exp exp='.freq = .v10khz + .i' />
								</command>
								<command class_type='call' title='q' cmdcolor='1967002' cmdcolor_sec='8546302' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' macro='SetNCO' >
									<argument exp='.freq' />
								</command>
								<command class_type='delay' title='Delay' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' exp='.time' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='PMDIntialise' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<command class_type='native' title='C Code' ccode='// CLKRMD CLKR enabled; SYSCMD SYSCLK enabled; SCANMD SCANNER enabled; FVRMD FVR enabled; IOCMD IOC enabled; CRCMD CRC enabled; NVMMD NVM enabled; 
    PMD0 = 0x00;
    // TMR0MD TMR0 enabled; TMR1MD TMR1 enabled; TMR4MD TMR4 enabled; TMR5MD TMR5 enabled; TMR2MD TMR2 enabled; TMR3MD TMR3 enabled; NCOMD DDS(NCO) enabled; TMR6MD TMR6 enabled; 
    PMD1 = 0x00;
    // ZCDMD ZCD enabled; DACMD DAC enabled; CMP1MD CMP1 enabled; ADCMD ADC enabled; CMP2MD CMP2 enabled; 
    PMD2 = 0x00;
    // CCP2MD CCP2 enabled; CCP1MD CCP1 enabled; CCP4MD CCP4 enabled; CCP3MD CCP3 enabled; CCP5MD CCP5 enabled; PWM6MD PWM6 enabled; PWM7MD PWM7 enabled; 
    PMD3 = 0x00;
    // CWG3MD CWG3 disabled; CWG2MD CWG2 disabled; CWG1MD CWG1 enabled; MSSP1MD MSSP1 enabled; UART1MD EUSART enabled; MSSP2MD MSSP2 enabled; 
    PMD4 = 0x06;
    // DSMMD DSM enabled; CLC3MD CLC3 enabled; CLC4MD CLC4 enabled; SMT1MD SMT1 enabled; SMT2MD SMT2 enabled; CLC1MD CLC1 enabled; CLC2MD CLC2 enabled; 
    PMD5 = 0x00;' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='CWGIntialise' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<command class_type='native' title='    // Set the CWG1 to the options selected in PIC10 / PIC12 / P' ccode='// Set the CWG1 to the options selected in PIC10 / PIC12 / PIC16 / PIC18 MCUs

	// CWG1POLA inverted; CWG1POLC non inverted; CWG1POLB non inverted; CWG1POLD non inverted; 
	CWG1CON1 = 0x01;

	// CWG1DBR 0; 
	CWG1DBR = 0x00;

	// CWG1DBF 0; 
	CWG1DBF = 0x00;

	// CWG1SHUTDOWN No Auto-shutdown; CWG1REN enabled; CWG1LSBD tri-stated; CWG1LSAC tri-stated; 
	CWG1AS0 = 0x54;

	// AS1E disabled; AS0E disabled; AS3E disabled; AS2E disabled; AS5E disabled; AS4E disabled; AS6E disabled; 
	CWG1AS1 = 0x00;

	// CWG1STRD disabled; CWG1STRB disabled; CWG1STRC disabled; CWG1STRA disabled; CWG1OVRD low; CWG1OVRA high; CWG1OVRB low; CWG1OVRC low; 
	CWG1STR = 0x10;

	// CWG1CS FOSC; 
	CWG1CLKCON = 0x00;

	// IS NCO1_OUT; 
	CWG1ISM = 0x08;

	// CWG1LD Buffer_not_loaded; CWG1EN enabled; CWG1MODE Reverse Full bridge mode; 
	CWG1CON0 = 0x83;' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' language='C' />
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' statediag='0' >
						<return name='Return' type='v0' description='' isconst='0' isHidden='0' isinit='0' usrinit='' setinit='' />
						<command class_type='call' title='User Macro' cmdcolor='1967002' cmdcolor_sec='8546302' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' macro='PMDIntialise' />
						<command class_type='call' title='User Macro' disable='1' cmdcolor='1967002' cmdcolor_sec='8546302' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' macro='OscillatorInitialise' />
						<command class_type='call' title='User Macro' cmdcolor='1967002' cmdcolor_sec='8546302' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' macro='CWGIntialise' />
						<command class_type='call' title='User Macro' cmdcolor='1967002' cmdcolor_sec='8546302' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' macro='SetNCO' >
							<argument exp='1000' />
						</command>
						<command class_type='call' title='User Macro' cmdcolor='1967002' cmdcolor_sec='8546302' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' macro='PinInitialise' />
						<command class_type='loop' title='Loop' cmdcolor='1336547' cmdcolor_sec='7915775' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' type='0' exp='1' >
							<flowline >
								<command class_type='call' title='User Macro' cmdcolor='1967002' cmdcolor_sec='8546302' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' macro='Sweep' >
									<argument exp='0' />
									<argument exp='0' />
									<argument exp='100' />
								</command>
								<command class_type='delay' title='Delay' cmdcolor='4198239' cmdcolor_sec='10777539' cmdcolor_txt='16777215' cmdgradient='2' cmdopacity='1' exp='1' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
			</macros>
		</component>
	</components>
	<scadaresourcelookup />
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' >
		<background rgb='15780518' img='' style='0' />
		<camera xe='0' ye='0' ze='2658.09' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<viewport dx='560' dy='618' zoom='25.492' fix_topleft='0' />
		<page x='1000' y='1000' show='0' rgb='7360576' />
	</panel2d>
	<panel3d shadows='0' lighting='2' brightness='0' perspective='1' >
		<background rgb='8409120' img='' style='0' />
		<table rgb='7360576' img='' style='0' size='0' />
		<camera xe='0' ye='0' ze='781.66' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey0 xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey1 xe='-3.67394e-14' ye='0' ze='-300' xt='0' yt='0' zt='0' xquat='0' yquat='1' zquat='0' wquat='6.12323e-17' />
		<camerakey2 xe='0' ye='-300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.707107' yquat='0' zquat='0' wquat='0.707107' />
		<camerakey3 xe='-3.67394e-14' ye='300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-4.32978e-17' yquat='0.707107' zquat='0.707107' wquat='4.32978e-17' />
		<camerakey4 xe='-300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='0.5' zquat='0.5' wquat='0.5' />
		<camerakey5 xe='300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='-0.5' zquat='-0.5' wquat='0.5' />
		<camerakey6 xe='-173.205' ye='-173.205' ze='173.205' xt='0' yt='0' zt='0' xquat='-0.424708' yquat='0.17592' zquat='0.339851' wquat='0.820473' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAeAAAAwgMAAFIDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='PinInitialise' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAeAAAAwgMAAFIDAAA' zoom='75' scrollx='0' scrolly='284' flags='0' />
		<view type='0' name='SetNCO' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAeAAAAwgMAAFIDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='PMDIntialise' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAeAAAAwgMAAFIDAAA' zoom='75' scrollx='79' scrolly='0' flags='0' />
		<view type='0' name='OscillatorInitialise' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAeAAAAwgMAAFIDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='CWGIntialise' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAeAAAAwgMAAFIDAAA' zoom='75' scrollx='86' scrolly='0' flags='0' />
		<view type='0' name='Sweep' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAeAAAAwgMAAFIDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
