├── VB.Net2-Code
├── Aj_Scope
│ ├── ClassDiagram1.cd
│ ├── Aj_Scope.ico
│ ├── Aj_Scope2.vb
│ ├── Aj_Scope_1.ico
│ ├── Aj_Scope2_draft.vb
│ ├── Aj_Scope2_draft1.vb
│ ├── Aj_Scope2_working1.vb
│ ├── Aj_Scope2_working2.vb
│ ├── bin
│ │ ├── Debug
│ │ │ ├── Aj_Scope.exe
│ │ │ ├── Aj_Scope.pdb
│ │ │ ├── ZedGraph.dll
│ │ │ ├── Aj_Scope.vshost.exe
│ │ │ └── Aj_Scope.xml
│ │ └── Release
│ │ │ ├── Aj_Scope.exe
│ │ │ ├── Aj_Scope.ico
│ │ │ ├── Aj_Scope.pdb
│ │ │ ├── ZedGraph.dll
│ │ │ └── Aj_Scope.xml
│ ├── obj
│ │ ├── Debug
│ │ │ ├── Aj_Scope.exe
│ │ │ ├── Aj_Scope.pdb
│ │ │ ├── Aj_Scope.Resources.resources
│ │ │ ├── ResolveAssemblyReference.cache
│ │ │ ├── Aj_Scope.Scope_Main_Form.resources
│ │ │ ├── Aj_Scope.xml
│ │ │ ├── Aj_Scope.vbproj.GenerateResource.Cache
│ │ │ ├── Aj_Scope2.vbproj.GenerateResource.Cache
│ │ │ └── TempPE
│ │ │ │ └── My Project.Resources.Designer.vb.dll
│ │ ├── Release
│ │ │ ├── Aj_Scope.exe
│ │ │ ├── Aj_Scope.pdb
│ │ │ ├── Aj_Scope.Resources.resources
│ │ │ ├── Aj_Scope.Scope_Main_Form.resources
│ │ │ ├── Aj_Scope.xml
│ │ │ ├── Aj_Scope.vbproj.GenerateResource.Cache
│ │ │ ├── Aj_Scope2.vbproj.GenerateResource.Cache
│ │ │ └── TempPE
│ │ │ │ └── My Project.Resources.Designer.vb.dll
│ │ ├── Aj_Scope2.vbproj.FileListAbsolute.txt
│ │ └── Aj_Scope.vbproj.FileListAbsolute.txt
│ ├── Aj_Scope2.vbproj.user
│ ├── My Project
│ │ ├── Settings.settings
│ │ ├── Application.myapp
│ │ ├── AssemblyInfo.vb
│ │ ├── Application.Designer.vb
│ │ ├── Resources.Designer.vb
│ │ ├── Settings.Designer.vb
│ │ └── Resources.resx
│ ├── Aj_Scope2.vbproj
│ ├── Aj_Scope2_draft.resx
│ ├── Aj_Scope2_draft1.resx
│ ├── Aj_Scope2_working1.resx
│ └── Aj_Scope2_working2.resx
├── Aj_Scope.suo
├── ZedGraph.dll
├── display_1.jpg
├── display_1.psp
├── display_2.jpg
├── ZedGraph.Web.dll
├── ZGraph_How To.doc
├── Temp_Text.txt
├── Aj_Scope.sln
└── Zg_Code_Temp.vb
├── Python-Code
└── Aj_Scope2_V2.7.pyc
├── MPLAB C30_Code
├── 015_Scope2
│ ├── Scope2.o
│ ├── Scope2.cof
│ ├── Scope2.mcw
│ ├── Scope2.tagsrc
│ ├── Scope2.xls
│ ├── ICD_Scope2.c
│ ├── ICD_Scope2.pdf
│ ├── Plot_From_ICD.xls
│ ├── Readme_Scope2.doc
│ ├── Scope2.mcp
│ ├── data.txt
│ ├── Scope2.mcs
│ ├── Docklight_Scope2.ptp
│ ├── Scope2.mptags
│ ├── Scope2_while.c
│ ├── Scope2_while_int_normal.c
│ ├── Scope2_V0_noFFT.c
│ ├── Scope2_V2with FFT.c
│ ├── Scope2_V1with FFT.c
│ ├── Scope2_V3_Complete.c
│ ├── Scope2_V4_withACK.c
│ └── Scope2_final_115.c
└── 000_AJ_Include
│ ├── delay.h
│ ├── OCxPWM.c
│ ├── simple_spi.c
│ ├── rs232_C30.c
│ ├── rs232_Int_115.c
│ ├── rs232_Int.c
│ ├── adc_comparator.c
│ └── libpic30.h
└── README.md
/VB.Net2-Code/Aj_Scope/ClassDiagram1.cd:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope.suo
--------------------------------------------------------------------------------
/VB.Net2-Code/ZedGraph.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/ZedGraph.dll
--------------------------------------------------------------------------------
/VB.Net2-Code/display_1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/display_1.jpg
--------------------------------------------------------------------------------
/VB.Net2-Code/display_1.psp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/display_1.psp
--------------------------------------------------------------------------------
/VB.Net2-Code/display_2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/display_2.jpg
--------------------------------------------------------------------------------
/VB.Net2-Code/ZedGraph.Web.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/ZedGraph.Web.dll
--------------------------------------------------------------------------------
/Python-Code/Aj_Scope2_V2.7.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/Python-Code/Aj_Scope2_V2.7.pyc
--------------------------------------------------------------------------------
/VB.Net2-Code/ZGraph_How To.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/ZGraph_How To.doc
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/Scope2.o
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/Aj_Scope.ico
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2.vb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/Aj_Scope2.vb
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.cof:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/Scope2.cof
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.mcw:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/Scope2.mcw
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.tagsrc:
--------------------------------------------------------------------------------
1 | C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c
2 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/Scope2.xls
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope_1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/Aj_Scope_1.ico
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/ICD_Scope2.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/ICD_Scope2.c
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/ICD_Scope2.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/ICD_Scope2.pdf
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_draft.vb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/Aj_Scope2_draft.vb
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_draft1.vb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/Aj_Scope2_draft1.vb
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Plot_From_ICD.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/Plot_From_ICD.xls
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Readme_Scope2.doc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/MPLAB C30_Code/015_Scope2/Readme_Scope2.doc
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_working1.vb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/Aj_Scope2_working1.vb
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_working2.vb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/Aj_Scope2_working2.vb
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Debug/Aj_Scope.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Debug/Aj_Scope.exe
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Debug/Aj_Scope.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Debug/Aj_Scope.pdb
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Debug/ZedGraph.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Debug/ZedGraph.dll
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.exe
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.pdb
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Release/Aj_Scope.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Release/Aj_Scope.exe
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Release/Aj_Scope.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Release/Aj_Scope.ico
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Release/Aj_Scope.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Release/Aj_Scope.pdb
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Release/ZedGraph.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Release/ZedGraph.dll
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.exe
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.pdb
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Debug/Aj_Scope.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/bin/Debug/Aj_Scope.vshost.exe
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | USB_Matchbox_Scope
2 | ==================
3 |
4 | Source Code for My-USB-OSCILLOSCOPE posted at http://www.instructables.com/id/DIY-USB-OSCILLOSCOPE-IN-A-MATCHBOX/
5 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.Resources.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.Resources.resources
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/ResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/ResolveAssemblyReference.cache
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.Resources.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.Resources.resources
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Debug/Aj_Scope.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Aj_Scope
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.Scope_Main_Form.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.Scope_Main_Form.resources
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Aj_Scope
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/bin/Release/Aj_Scope.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Aj_Scope
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.Scope_Main_Form.resources:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.Scope_Main_Form.resources
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Aj_Scope
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.vbproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope.vbproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope2.vbproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/Aj_Scope2.vbproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.vbproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope.vbproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope2.vbproj.GenerateResource.Cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Release/Aj_Scope2.vbproj.GenerateResource.Cache
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Debug/TempPE/My Project.Resources.Designer.vb.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Debug/TempPE/My Project.Resources.Designer.vb.dll
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Release/TempPE/My Project.Resources.Designer.vb.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ajoyraman/USB_Matchbox_Scope/HEAD/VB.Net2-Code/Aj_Scope/obj/Release/TempPE/My Project.Resources.Designer.vb.dll
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2.vbproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 | ShowAllFiles
4 |
5 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/My Project/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/My Project/Application.myapp:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 | Scope_Main_Form
5 | false
6 | 0
7 | true
8 | 0
9 | true
10 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Temp_Text.txt:
--------------------------------------------------------------------------------
1 | 20Mbps 0.05us/sample (ETS)
2 | 10Mbps 0.10us/sample (ETS)
3 | 5Mbps 0.20us/sample (ETS)
4 | 2Mbps 0.50us/sample (ETS)
5 | 1Mbps 1.0us/sample (ETS)
6 | 500kbps 2.0us/sample (ETS)
7 | 200kbps 5.0us/sample (ETS)
8 | 100kbps 10us/sample
9 | 50kbps 20us/sample
10 | 20kbps 50us/sample
11 | 10kbps 100us/sample
12 | 5kbps 200us/sample
13 | 2kbps 500us/sample
14 | 1kbps 1.0ms/sample
15 | 500Hz 2.0ms/sample
16 | 200Hz 5.0ms/sample
17 | 100Hz 10ms/sample
18 | 50Hz 20ms/sample
19 | 20Hz 50ms/sample
20 | 10Hz 100ms/sample
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/delay.h:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | If you ever worried about finding the right parameter for __delay32(), feel free to use the attached file.
4 | Before you can use it, rename it do delay.h.
5 |
6 | The file contains macros for delay_us(x) and delay_ms(x)
7 | */
8 |
9 | // FOSC changed by me on 27 July 2014
10 |
11 | /*
12 | delay_us(x) and delay_ms(x) for C30
13 | */
14 |
15 | #ifndef __DELAY_H
16 |
17 | #define FOSC 96000000LL //32000000LL // clock-frequecy in Hz with suffix LL (64-bit-long), eg. 32000000LL for 32MHz
18 | #define FCY (FOSC/2) // MCU is running at FCY MIPS
19 |
20 | #define delay_us(x) __delay32(((x*FCY)/1000000L)) // delays x us
21 | #define delay_ms(x) __delay32(((x*FCY)/1000L)) // delays x ms
22 |
23 | #define __DELAY_H 1
24 | #include
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 9.00
3 | # Visual Studio 2005
4 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Aj_Scope2", "Aj_Scope\Aj_Scope2.vbproj", "{4C55E797-2C61-4D9E-807C-D712D4E2E150}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {4C55E797-2C61-4D9E-807C-D712D4E2E150}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {4C55E797-2C61-4D9E-807C-D712D4E2E150}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {4C55E797-2C61-4D9E-807C-D712D4E2E150}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {4C55E797-2C61-4D9E-807C-D712D4E2E150}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/My Project/AssemblyInfo.vb:
--------------------------------------------------------------------------------
1 | Imports System
2 | Imports System.Reflection
3 | Imports System.Runtime.InteropServices
4 |
5 | ' General Information about an assembly is controlled through the following
6 | ' set of attributes. Change these attribute values to modify the information
7 | ' associated with an assembly.
8 |
9 | ' Review the values of the assembly attributes
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM
21 |
22 |
23 | ' Version information for an assembly consists of the following four values:
24 | '
25 | ' Major Version
26 | ' Minor Version
27 | ' Build Number
28 | ' Revision
29 | '
30 | ' You can specify all the values or you can default the Build and Revision Numbers
31 | ' by using the '*' as shown below:
32 | '
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.mcp:
--------------------------------------------------------------------------------
1 | [HEADER]
2 | magic_cookie={66E99B07-E706-4689-9E80-9B2582898A13}
3 | file_version=1.0
4 | device=dsPIC30F2020
5 | [PATH_INFO]
6 | BuildDirPolicy=BuildDirIsProjectDir
7 | dir_src=
8 | dir_bin=
9 | dir_tmp=
10 | dir_sin=
11 | dir_inc=C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\000_AJ_Include
12 | dir_lib=C:\Program Files\Microchip\MPLAB C30\lib
13 | dir_lkr=
14 | [CAT_FILTERS]
15 | filter_src=*.s;*.c
16 | filter_inc=*.h;*.inc
17 | filter_obj=*.o
18 | filter_lib=*.a
19 | filter_lkr=*.gld
20 | [CAT_SUBFOLDERS]
21 | subfolder_src=
22 | subfolder_inc=
23 | subfolder_obj=
24 | subfolder_lib=
25 | subfolder_lkr=
26 | [FILE_SUBFOLDERS]
27 | file_000=.
28 | [GENERATED_FILES]
29 | file_000=no
30 | [OTHER_FILES]
31 | file_000=no
32 | [FILE_INFO]
33 | file_000=Scope2.c
34 | [SUITE_INFO]
35 | suite_guid={479DDE59-4D56-455E-855E-FFF59A3DB57E}
36 | suite_state=
37 | [TOOL_SETTINGS]
38 | TS{7D9C6ECE-785D-44CB-BA22-17BF2E119622}=-g
39 | TS{25AC22BD-2378-4FDB-BFB6-7345A15512D3}=-g -Wall
40 | TS{7DAC9A1D-4C45-45D6-B25A-D117C74E8F5A}=-o"$(BINDIR_)$(TARGETBASE).$(TARGETSUFFIX)" -Map="$(BINDIR_)$(TARGETBASE).map" --report-mem
41 | TS{509E5861-1E2A-483B-8B6B-CA8DB7F2DD78}=
42 | [INSTRUMENTED_TRACE]
43 | enable=0
44 | transport=0
45 | format=0
46 | [CUSTOM_BUILD]
47 | Pre-Build=
48 | Pre-BuildEnabled=1
49 | Post-Build=
50 | Post-BuildEnabled=1
51 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/data.txt:
--------------------------------------------------------------------------------
1 | 234 233 234 235 233 233 234 233 233 233 234 234 235 235 234 233 235 233 233 234 233 233 235 234 234 235 235 234 234 234 233 233 234 233 234 235 234 234 234 234 233 234 235 235 235 234 233 235 234 233 233 234 235 235 235 234 235 233 234 234 235 234 233 234 233 233 234 235 235 235 235 234 150 081 007 008 000 000 001 003 000 001 001 002 001 001 001 001 001 001 002 001 001 001 001 000 001 001 001 001 001 002 001 001 001 001 002 000 000 001 002 003 000 000 000 004 001 000 001 000 000 001 001 002 001 000 000 001 002 001 000 000 001 002 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 002 001 001 000 000 002 001 001 000 001 002 002 001 000 001 002 152 236 235 235 235 234 233 236 234 234 234 233 234 235 234 233 234 234 235 234 233 235 235 234 234 233 233 235 233 233 235 235 235 234 235 234 235 234 235 235 235 234 234 234 234 233 234 235 235 234 234 235 235 235 233 234 235 234 234 235 235 234 235 234 235 234 234 233 235 234 234 235 235 234 233 235 234 234 235 235 233 234 235 235 234 234 235 235 234 235 235 234 234 234 234 234 235 235 235 234 234 235 234 233 235 234 177 115 001 007 000 003 000 001 001 001 000 001 002 001 001 001 001 001 001 001 002 002 001 001 001 002 001 002 001 001 001 001 001 000 003 001 000 000 003 001 000 001 000 000 001 001 001 001 001 000 001 000 000 001 001 000 001 001 001 001 001 000 001 001 000 001 001 001 002 001 001 002 001 001 001 001 001 001 000 001 001 001 001 001 000 001 001 001 001 000 001 002 001 001 076 233 235 233 233 233 233 233 233 233 233 233 233 233 233 233 233 233 233 233 233 234 233 234 233 233 234 233 233 235 233 234 233 233
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/My Project/Application.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:2.0.50727.3643
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | 'NOTE: This file is auto-generated; do not modify it directly. To make changes,
18 | ' or if you encounter build errors in this file, go to the Project Designer
19 | ' (go to Project Properties or double-click the My Project node in
20 | ' Solution Explorer), and make changes on the Application tab.
21 | '
22 | Partial Friend Class MyApplication
23 |
24 | _
25 | Public Sub New()
26 | MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
27 | Me.IsSingleInstance = false
28 | Me.EnableVisualStyles = true
29 | Me.SaveMySettingsOnExit = true
30 | Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
31 | End Sub
32 |
33 | _
34 | Protected Overrides Sub OnCreateMainForm()
35 | Me.MainForm = Global.Aj_Scope.Scope_Main_Form
36 | End Sub
37 | End Class
38 | End Namespace
39 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/OCxPWM.c:
--------------------------------------------------------------------------------
1 | //Aj OCxPWM.c
2 | // 22 July 2013
3 |
4 | //------------------------------------------------
5 | // Sets up the OC1 & OC2 PWM Channels
6 | // OC1RS=(0-1024) sets the duty cycle for OC1PWM
7 | // OC2RS=(0-1024) sets the duty cycle for OC2PWM
8 | // Default PWM is 50%
9 | // Frequency is 23.44kHz with 12MHz crystal PLL_ON
10 | // Step4 is a repetition but OK
11 | // -----------------------------------------------
12 |
13 | #include
14 |
15 |
16 | void setupOC1PWM(void);
17 | void setupOC2PWM(void);
18 |
19 |
20 |
21 | void setupOC1PWM(void){
22 | //1. Set the PWM period by writing to the appropriate period register.
23 | PR2=1024;
24 |
25 | //2. Set the PWM duty cycle by writing to the OCxRS register.
26 | OC1RS=512;
27 |
28 | //3. Configure the output compare module for PWM operation.
29 | OC1CONbits.OCM=6; //110 = PWM mode on OCx, Fault pin disabled
30 | OC1CONbits.OCTSEL=0; //0 = Timer2 is the clock source for compare x
31 |
32 | //4. Set the TMRx prescale value and enable the Timer, TON (TxCON<15>) = 1
33 | T2CONbits.TCS=0; //Timer2 Clock Source Internal
34 | T2CONbits.TCKPS=0; //Timer2 prescale 1:1
35 | T2CONbits.TON=1;//Enable Timer
36 |
37 | }
38 | void setupOC2PWM(void){
39 | //1. Set the PWM period by writing to the appropriate period register.
40 | PR2=1024;
41 |
42 | //2. Set the PWM duty cycle by writing to the OCxRS register.
43 | OC2RS=512;
44 |
45 | //3. Configure the output compare module for PWM operation.
46 | OC2CONbits.OCM=6; //110 = PWM mode on OCx, Fault pin disabled
47 | OC2CONbits.OCTSEL=0; //0 = Timer2 is the clock source for compare x
48 |
49 | //4. Set the TMRx prescale value and enable the Timer, TON (TxCON<15>) = 1
50 | T2CONbits.TCS=0; //Timer2 Clock Source Internal
51 | T2CONbits.TCKPS=0; //Timer2 prescale 1:1
52 | T2CONbits.TON=1;//Enable Timer
53 | }
54 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/simple_spi.c:
--------------------------------------------------------------------------------
1 | // Aj SPI function
2 | // contains the delay function also
3 | // Uses PortE 0-4 Pins
4 | // 25 July 2013
5 |
6 | //----------------------------------
7 | //SPI USAGE
8 | //setpga(gain=xx,pga=yy);
9 | //xx=0 for Gain1, 1 for Gain2, 2 for Gain 4, 3 for Gain 5
10 | //yy=0 for PGA1, 1 for PGA2,
11 | //------------------------------------
12 | //DELAY USAGE
13 | //delay(zz);
14 | //zz= 1 to 65536
15 | //zz=50 gives 25 microSec
16 | //------------------------------------
17 | #include
18 | #include
19 |
20 | #define spic LATEbits.LATE0 // SPI Clock
21 | #define spid LATEbits.LATE1 // SPI Data
22 | #define cs1 LATEbits.LATE2 // CS Bar for PGA1
23 | #define cs2 LATEbits.LATE3 // CS bar for PGA2
24 |
25 |
26 | //unsigned long x;
27 | int gain,pga;//
28 |
29 | //void delay(unsigned long dog);
30 | void setpga(int gain, int pga); //gain=gain setting, pga= 1 or 2
31 |
32 | /*
33 | //-------------------------------------------------------------
34 | void delay(unsigned long dog){
35 | unsigned long x;
36 | for( x=0; x0 ){
82 | spid =1;
83 | __delay32(320);
84 | spic=1;
85 | __delay32(320);
86 | spic=0;
87 | }
88 | else{
89 | spid =0;
90 | __delay32(320);
91 | spic=1;
92 | __delay32(320);
93 | spic=0;
94 | }
95 | testvector=testvector>>1;
96 | }
97 | __delay32(320);
98 |
99 | if (pga==1)
100 | cs1=1;
101 | else
102 | cs2=1;
103 | }
104 |
105 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.mcs:
--------------------------------------------------------------------------------
1 | [Header]
2 | MagicCookie={0b13fe8c-dfe0-40eb-8900-6712719559a7}
3 | Version=1.0
4 | [File000]
5 | Location=C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.o
6 | Folder=Intermediary
7 | DeviceName=dsPIC30F2020
8 | LanguageToolSuiteID={479DDE59-4D56-455E-855E-FFF59A3DB57E}
9 | LanguageToolID={069BD372-6CA0-40D4-BF2F-5DC806D05083}
10 | LanguageToolLocation=C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe
11 | PPAD=$(BINDIR)||$(TMPDIR)||$(AINDIR)||$(INCDIR)|C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\000_AJ_Include||$(LIBDIR)|C:\Program Files\Microchip\MPLAB C30\lib||$(LKRDIR)||
12 | SOLK=|Scope2.c||||||||
13 | SuiteArgsString=
14 | ToolArgsString=-g -Wall
15 | TraceCmdString=
16 | DebugOptions=
17 | [File001]
18 | Location=C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.cof
19 | Folder=Output
20 | DeviceName=dsPIC30F2020
21 | LanguageToolSuiteID={479DDE59-4D56-455E-855E-FFF59A3DB57E}
22 | LanguageToolID={433C3D55-811D-409D-A6BF-159CF9355B42}
23 | LanguageToolLocation=C:\Program Files\Microchip\MPLAB C30\bin\pic30-ld.exe
24 | PPAD=$(BINDIR)||$(TMPDIR)||$(AINDIR)||$(INCDIR)|C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\000_AJ_Include||$(LIBDIR)|C:\Program Files\Microchip\MPLAB C30\lib||$(LKRDIR)||
25 | SOLK=|Scope2.c||||||||
26 | SuiteArgsString=
27 | ToolArgsString=-o"$(BINDIR_)$(TARGETBASE).$(TARGETSUFFIX)" -Map="$(BINDIR_)$(TARGETBASE).map" --report-mem
28 | TraceCmdString=
29 | DebugOptions=
30 | [File002]
31 | Location=C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.hex
32 | Folder=Output
33 | DeviceName=dsPIC30F2020
34 | LanguageToolSuiteID={479DDE59-4D56-455E-855E-FFF59A3DB57E}
35 | LanguageToolID={433C3D55-811D-409D-A6BF-159CF9355B42}
36 | LanguageToolLocation=C:\Program Files\Microchip\MPLAB C30\bin\pic30-ld.exe
37 | PPAD=$(BINDIR)||$(TMPDIR)||$(AINDIR)||$(INCDIR)|C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\000_AJ_Include||$(LIBDIR)|C:\Program Files\Microchip\MPLAB C30\lib||$(LKRDIR)||
38 | SOLK=|Scope2.c||||||||
39 | SuiteArgsString=
40 | ToolArgsString=-o"$(BINDIR_)$(TARGETBASE).$(TARGETSUFFIX)" -Map="$(BINDIR_)$(TARGETBASE).map" --report-mem
41 | TraceCmdString=
42 | DebugOptions=
43 | [TOOL_LOC_STAMPS]
44 | tool_loc{069BD372-6CA0-40D4-BF2F-5DC806D05083}=C:\Program Files\Microchip\MPLAB C30\bin\pic30-gcc.exe
45 | tool_loc{433C3D55-811D-409D-A6BF-159CF9355B42}=C:\Program Files\Microchip\MPLAB C30\bin\pic30-ld.exe
46 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Aj_Scope2.vbproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\Aj_Scope.exe
2 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\Aj_Scope.pdb
3 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\Aj_Scope.xml
4 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\ZedGraph.dll
5 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\ResolveAssemblyReference.cache
6 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.Scope_Main_Form.resources
7 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.Resources.resources
8 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope2.vbproj.GenerateResource.Cache
9 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.exe
10 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.xml
11 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.pdb
12 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Release\Aj_Scope.exe
13 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Release\Aj_Scope.pdb
14 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Release\Aj_Scope.xml
15 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Release\ZedGraph.dll
16 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\ResolveAssemblyReference.cache
17 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.Scope_Main_Form.resources
18 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.Resources.resources
19 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope2.vbproj.GenerateResource.Cache
20 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.exe
21 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.xml
22 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.pdb
23 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/rs232_C30.c:
--------------------------------------------------------------------------------
1 |
2 | //UART Initialize and rs232 routines 115200 baud
3 | //Ajoy 22 July 2013
4 | //Modified 31 July 13 for 16 MHz Crystal
5 | //----------------------------------------------------------------------------------
6 | // initUART(); sets up the UART RX in Interrupt mode & Tx seems to be in polled mode
7 | // getHex(); Reads one byte from RX
8 | // putHex(); Writes one byte to TX
9 | // clearRXBuffer(); does not work ?
10 | //----------------------------------------------------------------------------------
11 |
12 | #include
13 |
14 | // Function prototypes
15 | void __attribute__((__interrupt__, __auto_psv__)) _U1RXInterrupt(void);
16 | void initUart(void);
17 | void clearRXBuffer(void);
18 | int getHex(void);
19 | void putHex(int x);
20 |
21 | //global
22 | int RXflag=0;
23 |
24 |
25 | void initUart(void){
26 | U1MODEbits.UARTEN= 0; //UART1 Disabled
27 | //U1MODEbits.UARTEN= 1; //UART1 Enabled
28 | U1MODEbits.ALTIO = 1; // Use alternate IO
29 | U1MODEbits.BRGH = 0; //Use High Bit rate
30 | //U1MODEbits.BRGH = 1; //Use High Bit rate **Bug in Chip
U1MODEbits.PDSEL = 0;; //8 bit no parity
31 | U1MODEbits.STSEL = 0; //One stop bit
32 |
33 | IPC2bits.U1RXIP =4;//2;//Set UART1 RX Int Priority 0-7, 0=disabled 7=Highest
34 | //IPC2bits.U1TXIP =1;//TX Priority 2
35 | //IEC0bits.U1RXIE = 1;//Enable UART1 Receiver Interrupt
36 | //IEC0bits.U1TXIE = 1;//Enable UART1 Tx Interrupt
37 | IFS0bits.U1RXIF =0; //Set UART1 RX Int Flag=0
38 |
39 |
40 | U1STAbits.UTXISEL0 = 0;
41 | U1STAbits.UTXISEL1 = 0;
42 | U1STAbits.UTXBRK = 0;
43 | U1STAbits.URXISEL = 0;
44 | U1STAbits.UTXEN = 1; // Enable transmit
45 |
46 | //U1BRG = 155;// 9600 baud 12MHz Crystal
47 | //U1BRG = 12; // 115200 baud 12 MHz Crystal
48 | U1BRG = 16; // 115200 baud 16 MHz Crystal
49 |
50 | U1MODEbits.UARTEN= 1; //UART1 Enabled
51 |
52 | IEC0bits.U1RXIE = 1;//Enable UART1 Receiver Interrupt
53 | U1STAbits.UTXEN = 1; // Enable transmit
54 |
55 | }
56 |
57 | void putHex(int x)
58 | { while(U1STAbits.UTXBF==1) continue; //Checks if Buffer is Full and w8ts for it to have one location empty
59 | U1TXREG=x;
60 | while(U1STAbits.TRMT==0) continue; //Loops till Transmition is over
61 | }
62 | int getHex(void){
63 | while(RXflag==0) continue; //Loops till RX Flag=1 meaning one character has been recived
64 | RXflag=0; //resets RX flag
65 | return(U1RXREG);
66 | }
67 |
68 |
69 | void __attribute__((__interrupt__, __auto_psv__)) _U1RXInterrupt(void)
70 | {
71 | RXflag=1;
72 | _U1RXIF=0; //clear RX Interrupt Flag
73 | }
74 |
75 | void clearRXBuffer(void){
76 | char dummy;
77 | dummy=U1RXREG;
78 | dummy=U1RXREG;
79 | dummy=U1RXREG;
80 | }
81 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/My Project/Resources.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:2.0.50727.3643
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My.Resources
16 |
17 | 'This class was auto-generated by the StronglyTypedResourceBuilder
18 | 'class via a tool like ResGen or Visual Studio.
19 | 'To add or remove a member, edit your .ResX file then rerun ResGen
20 | 'with the /str option, or rebuild your VS project.
21 | '
22 | ' A strongly-typed resource class, for looking up localized strings, etc.
23 | '
24 | _
28 | Friend Module Resources
29 |
30 | Private resourceMan As Global.System.Resources.ResourceManager
31 |
32 | Private resourceCulture As Global.System.Globalization.CultureInfo
33 |
34 | '
35 | ' Returns the cached ResourceManager instance used by this class.
36 | '
37 | _
38 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
39 | Get
40 | If Object.ReferenceEquals(resourceMan, Nothing) Then
41 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Aj_Scope.Resources", GetType(Resources).Assembly)
42 | resourceMan = temp
43 | End If
44 | Return resourceMan
45 | End Get
46 | End Property
47 |
48 | '
49 | ' Overrides the current thread's CurrentUICulture property for all
50 | ' resource lookups using this strongly typed resource class.
51 | '
52 | _
53 | Friend Property Culture() As Global.System.Globalization.CultureInfo
54 | Get
55 | Return resourceCulture
56 | End Get
57 | Set(ByVal value As Global.System.Globalization.CultureInfo)
58 | resourceCulture = value
59 | End Set
60 | End Property
61 | End Module
62 | End Namespace
63 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/rs232_Int_115.c:
--------------------------------------------------------------------------------
1 |
2 | //UART Initialize and rs232 routines 115200 baud
3 | //Ajoy 22 July 2013
4 | //Modified 31 July 13 for 16 MHz Crystal
5 | //Modified 04 Aug 2013 for Tx in Interrupt Mode
6 | //----------------------------------------------------------------------------------
7 | // initUART(); sets up the UART RX in Interrupt mode
8 | // Tx in interrupt mode
9 | // getHex(); Reads one byte from RX
10 | // putHex(); Writes one byte to TX
11 | // clearRXBuffer(); does not work ?
12 | //----------------------------------------------------------------------------------
13 |
14 | #include
15 |
16 | // Function prototypes
17 | void __attribute__((__interrupt__, __auto_psv__)) _U1RXInterrupt(void);
18 | void __attribute__((__interrupt__, __auto_psv__)) _U1TXInterrupt(void);
19 | void initUart(void);
20 | void clearRXBuffer(void);
21 | int getHex(void);
22 | void putHex(int x);
23 |
24 | //global
25 | int RXflag=0, TXflag=0;
26 |
27 | #define hw_reset LATEbits.LATE5 // HW_Reset
28 |
29 | void initUart(void){
30 | TRISE=0;
31 | hw_reset =0;
32 |
33 | U1MODEbits.UARTEN= 0; //UART1 Disabled
34 | //U1MODEbits.UARTEN= 1; //UART1 Enabled
35 | U1MODEbits.ALTIO = 1; // Use alternate IO
36 | U1MODEbits.BRGH = 0; //Use High Bit rate
37 | //U1MODEbits.BRGH = 1; //Use High Bit rate **Bug in Chip
38 | U1MODEbits.PDSEL = 0;; //8 bit no parity
39 | U1MODEbits.STSEL = 0; //One stop bit
40 |
41 | IPC2bits.U1RXIP =5;//2;//Set UART1 RX Int Priority 0-7, 0=disabled 7=Highest
42 | IPC2bits.U1TXIP =4;//TX Priority 2
43 | //IEC0bits.U1RXIE = 1;//Enable UART1 Receiver Interrupt
44 | //IEC0bits.U1TXIE = 1;//Enable UART1 Tx Interrupt
45 | IFS0bits.U1RXIF =0; //Set UART1 RX Int Flag=0
46 |
47 |
48 | U1STAbits.UTXISEL0 = 0;
49 | U1STAbits.UTXISEL1 = 0;
50 | U1STAbits.UTXBRK = 0;
51 | U1STAbits.URXISEL = 0;
52 | //U1STAbits.UTXEN = 1; // Enable transmit
53 |
54 | U1BRG = 16; // 115200 baud 16 MHz Crystal
55 |
56 | U1MODEbits.UARTEN= 1; //UART1 Enabled
57 |
58 | IEC0bits.U1RXIE = 1;//Enable UART1 Receiver Interrupt
59 | IEC0bits.U1TXIE = 1;//Enable UART1 Tx Interrut
60 |
61 | U1STAbits.UTXEN = 1; // Enable transmit
62 |
63 | }
64 |
65 | void putHex(int x) {
66 | while(TXflag==0) continue; //Checks if Buffer is Full and w8ts for it to have one location empty
67 | U1TXREG=x;
68 | TXflag=0;
69 | return; //Loops till Transmition is over
70 | }
71 | int getHex(void){
72 | while(RXflag==0) continue;//Loops till RX Flag=1 meaning one character has been recived
73 | RXflag=0; //resets RX flag
74 | return(U1RXREG);
75 | }
76 |
77 |
78 | void __attribute__((__interrupt__, __auto_psv__)) _U1RXInterrupt(void){
79 | RXflag=1;
80 | _U1RXIF=0; //clear RX Interrupt Flag
81 | }
82 | void __attribute__((__interrupt__, __auto_psv__)) _U1TXInterrupt(void){
83 | TXflag=1;
84 | _U1TXIF=0; //clear RX Interrupt Flag
85 |
86 | }
87 | void clearRXBuffer(void){
88 | char dummy;
89 | dummy=U1RXREG;
90 | dummy=U1RXREG;
91 | dummy=U1RXREG;
92 | }
93 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/rs232_Int.c:
--------------------------------------------------------------------------------
1 |
2 | //UART Initialize and rs232 routines 115200 baud
3 | //Ajoy 22 July 2013
4 | //Modified 31 July 13 for 16 MHz Crystal
5 | //Modified 04 Aug 2013 for Tx in Interrupt Mode
6 | //----------------------------------------------------------------------------------
7 | // initUART(); sets up the UART RX in Interrupt mode
8 | // Tx in interrupt mode
9 | // getHex(); Reads one byte from RX
10 | // putHex(); Writes one byte to TX
11 | // clearRXBuffer(); does not work ?
12 | //----------------------------------------------------------------------------------
13 |
14 | #include
15 |
16 | // Function prototypes
17 | void __attribute__((__interrupt__, __auto_psv__)) _U1RXInterrupt(void);
18 | void __attribute__((__interrupt__, __auto_psv__)) _U1TXInterrupt(void);
19 | void initUart(void);
20 | void clearRXBuffer(void);
21 | int getHex(void);
22 | void putHex(int x);
23 |
24 | //global
25 | int RXflag=0, TXflag=0;
26 |
27 |
28 | void initUart(void){
29 | TRISE=0;
30 |
31 | U1MODEbits.UARTEN= 0; //UART1 Disabled
32 | //U1MODEbits.UARTEN= 1; //UART1 Enabled
33 | U1MODEbits.ALTIO = 1; // Use alternate IO
34 | U1MODEbits.BRGH = 0; //Use High Bit rate
35 | //U1MODEbits.BRGH = 1; //Use High Bit rate **Bug in Chip
36 | U1MODEbits.PDSEL = 0;; //8 bit no parity
37 | U1MODEbits.STSEL = 0; //One stop bit
38 |
39 | IPC2bits.U1RXIP =5;//2;//Set UART1 RX Int Priority 0-7, 0=disabled 7=Highest
40 | IPC2bits.U1TXIP =4;//TX Priority 2
41 | //IEC0bits.U1RXIE = 1;//Enable UART1 Receiver Interrupt
42 | //IEC0bits.U1TXIE = 1;//Enable UART1 Tx Interrupt
43 | IFS0bits.U1RXIF =0; //Set UART1 RX Int Flag=0
44 |
45 |
46 | U1STAbits.UTXISEL0 = 0;
47 | U1STAbits.UTXISEL1 = 0;
48 | U1STAbits.UTXBRK = 0;
49 | U1STAbits.URXISEL = 0;
50 | //U1STAbits.UTXEN = 1; // Enable transmit
51 |
52 |
53 | //U1BRG = (FCY/16*Baud Rate)-1 WITH BRGL
54 | //FCY = FCY = Primary Osc X 2 WITH PLL
55 | U1BRG = 16; // 115200 baud 16 MHz Crystal BRGL
56 |
57 | U1MODEbits.UARTEN= 1; //UART1 Enabled
58 |
59 | IEC0bits.U1RXIE = 1;//Enable UART1 Receiver Interrupt
60 | IEC0bits.U1TXIE = 1;//Enable UART1 Tx Interrut
61 |
62 | U1STAbits.UTXEN = 1; // Enable transmit
63 |
64 | }
65 |
66 | void putHex(int x) {
67 | while(TXflag==0) continue; //Checks if Buffer is Full and w8ts for it to have one location empty
68 | U1TXREG=x;
69 | TXflag=0;
70 | return; //Loops till Transmition is over
71 | }
72 | int getHex(void){
73 | while(RXflag==0) continue;//Loops till RX Flag=1 meaning one character has been recived
74 | RXflag=0; //resets RX flag
75 | return(U1RXREG);
76 | }
77 |
78 |
79 | void __attribute__((__interrupt__, __auto_psv__)) _U1RXInterrupt(void){
80 | RXflag=1;
81 | _U1RXIF=0; //clear RX Interrupt Flag
82 | }
83 | void __attribute__((__interrupt__, __auto_psv__)) _U1TXInterrupt(void){
84 | TXflag=1;
85 | _U1TXIF=0; //clear RX Interrupt Flag
86 |
87 | }
88 | void clearRXBuffer(void){
89 | char dummy;
90 | dummy=U1RXREG;
91 | dummy=U1RXREG;
92 | dummy=U1RXREG;
93 | }
94 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/My Project/Settings.Designer.vb:
--------------------------------------------------------------------------------
1 | '------------------------------------------------------------------------------
2 | '
3 | ' This code was generated by a tool.
4 | ' Runtime Version:2.0.50727.3643
5 | '
6 | ' Changes to this file may cause incorrect behavior and will be lost if
7 | ' the code is regenerated.
8 | '
9 | '------------------------------------------------------------------------------
10 |
11 | Option Strict On
12 | Option Explicit On
13 |
14 |
15 | Namespace My
16 |
17 | _
20 | Partial Friend NotInheritable Class MySettings
21 | Inherits Global.System.Configuration.ApplicationSettingsBase
22 |
23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings), MySettings)
24 |
25 | #Region "My.Settings Auto-Save Functionality"
26 | #If _MyType = "WindowsForms" Then
27 | Private Shared addedHandler As Boolean
28 |
29 | Private Shared addedHandlerLockObject As New Object
30 |
31 | _
32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
33 | If My.Application.SaveMySettingsOnExit Then
34 | My.Settings.Save()
35 | End If
36 | End Sub
37 | #End If
38 | #End Region
39 |
40 | Public Shared ReadOnly Property [Default]() As MySettings
41 | Get
42 |
43 | #If _MyType = "WindowsForms" Then
44 | If Not addedHandler Then
45 | SyncLock addedHandlerLockObject
46 | If Not addedHandler Then
47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
48 | addedHandler = True
49 | End If
50 | End SyncLock
51 | End If
52 | #End If
53 | Return defaultInstance
54 | End Get
55 | End Property
56 | End Class
57 | End Namespace
58 |
59 | Namespace My
60 |
61 | _
64 | Friend Module MySettingsProperty
65 |
66 | _
67 | Friend ReadOnly Property Settings() As Global.Aj_Scope.My.MySettings
68 | Get
69 | Return Global.Aj_Scope.My.MySettings.Default
70 | End Get
71 | End Property
72 | End Module
73 | End Namespace
74 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/adc_comparator.c:
--------------------------------------------------------------------------------
1 | //Initialize the ADC Channels
2 | //Initialise the COMP3A and COMP3B
3 | //Ajoy 2 Aug 13
4 | //
5 | //----------------------------------------------------------------------------------
6 | // initialiseADC () Sets up AN0-AN3
7 | /* Sample Calling Routine for AN0/AN2
8 | int temp;
9 | char AN[405];
10 |
11 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
12 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
13 | AN[temp]=ADCBUF0>>2;
14 | temp++;
15 | AN[temp]=ADCBUF1>>2;
16 | temp++;
17 | */
18 |
19 | //----------------------------------------------------------------------------------
20 |
21 | #include
22 |
23 | // Function prototypes
24 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void);
25 | void initialiseADC(void);
26 | void initialiseComp(void);
27 |
28 |
29 | void initialiseADC (void){
30 | //This function initializes the ADC for a dsPIC30F2020
31 | // ADCON: ADC Control Register 1
32 | //ADCONbits.ADCS = 4; //100 = FADC/12 = 20.0 MHz @ 30 MIPS
33 | // Fadc=Xtal*16 Divider is set up for Fadc/12
34 | // 16 MHz with 12MHz Xtal
35 | ADCONbits.ADCS = 2; //010 = FADC/8 = 30.0 MHz @ 30 MIPS
36 |
37 | //ADCONbits.ADCS = 3; //011 = FADC/10 = 24.0 MHz @ 30 MIPS
38 |
39 | ADCONbits.SEQSAMP = 0; // Simultaneous Sampling
40 | ADCONbits.ORDER = 0; // Even channel first
41 | //ADCONbits.EIE = 0; // Interrupt after second conversion
42 | ADCONbits.FORM = 0; // Output in Integer Format
43 | ADCONbits.GSWTRG = 0; // global software trigger bit
44 | ADCONbits.ADSIDL = 0; // Operate in Idle Mode
45 |
46 | ADPCFG = 0b1111111111000000; // AN0-AN5 all analog inputs
47 | // TRIS ?
48 |
49 | ADSTAT = 0; // Clear the ADSTAT register
50 |
51 | //Settings for AN3 AN2
52 | ADCPC0bits.TRGSRC1 = 1; // source is individual software trigger for AN3 AN2
53 | ADCPC0bits.SWTRG1 = 0; // When set to 1 will start conversion of AN3 and AN2
54 | ADCPC0bits.PEND1 = 0; // goes to 1 on conversion pending & 0 on conversion complete ADCPC0bits.IRQEN1 = 0; // disable the interrupt
55 | ADCPC0bits.IRQEN1 = 0; // interrupt is not generated
56 |
57 | //Settings for AN1 AN0
58 | ADCPC0bits.TRGSRC0 = 1; // source is individual software trigger for AN1 AN0
59 | ADCPC0bits.SWTRG0 = 0; // When set to 1 will start conversion of AN1 and AN0
60 | ADCPC0bits.PEND0 = 0; // goes to 1 on conversion pending & 0 on conversion complete ADCPC0bits.IRQEN0 = 0; // disable the interrupt
61 | ADCPC0bits.IRQEN0 = 0; // interrupt is not generated at end of conversion
62 |
63 | ADCONbits.ADON = 1; //Start the ADC module
64 |
65 |
66 | }
67 | void initialiseComp(void){
68 |
69 | CMPCON3bits.CMPSIDL=1; //Continue in IDLE
70 | CMPCON3bits.EXTREF=0; //Internal Reference
71 | //CMPCON3bits.CMPPOL=0; //Normal input polarity ----------Set in Main
72 | CMPCON3bits.RANGE =1; //High Range VDD/2
73 | // CMPCON3bits.INSEL=0; // 3A selected ----------Set in Main
74 | //CMPCON3bits.CMPSTAT=0; //Status including CMPPOL
75 |
76 | //CMPDAC3bits.CMREF= 512; //2.5V/2 initial setting ----------Set in Main
77 |
78 | //CMPCON3bits.CMPON=1; //Comparator ON ----------Set in Main
79 |
80 |
81 |
82 |
83 | //Interrupt priority and enable
84 | IPC7bits.AC3IP =3; //Priority for AC3 Interrupt
85 |
86 | IFS1bits.AC3IF =0; //Analog Comparator #3 Interrupt Flag Status bit
87 |
88 | // IEC1bits.AC3IE =0; // Set 1 to Enable interrupt ----------Set in Main
89 |
90 | }
91 |
92 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Docklight_Scope2.ptp:
--------------------------------------------------------------------------------
1 | VERSION
2 | 8
3 |
4 | COMMSETTINGS
5 | 0
6 | COM14
7 | COM1
8 | 115200
9 | 2
10 | 0
11 | 4
12 | 0
13 | 0
14 |
15 | COMMDISPLAY
16 | 0
17 |
18 | SEND
19 | 0
20 | Test LED
21 | 74
22 | 0
23 | 5
24 |
25 | SEND
26 | 1
27 | Gain 1/2/5 , PGA1
28 | 47 01 01
29 | 0
30 | 5
31 |
32 | SEND
33 | 2
34 | Gain 1/2/5 PGA2
35 | 47 01 02
36 | 0
37 | 5
38 |
39 | SEND
40 | 3
41 | "O"Offset CH1
42 | 4F 02 66
43 | 0
44 | 5
45 |
46 | SEND
47 | 4
48 | "o" Offset CH2
49 | 6F 02 66
50 | 0
51 | 5
52 |
53 | SEND
54 | 5
55 | Trig Auto
56 | 54 00
57 | 0
58 | 5
59 |
60 | SEND
61 | 6
62 | Trig CH1
63 | 54 01
64 | 0
65 | 5
66 |
67 | SEND
68 | 7
69 | Trig CH2
70 | 54 02
71 | 0
72 | 5
73 |
74 | SEND
75 | 8
76 | Trig Level Ch1 50%
77 | 4C 02 00
78 | 0
79 | 1
80 |
81 | SEND
82 | 9
83 | Trig Level Ch2 50%
84 | 6C 02 80
85 | 0
86 | 5
87 |
88 | SEND
89 | 10
90 | Ch1 Trig +/- Edge 0/1
91 | 50 00
92 | 0
93 | 5
94 |
95 | SEND
96 | 11
97 | Ch2 Trig +/- Edge 0/1
98 | 70 01
99 | 0
100 | 5
101 |
102 | SEND
103 | 12
104 | Set FFT Normal 0/1/2 N/Ch1/Ch2
105 | 46 00
106 | 0
107 | 5
108 |
109 | SEND
110 | 13
111 | Set FFT CH1
112 | 46 01
113 | 0
114 | 5
115 |
116 | SEND
117 | 14
118 | Set FFT CH2
119 | 46 02
120 | 0
121 | 5
122 |
123 | SEND
124 | 15
125 | Sampling Rate 1 set 10 kHz
126 | 53 01
127 | 0
128 | 5
129 |
130 | SEND
131 | 16
132 | Sampling Rate 2 set 5kHz
133 | 53 02
134 | 0
135 | 5
136 |
137 | SEND
138 | 17
139 | Sampling Rate 3 set 2kHz
140 | 53 03
141 | 0
142 | 5
143 |
144 | SEND
145 | 18
146 | Sampling Rate 4 set 1kHz
147 | 53 04
148 | 0
149 | 5
150 |
151 | SEND
152 | 19
153 | Sampling Rate 5 set 500Hz
154 | 53 05
155 | 0
156 | 5
157 |
158 | SEND
159 | 20
160 | Sampling Rate 6 set 200Hz
161 | 53 06
162 | 0
163 | 5
164 |
165 | SEND
166 | 21
167 | Sampling Rate 7 set 100Hz
168 | 53 07
169 | 0
170 | 5
171 |
172 | SEND
173 | 22
174 | Sampling Rate 8 set 50Hz
175 | 53 08
176 | 0
177 | 5
178 |
179 | SEND
180 | 23
181 | Sampling Rate 9 set 20Hz
182 | 53 09
183 | 0
184 | 5
185 |
186 | SEND
187 | 24
188 | Sampling Rate 10 set 10Hz
189 | 53 0A
190 | 0
191 | 5
192 |
193 | SEND
194 | 25
195 | Sampling Rate 11 set 5Hz
196 | 53 0B
197 | 0
198 | 5
199 |
200 | SEND
201 | 26
202 | Sampling Rate 12 Set 2Hz
203 | 53 0C
204 | 0
205 | 5
206 |
207 | SEND
208 | 27
209 | Sampling Rate 13 set 1Hz
210 | 53 0D
211 | 0
212 | 5
213 |
214 | SEND
215 | 28
216 | Sampling Rate 14 set 0.5Hz
217 | 53 0E
218 | 0
219 | 5
220 |
221 | SEND
222 | 29
223 | Sampling Rate 15 set 0.2Hz
224 | 53 0F
225 | 0
226 | 5
227 |
228 | SEND
229 | 30
230 | Sampling Rate 16 set 0.1Hz
231 | 53 10
232 | 0
233 | 5
234 |
235 | SEND
236 | 31
237 | Sampling Rate 17 set 20kHz
238 | 53 11
239 | 0
240 | 5
241 |
242 | SEND
243 | 32
244 | Sampling Rate 18 set 50kHz
245 | 53 12
246 | 0
247 | 5
248 |
249 | SEND
250 | 33
251 | Sampling Rate 19 set 100kHz
252 | 53 13
253 | 0
254 | 5
255 |
256 | SEND
257 | 34
258 | Sampling Rate 20 set 200kHz
259 | 53 14
260 | 0
261 | 5
262 |
263 | SEND
264 | 35
265 | Capture
266 | 43
267 | 0
268 | 5
269 |
270 | SEND
271 | 36
272 | Abort
273 | 41
274 | 0
275 | 5
276 |
277 | SEND
278 | 37
279 | Read Ch1 Data 200 Even
280 | 44 01
281 | 0
282 | 5
283 |
284 | SEND
285 | 38
286 | Read Ch2 Data 200 Odd
287 | 44 02
288 | 0
289 | 5
290 |
291 | SEND
292 | 39
293 | Read FFT/CH1 First 200 Data
294 | 44 03
295 | 0
296 | 5
297 |
298 | SEND
299 | 40
300 | Read FFT/CH2 Second 200
301 | 44 04
302 | 0
303 | 5
304 |
305 | SEND
306 | 41
307 | "R" Read VRef
308 | 52
309 | 0
310 | 5
311 |
312 | SEND
313 | 42
314 | Fake Sequence
315 | 58
316 | 0
317 | 5
318 |
319 | SEND
320 | 43
321 | Read BUSY
322 | 42
323 | 0
324 | 5
325 |
326 | SEND
327 | 44
328 | Ready Response
329 | 41 6A 53 63 6F 70 65 52 65 61 64 79 0A 0D
330 | 0
331 | 5
332 |
333 | SEND
334 | 45
335 | Identify
336 | 49
337 | 0
338 | 5
339 |
340 | SEND
341 | 46
342 | Compensate OSC1
343 | 63 01
344 | 0
345 | 5
346 |
347 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/obj/Aj_Scope.vbproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Debug\Aj_Scope.exe
2 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Debug\Aj_Scope.pdb
3 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Debug\Aj_Scope.xml
4 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Debug\ResolveAssemblyReference.cache
5 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Debug\Aj_Scope.Scope_Main_Form.resources
6 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Debug\Aj_Scope.Resources.resources
7 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Debug\Aj_Scope.vbproj.GenerateResource.Cache
8 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Debug\Aj_Scope.exe
9 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Debug\Aj_Scope.xml
10 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Debug\Aj_Scope.pdb
11 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Debug\ZedGraph.dll
12 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Release\Aj_Scope.exe
13 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Release\Aj_Scope.pdb
14 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Release\Aj_Scope.xml
15 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\bin\Release\ZedGraph.dll
16 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Release\ResolveAssemblyReference.cache
17 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Release\Aj_Scope.Scope_Main_Form.resources
18 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Release\Aj_Scope.Resources.resources
19 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Release\Aj_Scope.vbproj.GenerateResource.Cache
20 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Release\Aj_Scope.exe
21 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Release\Aj_Scope.xml
22 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope\Aj_Scope\obj\Release\Aj_Scope.pdb
23 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.exe
24 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.xml
25 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Release\Aj_Scope.pdb
26 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\Aj_Scope.exe
27 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\Aj_Scope.pdb
28 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\Aj_Scope.xml
29 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\bin\Debug\ZedGraph.dll
30 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\ResolveAssemblyReference.cache
31 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.Scope_Main_Form.resources
32 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.Resources.resources
33 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.vbproj.GenerateResource.Cache
34 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.exe
35 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.xml
36 | C:\Documents and Settings\ajoy\My Documents\Visual Studio 2005\Projects\Aj_Scope2\Aj_Scope\obj\Debug\Aj_Scope.pdb
37 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/000_AJ_Include/libpic30.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2006 Microchip Technology, all rights reserved
3 | *
4 | * This file defines useful exports from libpic30.a
5 | * Not all functions defined in libpic30.a can be usefully called by
6 | * the user, most are helper functions for the standard C library, libc.a
7 | *
8 | */
9 |
10 | #ifndef __LIBPIC30_H
11 | #define __LIBPIC30_H
12 |
13 | /*
14 | * The following two functions allow the programmer to attach a file to
15 | * standard input, and later close the file. The functions are only useful
16 | * if the executable will be simulated.
17 | *
18 | * With these functions input from the file will be read on-demmand, otherwise
19 | * the programmer should use the message based stimulus (information on this
20 | * can be found within MPLAB IDE's help pages).
21 | */
22 |
23 | extern int __attach_input_file(const char *f);
24 | void __close_input_file(void);
25 |
26 | /*
27 | * __C30_UART selects the default UART port that read() and write() will use.
28 | * read() is called by fscanf and family, while write() is called by printf
29 | * and family. The default setting (as shipped) is 1, which is suitable for
30 | * the dsPICdem 1.1(tm) board. Modifying this to another value will select
31 | * UART 2, suitable for the explorer 16(tm) board.
32 | */
33 |
34 | extern int __C30_UART;
35 |
36 | /*
37 | * __delay32() provides a 32-bit delay routine which will delay for the number
38 | * of cycles denoted by its argument. The minimum delay is 11 cycles
39 | * including call and return statements. With this function only the time
40 | * required for argument transmission is not accounted for. Requests for
41 | * less than 11 cycles of delay will cause an 11 cycle delay.
42 | */
43 |
44 | extern void __delay32(unsigned long cycles);
45 |
46 | /*
47 | * __memcpy_helper() - not a user-callable function
48 | *
49 | * Copies data from program memory to data memory. It does
50 | * not require the Program Space Visibility (PSV) window. However, it
51 | * does change the value of TBLPAG during execution.
52 | *
53 | * The source address in program memory is specified by a tbl_offset,
54 | * tbl_page pair. Flags indicate whether the upper byte should be
55 | * copied, and whether to terminate early after a NULL byte.
56 | * The return value is an updated source address pair.
57 | *
58 | * The number of bytes copied may be even or odd. The source address
59 | * is always even and is always aligned to the start of the next
60 | * program memory word.
61 | */
62 | typedef struct _prog_address_tag {
63 | union {
64 | struct {
65 | int low;
66 | int high;
67 | } w;
68 | long next;
69 | };
70 | } _prog_addressT;
71 |
72 | extern _prog_addressT _memcpy_helper(unsigned int tbl_offset, unsigned int tbl_page,
73 | char *dst, unsigned int len, int flags);
74 |
75 | /*
76 | * Initialize a variable of type _prog_addressT.
77 | *
78 | * These variables are not equivalent to C pointers,
79 | * since each source address corresponds to 2 or 3 chars.
80 | */
81 |
82 | #define _init_prog_address(a,b) { \
83 | a.w.low = __builtin_tbloffset(b); \
84 | a.w.high = __builtin_tblpage(b); \
85 | };
86 |
87 | /*
88 | * _memcpy_p2d16() copies 16 bits of data from each address
89 | * in program memory to data memory. The source address is
90 | * specified as type _prog_addressT; the next unused address
91 | * is returned.
92 | */
93 |
94 | static __inline__ _prog_addressT
95 | _memcpy_p2d16(char *dest, _prog_addressT src, unsigned int len) {
96 | return _memcpy_helper(src.w.low, src.w.high, dest, len, 0);
97 | }
98 |
99 | /*
100 | * _memcpy_p2d24() copies 24 bits of data from each address
101 | * in program memory to data memory. The source address is
102 | * specified as type _prog_addressT; the next unused address
103 | * is returned.
104 | */
105 |
106 | static __inline__ _prog_addressT
107 | _memcpy_p2d24(char *dest, _prog_addressT src, unsigned int len) {
108 | return _memcpy_helper(src.w.low, src.w.high, dest, len, 1);
109 | }
110 |
111 | /*
112 | * _strncpy_p2d16() copies 16 bits of data from each address
113 | * in program memory to data memory. The operation terminates
114 | * early if a NULL char is copied. The source address is
115 | * specified as type _prog_addressT; the next unused address
116 | * is returned.
117 | */
118 |
119 | static __inline__ _prog_addressT
120 | _strncpy_p2d16(char *dest, _prog_addressT src, unsigned int len) {
121 | return _memcpy_helper(src.w.low, src.w.high, dest, len, 2);
122 | }
123 |
124 | /*
125 | * _strncpy_p2d24() copies 24 bits of data from each address
126 | * in program memory to data memory. The operation terminates
127 | * early if a NULL char is copied. The source address is
128 | * specified as type _prog_addressT; the next unused address
129 | * is returned.
130 | */
131 |
132 | static __inline__ _prog_addressT
133 | _strncpy_p2d24(char *dest, _prog_addressT src, unsigned int len) {
134 | return _memcpy_helper(src.w.low, src.w.high, dest, len, 3);
135 | }
136 |
137 | #endif
138 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2.vbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.50727
7 | 2.0
8 | {4C55E797-2C61-4D9E-807C-D712D4E2E150}
9 | WinExe
10 | Aj_Scope.My.MyApplication
11 | Aj_Scope
12 | Aj_Scope
13 | WindowsForms
14 | Aj_Scope.ico
15 |
16 |
17 | true
18 | full
19 | true
20 | true
21 | bin\Debug\
22 | Aj_Scope.xml
23 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
24 |
25 |
26 | pdbonly
27 | false
28 | true
29 | true
30 | bin\Release\
31 | Aj_Scope.xml
32 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | False
43 | ..\ZedGraph.dll
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | Aj_Scope2.vb
59 |
60 |
61 | Form
62 |
63 |
64 |
65 | True
66 | Application.myapp
67 |
68 |
69 | True
70 | True
71 | Resources.resx
72 |
73 |
74 | True
75 | Settings.settings
76 | True
77 |
78 |
79 |
80 |
81 | Aj_Scope2.vb
82 | Designer
83 |
84 |
85 | VbMyResourcesResXFileCodeGenerator
86 | Resources.Designer.vb
87 | My.Resources
88 | Designer
89 |
90 |
91 |
92 |
93 |
94 | MyApplicationCodeGenerator
95 | Application.Designer.vb
96 |
97 |
98 | SettingsSingleFileGenerator
99 | My
100 | Settings.Designer.vb
101 |
102 |
103 |
104 |
105 |
106 |
107 |
114 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2.mptags:
--------------------------------------------------------------------------------
1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
4 | !_TAG_PROGRAM_NAME Exuberant Ctags //
5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
6 | !_TAG_PROGRAM_VERSION 5.5.4 //
7 | !_TAG_REVISION_NAME MCHPTags //
8 | !_TAG_REVISION_VERSION 6.0.1 //
9 | AN C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 56;" v line:56
10 | AN2lsb C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 285;" l line:285
11 | AN2msb C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 285;" l line:285
12 | AN3lsb C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 285;" l line:285
13 | AN3msb C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 285;" l line:285
14 | CODE_PROT_OFF C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 42;" v line:42
15 | FWDTEN_OFF C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 41;" v line:41
16 | HS C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 37;" v line:37
17 | PRIOSC_PLL C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 38;" v line:38
18 | PWRT_OFF C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 43;" v line:43
19 | _CMP3Interrupt C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 68;" f line:68 signature:(void)
20 | adc_index C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 60;" v line:60
21 | busy::LATEbits.LATE4 C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 63;" d line:63 file:
22 | capture_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 297;" f line:297 signature:(void)
23 | capture_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 50;" p line:50 file: signature:(void)
24 | capture_mode C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 57;" v line:57
25 | data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 56;" v line:56
26 | data_index C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 58;" v line:58
27 | delay_cycles C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 59;" v line:59
28 | error C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 57;" v line:57
29 | fft C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 57;" v line:57
30 | get_fft1_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 450;" f line:450 signature:(void)
31 | get_fft1_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 53;" p line:53 file: signature:(void)
32 | get_fft2_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 464;" f line:464 signature:(void)
33 | get_fft2_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 54;" p line:54 file: signature:(void)
34 | get_normal_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 432;" f line:432 signature:(void)
35 | get_normal_data C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 52;" p line:52 file: signature:(void)
36 | hw_reset::LATEbits.LATE5 C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 64;" d line:64 file:
37 | input_string C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 56;" v line:56
38 | main C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 127;" f line:127
39 | readVref C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 282;" f line:282 signature:(void)
40 | readVref C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 49;" p line:49 file: signature:(void)
41 | sampling_mode C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 57;" v line:57
42 | sampling_rate C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 57;" v line:57
43 | set_sampling C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 381;" f line:381 signature:(unsigned char rate)
44 | set_sampling C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 51;" p line:51 file: signature:(unsigned char rate)
45 | sliding_delay C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 59;" v line:59
46 | sliding_delay_cycles C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 60;" v line:60
47 | temp C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 433;" l line:433
48 | temp C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 451;" l line:451
49 | temp C:\Documents and Settings\ajoy\My Documents\Aj-PIC\029_Aj_SimplerScope\015_Scope2\Scope2.c 465;" l line:465
50 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/My Project/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_draft.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | Aj-Scope2
123 |
124 | USB Osciloscope
125 | for
126 | Students & Hobbyists
127 |
128 |
129 | By
130 | Ajoy Raman
131 | http://www.ajoyraman.in
132 |
133 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_draft1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | Aj-Scope2
123 |
124 | USB Osciloscope
125 | for
126 | Students & Hobbyists
127 |
128 |
129 | By
130 | Ajoy Raman
131 | http://www.ajoyraman.in
132 |
133 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_working1.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | Aj-Scope2
123 |
124 | USB Osciloscope
125 | for
126 | Students & Hobbyists
127 |
128 |
129 | By
130 | Ajoy Raman
131 | http://www.ajoyraman.in
132 |
133 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Aj_Scope/Aj_Scope2_working2.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | Aj-Scope2
123 |
124 | USB Osciloscope
125 | for
126 | Students & Hobbyists
127 |
128 |
129 | By
130 | Ajoy Raman
131 | http://www.ajoyraman.in
132 |
133 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_while.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | //
8 | // ------------------------------------------------------------
9 | //
10 | //
11 | //
12 | //-------------------------------------------------------------
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | //#include
19 |
20 | //Fuzes 16 MHz crystal
21 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
22 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
23 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
24 | //FCY = Primary Osc X 2
25 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
26 | _FGS(CODE_PROT_OFF); //Turn off code protect
27 | _FPOR( PWRT_OFF ); //Turn off power up timer
28 |
29 |
30 |
31 |
32 | //Function Prototypes
33 | void readVref(void);
34 | void capture_data(void);
35 | void set_sampling(unsigned char rate);
36 |
37 | unsigned char input_string[3],AN[405],data;
38 | char capture_mode=0,error=0;
39 | int data_index, adc_index;
40 | unsigned long delay_cycles=10, sliding_delay_cycles;
41 |
42 |
43 | #define busy LATEbits.LATE4 // Busy
44 |
45 |
46 | //----------------------------------------------------------------------
47 | //Main Program
48 | int main( ){
49 | __delay32(3200);//initial delay 100uSec
50 | initUart(); //Initialise the UART
51 | __delay32(3200);//initial delay 100uSec
52 |
53 | //TRISA=0; //PortA all inputs
54 | TRISE=0; //PortE all outputs
55 | initialiseADC ();
56 | setupOC1PWM();
57 | setupOC2PWM();
58 |
59 | busy=1;
60 |
61 | //AjScope
62 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
63 |
64 |
65 |
66 | while(1){
67 |
68 | for (data_index=1;data_index<=3;++data_index)
69 | input_string[data_index-1]= getHex();
70 |
71 | if (input_string[0]==65){ // "A" ABORT
72 | goto restart;//return(0);
73 | }
74 | else;
75 |
76 | //putHex(input_string[0]);
77 | //putHex(input_string[1]);
78 | //putHex(input_string[2]);
79 |
80 |
81 |
82 | if ( error==0) {
83 |
84 | if (input_string[0]==73){ //"I" Identify
85 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
86 | }
87 | else if (input_string[0]==65) //"A" Abort
88 | putHex(65);
89 | else if (input_string[0]==82){ //"R" Read Vref
90 | putHex(82);
91 | readVref();
92 | }
93 | else if (input_string[0]==68){ //"D" Send Data
94 | putHex(68);
95 | for(adc_index=0;adc_index<400;adc_index++){
96 | putHex(AN[adc_index]);//8 bit AN0 Value
97 | adc_index++;
98 | }
99 | }
100 | else if (input_string[0]==83){ //"S" Sample Rate
101 | putHex(83);
102 | set_sampling(input_string[1]);
103 | }
104 | else if (input_string[0]==78) //"N" Noise Filter
105 | putHex(78);
106 | else if (input_string[0]==67){ //"C" Capture Data
107 | putHex(67);
108 | capture_data();
109 | }
110 | else if (input_string[0]==76){ //"L" Trig Level
111 | putHex(76);
112 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
113 | }
114 | else if (input_string[0]==84){ //"T" Trig Source
115 | putHex(84);
116 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
117 | }
118 | else if (input_string[0]==80){ //"P" Trig Polarity
119 | putHex(80);
120 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
121 | }
122 | else if (input_string[0]==71) //"G" Gains
123 | putHex(71);
124 | else if (input_string[0]==79){ //"O" Offset Ch1
125 | putHex(79);
126 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
127 | }
128 | else if (input_string[0]==111){ //"o" Offset Ch2
129 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
130 | putHex(111);
131 | }
132 | else if (input_string[0]==70) //"F" FFT mode
133 | putHex(70);
134 | else if (input_string[0]==100) //"d" Delay Post Trigger
135 | putHex(100);
136 | else if (input_string[0]==116){ //"t" Test LED
137 | putHex(116);
138 | busy = ~ busy;
139 | }
140 | else { //"E" Error
141 | putHex(69);
142 | goto restart;
143 | }
144 | }
145 |
146 |
147 | //loop
148 | }
149 |
150 |
151 | restart:
152 | return(0);
153 | }
154 | void readVref(void){
155 | //Reads the value of AN2 and AN3 and returns the 10bit Value
156 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
157 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
158 |
159 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
160 | Nop();Nop();Nop();
161 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
162 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
163 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
164 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
165 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
166 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
167 | }
168 | void capture_data(void){
169 | busy=1;
170 | if (capture_mode==0) {
171 | int temp=0;
172 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
173 | while(temp<400){
174 |
175 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
176 | AN[temp]=ADCBUF0>>2;
177 | temp++;
178 | AN[temp]=ADCBUF1>>2;
179 | temp++;
180 | __delay32(delay_cycles);
181 |
182 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
183 |
184 | }
185 | }
186 |
187 | busy=0;
188 | }
189 | void set_sampling(unsigned char rate){
190 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
191 | if(rate == 1) // 2 us/sample 500kbps 20us/div
192 | delay_cycles=11;
193 | else if(rate == 2) // 5 us/sample 200kbps 50us/div
194 | delay_cycles=11+96;
195 | else if(rate == 3) // 10 us/sample 100kbps 0.1ms/div
196 | delay_cycles=11+256;
197 | else if(rate == 4) // 20 us/sample 50kbps 0.2ms/div
198 | delay_cycles=11+576;
199 | else if(rate == 5) // 50 us/sample 20kbps 0.5ms/div
200 | delay_cycles=11+1536;
201 | else if(rate == 6) // 100 us/sample 10kbps 1ms/div
202 | delay_cycles=11+3136;
203 | else if(rate == 7) // 200 us/sample 5kbps 2ms/div
204 | delay_cycles=11+6336;
205 | else if(rate == 8) // 500 us/sample 2kbps 5ms/div
206 | delay_cycles=11+15936;
207 | else if(rate == 9) // 1000 us/sample 1kbps 10ms/div
208 | delay_cycles=11+31936;
209 | else if(rate == 10) // 2000 us/sample 500bps 20ms/div
210 | delay_cycles=11+63936;
211 | else if(rate == 11) // 5000 us/sample 200ps 50ms/div
212 | delay_cycles=11+159936;
213 | else if(rate == 12) // 10000 us/sample 100bps 0.1s/div
214 | delay_cycles=11+319936;
215 | else if(rate == 13) // 20000 us/sample 50bps 0.2s/div
216 | delay_cycles=11+639936;
217 | else if(rate == 14) // 50000 us/sample 20ps 0.5s/div
218 | delay_cycles=11+1599936;
219 | else if(rate == 15) // 100000 us/sample 10bps 1.0s/div
220 | delay_cycles=11+3199936;
221 |
222 |
223 |
224 |
225 | }
226 |
227 |
228 |
229 |
230 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_while_int_normal.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | // Added the Interrupt Mode for Normal sampling
8 | //
9 | // ------------------------------------------------------------
10 | //
11 | //
12 | //
13 | //-------------------------------------------------------------
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | //#include
20 |
21 | //Fuzes 16 MHz crystal
22 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
23 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
24 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
25 | //FCY = Primary Osc X 2
26 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
27 | _FGS(CODE_PROT_OFF); //Turn off code protect
28 | _FPOR( PWRT_OFF ); //Turn off power up timer
29 |
30 |
31 |
32 |
33 | //Function Prototypes
34 | void readVref(void);
35 | void capture_data(void);
36 | void set_sampling(unsigned char rate);
37 |
38 | unsigned char input_string[3],AN[405],data;
39 | char capture_mode=1,sampling_mode=0, error=0;
40 | int data_index, adc_index;
41 | unsigned long delay_cycles=10, sliding_delay_cycles;
42 |
43 |
44 | #define busy LATEbits.LATE4 // Busy
45 | //ISR for CMP3
46 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void){
47 | //Read ADC AN0 AN3 on CMP3 Interrupt
48 | int temp=0;
49 | putHex(65);
50 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
51 | while(temp<400){
52 |
53 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
54 | AN[temp]=ADCBUF0>>2;
55 | temp++;
56 | AN[temp]=ADCBUF1>>2;
57 | temp++;
58 | __delay32(delay_cycles);
59 |
60 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
61 | // sets PEND0 to 1
62 | }
63 |
64 | IEC1bits.AC3IE =0; //Disable interrupt
65 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
66 | }
67 |
68 | //----------------------------------------------------------------------
69 | //Main Program
70 | int main( ){
71 | __delay32(3200);//initial delay 100uSec
72 | initUart(); //Initialise the UART
73 | __delay32(3200);//initial delay 100uSec
74 |
75 | //TRISA=0; //PortA all inputs
76 | TRISE=0; //PortE all outputs
77 | initialiseADC ();
78 | initialiseComp();
79 | setupOC1PWM();
80 | setupOC2PWM();
81 |
82 | busy=1;
83 |
84 | //AjScope
85 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
86 |
87 |
88 |
89 | while(1){
90 |
91 | for (data_index=1;data_index<=3;++data_index)
92 | input_string[data_index-1]= getHex();
93 |
94 | if (input_string[0]==65){ // "A" ABORT
95 | goto restart;//return(0);
96 | }
97 | else;
98 |
99 | //putHex(input_string[0]);
100 | //putHex(input_string[1]);
101 | //putHex(input_string[2]);
102 |
103 |
104 |
105 | if ( error==0) {
106 |
107 | if (input_string[0]==73){ //"I" Identify
108 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
109 | }
110 | else if (input_string[0]==65) //"A" Abort
111 | putHex(65);
112 | else if (input_string[0]==82){ //"R" Read Vref
113 | putHex(82);
114 | readVref();
115 | }
116 | else if (input_string[0]==68){ //"D" Send Data
117 | putHex(68);
118 | for(adc_index=0;adc_index<400;adc_index++){
119 | putHex(AN[adc_index]);//8 bit AN0 Value
120 | adc_index++;
121 | }
122 | }
123 | else if (input_string[0]==83){ //"S" Sample Rate
124 | putHex(83);
125 | set_sampling(input_string[1]);
126 | }
127 | else if (input_string[0]==78) //"N" Noise Filter
128 | putHex(78);
129 | else if (input_string[0]==67){ //"C" Capture Data
130 | putHex(67);
131 | capture_data();
132 | }
133 | else if (input_string[0]==76){ //"L" Trig Level
134 | putHex(76);
135 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
136 | }
137 | else if (input_string[0]==84){ //"T" Trig Source
138 | putHex(84);
139 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
140 | sampling_mode=input_string[2]; //0/1 normal/sliding
141 | }
142 | else if (input_string[0]==80){ //"P" Trig Polarity
143 | putHex(80);
144 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
145 | }
146 | else if (input_string[0]==71) //"G" Gains
147 | putHex(71);
148 | else if (input_string[0]==79){ //"O" Offset Ch1
149 | putHex(79);
150 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
151 | }
152 | else if (input_string[0]==111){ //"o" Offset Ch2
153 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
154 | putHex(111);
155 | }
156 | else if (input_string[0]==70) //"F" FFT mode
157 | putHex(70);
158 | else if (input_string[0]==100) //"d" Delay Post Trigger
159 | putHex(100);
160 | else if (input_string[0]==116){ //"t" Test LED
161 | putHex(116);
162 | busy = ~ busy;
163 | }
164 | else { //"E" Error
165 | putHex(69);
166 | goto restart;
167 | }
168 | }
169 |
170 |
171 | //loop
172 | }
173 |
174 |
175 | restart:
176 | return(0);
177 | }
178 | void readVref(void){
179 | //Reads the value of AN2 and AN3 and returns the 10bit Value
180 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
181 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
182 |
183 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
184 | Nop();Nop();Nop();
185 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
186 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
187 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
188 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
189 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
190 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
191 | }
192 | void capture_data(void){
193 | busy=1;
194 | if (capture_mode==0) {
195 | int temp=0;
196 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
197 | while(temp<400){
198 |
199 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
200 | AN[temp]=ADCBUF0>>2;
201 | temp++;
202 | AN[temp]=ADCBUF1>>2;
203 | temp++;
204 | __delay32(delay_cycles);
205 |
206 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
207 |
208 | }
209 | }
210 | else if (capture_mode==1){ // Trigger by Channel 1 Comp3A
211 | // Trig Polarity set by "P"
212 | // Trig Level set by "L"
213 |
214 | CMPCON3bits.INSEL=0; // 3A selected
215 | CMPCON3bits.CMPON=1; //Comparator ON
216 |
217 | IFS1bits.AC3IF =0; //clear interrupt flag=0
218 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
219 | }
220 | else if (capture_mode==2){ // Trigger by Channel 2 Comp3B
221 | // Trig Polarity set by "P"
222 | // Trig Level set by "L"
223 | CMPCON3bits.INSEL=1; // 3B selected
224 | CMPCON3bits.CMPON=1; //Comparator ON
225 |
226 | IFS1bits.AC3IF =0; //clear interrupt flag=0
227 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
228 | }
229 |
230 |
231 | busy=0;
232 | }
233 | void set_sampling(unsigned char rate){
234 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
235 | if(rate == 1) // 2 us/sample 500kbps 20us/div
236 | delay_cycles=11;
237 | else if(rate == 2) // 5 us/sample 200kbps 50us/div
238 | delay_cycles=11+96;
239 | else if(rate == 3) // 10 us/sample 100kbps 0.1ms/div
240 | delay_cycles=11+256;
241 | else if(rate == 4) // 20 us/sample 50kbps 0.2ms/div
242 | delay_cycles=11+576;
243 | else if(rate == 5) // 50 us/sample 20kbps 0.5ms/div
244 | delay_cycles=11+1536;
245 | else if(rate == 6) // 100 us/sample 10kbps 1ms/div
246 | delay_cycles=11+3136;
247 | else if(rate == 7) // 200 us/sample 5kbps 2ms/div
248 | delay_cycles=11+6336;
249 | else if(rate == 8) // 500 us/sample 2kbps 5ms/div
250 | delay_cycles=11+15936;
251 | else if(rate == 9) // 1000 us/sample 1kbps 10ms/div
252 | delay_cycles=11+31936;
253 | else if(rate == 10) // 2000 us/sample 500bps 20ms/div
254 | delay_cycles=11+63936;
255 | else if(rate == 11) // 5000 us/sample 200ps 50ms/div
256 | delay_cycles=11+159936;
257 | else if(rate == 12) // 10000 us/sample 100bps 0.1s/div
258 | delay_cycles=11+319936;
259 | else if(rate == 13) // 20000 us/sample 50bps 0.2s/div
260 | delay_cycles=11+639936;
261 | else if(rate == 14) // 50000 us/sample 20ps 0.5s/div
262 | delay_cycles=11+1599936;
263 | else if(rate == 15) // 100000 us/sample 10bps 1.0s/div
264 | delay_cycles=11+3199936;
265 |
266 |
267 |
268 |
269 | }
270 |
271 |
272 |
273 |
274 |
--------------------------------------------------------------------------------
/VB.Net2-Code/Zg_Code_Temp.vb:
--------------------------------------------------------------------------------
1 | #Region "Plot"
2 | Private Sub Plot_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Plot_Button.Click
3 | Dim rowno As Integer
4 |
5 | 'Check what_to_plot
6 | what_to_plot()
7 | 'Dim display_y1, display_y2, display_xy, display_dft1, display_dft2 As Boolean
8 | 'Dim DataArray(401, 4) As String
9 | 'Dim xcolumn, ycolumn, y1column As Integer
10 | Plot_Error = False 'we will check for DBNull's and exit
11 | 'Start of Plot
12 | Dim myPane As GraphPane = Aj_ZG1.GraphPane
13 | 'Clear Previous Graph if Over Plot is Not Checked
14 | If Overplot = True Then
15 | Else
16 | Aj_ZG1.GraphPane.CurveList.Clear()
17 | Aj_ZG1.GraphPane.GraphObjList.Clear()
18 | End If
19 |
20 | ' Set the Title
21 | myPane.Title.Text = "Aj Test Plot" 'Title_TextBox.Text
22 |
23 | Dim list As New PointPairList
24 | Dim list2 As New PointPairList
25 | Dim x, y, y1 As String 'Double
26 |
27 | 'Proceed with data processing Plotting only if no null values are detected
28 | 'Populate the List assume no null values
29 | If Plot_Error = False Then
30 | For rowno = 1 To (Data_Length + 1)
31 | 'x and y data
32 | x = DataArray(rowno, xcolumn)
33 | y = DataArray(rowno, ycolumn)
34 | list.Add(x, y)
35 |
36 | 'Data for y1
37 | If display_y1 = True Then
38 | y1 = DataArray(rowno, y1column)
39 | list2.Add(x, y1)
40 | End If
41 | Next
42 |
43 |
44 |
45 | ' Generate a red curve with diamond symbols, and "Alpha" in the legend
46 | Dim myCurve As LineItem
47 | If Symbol_RadioButton.Checked Then
48 | myCurve = myPane.AddCurve("Dog", list, Color.Red, SymbolType.Diamond)
49 | ' Fill the symbols with white
50 | myCurve.Symbol.Fill = New Fill(Color.White)
51 | Else
52 | myCurve = myPane.AddCurve("Dog", list, Color.Red, SymbolType.None) 'No Symbols
53 | End If
54 |
55 |
56 |
57 | ' Generate a blue curve with circle symbols, and "Beta" in the legend
58 | If display_y1 = True Then
59 | If Symbol_RadioButton.Checked Then
60 | myCurve = myPane.AddCurve("Rat", list2, Color.Blue, SymbolType.Circle)
61 | ' Fill the symbols with white
62 | myCurve.Symbol.Fill = New Fill(Color.White)
63 | ' Associate this curve with the Y2 axis
64 | myCurve.IsY2Axis = True
65 | Else
66 | myCurve = myPane.AddCurve("Elephant", list2, Color.Blue, SymbolType.None)
67 | ' Fill the symbols with white
68 | myCurve.Symbol.Fill = New Fill(Color.White)
69 | ' Associate this curve with the Y2 axis
70 | myCurve.IsY2Axis = True
71 | End If
72 |
73 | End If
74 |
75 | ' Show the x axis grid
76 | myPane.XAxis.MajorGrid.IsVisible = True
77 |
78 | ' Make the Y axis scale red
79 | myPane.YAxis.Scale.FontSpec.FontColor = Color.Red
80 | myPane.YAxis.Title.FontSpec.FontColor = Color.Red
81 | ' turn off the opposite tics so the Y tics don't show up on the Y2 axis
82 | myPane.YAxis.MajorTic.IsOpposite = False
83 | myPane.YAxis.MinorTic.IsOpposite = False
84 | ' Don't display the Y zero line
85 | myPane.YAxis.MajorGrid.IsZeroLine = False
86 | ' Align the Y axis labels so they are flush to the axis
87 | myPane.YAxis.Scale.Align = AlignP.Inside
88 | ' Display the Y2 axis grid lines
89 | myPane.YAxis.MajorGrid.IsVisible = True
90 |
91 |
92 | ' Manually set the axis range
93 |
94 | myPane.YAxis.Scale.Min = -10
95 | myPane.YAxis.Scale.Max = 10
96 | myPane.XAxis.Scale.Min = 0
97 | myPane.XAxis.Scale.Max = Data_Length
98 |
99 |
100 | 'Enable the Y and Y2 axis display
101 | myPane.YAxis.IsVisible = True
102 |
103 | If display_y1 = True Then
104 | ' Enable the Y2 axis display
105 | myPane.Y2Axis.IsVisible = True
106 | End If
107 |
108 | ' Make the Y2 axis scale blue
109 | myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue
110 | myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue
111 | ' turn off the opposite tics so the Y2 tics don't show up on the Y axis
112 | myPane.Y2Axis.MajorTic.IsOpposite = False
113 | myPane.Y2Axis.MinorTic.IsOpposite = False
114 | ' Display the Y2 axis grid lines
115 | myPane.Y2Axis.MajorGrid.IsVisible = True
116 | ' Align the Y2 axis labels so they are flush to the axis
117 | myPane.Y2Axis.Scale.Align = AlignP.Inside
118 |
119 |
120 | ' Fill the axis background with a gradient
121 | myPane.Chart.Fill = New Fill(Color.White, Color.LightGray, 45.0F)
122 |
123 | ' Add a text box with Aj-Scope Signature
124 | '
125 | Dim mytext As New TextObj("Aj-" _
126 | & "S" & "c" & "o" & "p" & "e", 0.02F, 0.97F, _
127 | CoordType.ChartFraction, AlignH.Left, AlignV.Bottom)
128 | 'mytext.FontSpec.StringAlignment = StringAlignment.Near
129 | myPane.GraphObjList.Add(mytext)
130 |
131 |
132 |
133 | ' Add a text box with instructions
134 | '
135 | 'Dim text As New TextObj( _
136 | '"Zoom: left mouse & drag" & Chr(10) & "Pan: middle mouse & drag" & Chr(10) _
137 | '& "Context Menu: right mouse", _
138 | '0.05F, 0.95F, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom)
139 | 'text.FontSpec.StringAlignment = StringAlignment.Near
140 | 'myPane.GraphObjList.Add(text)
141 |
142 | ' Enable scrollbars if needed
143 | Aj_ZG1.IsShowHScrollBar = True
144 | Aj_ZG1.IsShowVScrollBar = True
145 | Aj_ZG1.IsAutoScrollRange = True
146 | If display_y1 = False Then 'Y2 Not Required
147 | Aj_ZG1.IsScrollY2 = True
148 | End If
149 | Aj_ZG1.IsShowPointValues = True
150 |
151 | ' Size the control to fit the window
152 | 'SetSize()
153 |
154 | ' Tell ZedGraph to calculate the axis ranges
155 | ' Note that you MUST call this after enabling IsAutoScrollRange,
156 | 'since AxisChange() sets
157 | ' up the proper scrolling parameters
158 | Aj_ZG1.AxisChange()
159 | ' Make sure the Graph gets redrawn
160 | Aj_ZG1.Invalidate()
161 |
162 | ' Size the control to fit the window
163 | SetSize()
164 |
165 | Else
166 | MessageBox.Show("Null Entries Set To 0 - Exiting")
167 | End If
168 | End Sub
169 | Private Sub Aj_ZG1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs)
170 | SetSize()
171 | End Sub
172 | Private Sub SetSize()
173 | 'Dim loc As New Point(0, 140)
174 | 'Aj_ZG1.Location = loc()
175 | ' Leave a small margin around the outside of the control
176 | Dim size1 As New Size(Me.ClientRectangle.Width - 200, Me.ClientRectangle.Height - 200) 'Rectangle
177 | Dim size2 As New Size(Me.ClientRectangle.Height - 200, Me.ClientRectangle.Height - 200) 'Square
178 |
179 | 'Dim size As New Size(Me.ClientRectangle.Height - 50, Me.ClientRectangle.Height - 50)
180 | If display_y1 = True Then
181 | Aj_ZG1.Size = size1
182 | Else
183 | Aj_ZG1.Size = size2
184 | End If
185 |
186 | End Sub
187 | Private Sub what_to_plot()
188 | 'Dim display_x, display_y, display_y1 As Boolean
189 | 'Dim xcolumn, ycolumn, y1column As Integer
190 |
191 | display_y = False
192 | display_y1 = False
193 |
194 | ' XLabel_TextBox.Text
195 |
196 | If BothCh_Display_RadioButton.Checked Then
197 | display_y = True
198 | display_y1 = True
199 | xcolumn = 0
200 | ycolumn = 1
201 | y1column = 2
202 | myPane.YAxis.Title.Text = "Ch1 Volts"
203 | myPane.Y2Axis.Title.Text = "Ch2 Volts"
204 | myPane.XAxis.Title.Text = Sample_Rate_DomainUpDown.Text
205 | ElseIf CH1_Display_RadioButton.Checked() Then
206 | display_y = True
207 | xcolumn = 0
208 | ycolumn = 1
209 | myPane.YAxis.Title.Text = "Ch1 Volts"
210 | myPane.XAxis.Title.Text = Sample_Rate_DomainUpDown.Text
211 | ElseIf CH2_Display_RadioButton.Checked() Then
212 | display_y = True
213 | xcolumn = 0
214 | ycolumn = 2
215 | myPane.YAxis.Title.Text = "Ch2 Volts"
216 | myPane.XAxis.Title.Text = Sample_Rate_DomainUpDown.Text
217 | ElseIf XY_Display_RadioButton.Checked() Then
218 | display_y = True
219 | xcolumn = 1
220 | ycolumn = 2
221 | myPane.XAxis.Title.Text = "Ch1 Volts"
222 | myPane.YAxis.Title.Text = "Ch2 Volts"
223 | ElseIf DFT_CH1_Display_RadioButton.Checked() Then
224 | display_y = True
225 | xcolumn = 5
226 | ycolumn = 3
227 | myPane.YAxis.Title.Text = "Ch1 Volts"
228 | myPane.XAxis.Title.Text = "Frequency"
229 | ElseIf DFT_CH2_Display_RadioButton.Checked() Then
230 | display_y = True
231 | xcolumn = 5
232 | ycolumn = 4
233 | myPane.YAxis.Title.Text = "Ch1 Volts"
234 | myPane.XAxis.Title.Text = "Frequency"
235 | End If
236 | End Sub
237 | #End Region
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_V0_noFFT.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | // Added the Interrupt Mode for Normal sampling
8 | // Added the Interrupt Mode for Sliding CH1
9 | //
10 | // ------------------------------------------------------------
11 | //
12 | //
13 | //
14 | //-------------------------------------------------------------
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | //Fuzes 16 MHz crystal
23 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
24 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
25 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
26 | //FCY = Primary Osc X 2
27 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
28 | _FGS(CODE_PROT_OFF); //Turn off code protect
29 | _FPOR( PWRT_OFF ); //Turn off power up timer
30 |
31 |
32 |
33 |
34 | //Function Prototypes
35 | void readVref(void);
36 | void capture_data(void);
37 | void set_sampling(unsigned char rate);
38 |
39 | unsigned char input_string[3],AN[405],data;
40 | char capture_mode=1,sampling_mode=0, error=0;
41 | int data_index, sliding_delay;
42 | unsigned long delay_cycles=10;
43 | unsigned long sliding_delay_cycles, adc_index;
44 |
45 |
46 | #define busy LATEbits.LATE4 // Busy
47 |
48 |
49 | //ISR for CMP3
50 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void){
51 | //Normal Mode
52 | if (sampling_mode==0){ //Normal Mode
53 | int temp=0;
54 | //putHex(65);
55 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
56 | while(temp<400){
57 |
58 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
59 | AN[temp]=ADCBUF0>>2;
60 | temp++;
61 | AN[temp]=ADCBUF1>>2;
62 | temp++;
63 | __delay32(delay_cycles);
64 |
65 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
66 | // sets PEND0 to 1
67 | }
68 | busy=0;
69 | IEC1bits.AC3IE =0; //Disable interrupt
70 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
71 | }
72 | //Sliding Mode
73 | else if (sampling_mode==1){ //Sliding Mode
74 |
75 | __delay32(sliding_delay_cycles);
76 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
77 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
78 | AN[adc_index]=ADCBUF0>>2;
79 | adc_index++;
80 | AN[adc_index]=ADCBUF1>>2;
81 | adc_index++;
82 |
83 | IEC1bits.AC3IE =0; //Disable interrupt
84 | }
85 | }
86 |
87 | //----------------------------------------------------------------------
88 | //Main Program
89 | int main( ){
90 | __delay32(3200);//initial delay 100uSec
91 | initUart(); //Initialise the UART
92 | __delay32(3200);//initial delay 100uSec
93 |
94 | //TRISA=0; //PortA all inputs
95 | TRISE=0; //PortE all outputs
96 | initialiseADC ();
97 | initialiseComp();
98 | setupOC1PWM();
99 | setupOC2PWM();
100 |
101 | busy=1;
102 |
103 | //AjScope
104 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
105 |
106 | __delay32(3200000); //initial delay 1Sec
107 |
108 | busy=0;
109 |
110 |
111 | while(1){
112 |
113 | for (data_index=1;data_index<=3;++data_index)
114 | input_string[data_index-1]= getHex();
115 |
116 | if (input_string[0]==65){ // "A" ABORT
117 | goto restart;
118 | }
119 | else;
120 |
121 | //putHex(input_string[0]);
122 | //putHex(input_string[1]);
123 | //putHex(input_string[2]);
124 |
125 |
126 |
127 | if ( error==0) {
128 |
129 | if (input_string[0]==73){ //"I" Identify
130 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
131 | }
132 | else if (input_string[0]==65) //"A" Abort
133 | putHex(65);
134 | else if (input_string[0]==82){ //"R" Read Vref
135 | putHex(82);
136 | readVref();
137 | }
138 | else if (input_string[0]==68){ //"D" Send Data
139 | putHex(68);
140 | if(input_string[1]==1){
141 | for(adc_index=0;adc_index<400;adc_index++){ //CH1 Data
142 | putHex(AN[adc_index]);//8 bit AN0 Value
143 | adc_index++;
144 | }
145 | }
146 |
147 | else {
148 | for(adc_index=0;adc_index<400;adc_index++){ //Ch2 Data
149 | putHex(AN[adc_index+1]);//8 bit AN0 Value
150 | adc_index++;
151 | }
152 | }
153 | }
154 | else if (input_string[0]==83){ //"S" Sample Rate
155 | putHex(83);
156 | set_sampling(input_string[1]);
157 | }
158 | else if (input_string[0]==78) //"N" Noise Filter
159 | putHex(78);
160 | else if (input_string[0]==67){ //"C" Capture Data
161 | putHex(67);
162 | capture_data();
163 | }
164 | else if (input_string[0]==76){ //"L" Trig Level
165 | putHex(76);
166 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
167 | }
168 | else if (input_string[0]==84){ //"T" Trig Source
169 | putHex(84);
170 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
171 | }
172 | else if (input_string[0]==80){ //"P" Trig Polarity
173 | putHex(80);
174 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
175 | }
176 | else if (input_string[0]==71){ //"G" Gains
177 | putHex(71);
178 | //Gain 1/2/5 Setting 0/1/3
179 | //Pga 1/2 Setting 1/2
180 | setpga(input_string[1], 1); //gain, pga= 1
181 | setpga(input_string[2], 2); //gain, pga= 2
182 | }
183 | else if (input_string[0]==79){ //"O" Offset Ch1
184 | putHex(79);
185 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
186 | }
187 | else if (input_string[0]==111){ //"o" Offset Ch2
188 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
189 | putHex(111);
190 | }
191 | else if (input_string[0]==70) //"F" FFT mode
192 | putHex(70);
193 | else if (input_string[0]==100) //"d" Delay Post Trigger
194 | putHex(100);
195 | else if (input_string[0]==116){ //"t" Test LED
196 | putHex(116);
197 | busy = ~ busy;
198 | }
199 | else { //"E" Error
200 | putHex(69);
201 | goto restart;
202 | }
203 | }
204 |
205 |
206 | //loop
207 | }
208 |
209 |
210 | restart:
211 | return(0);
212 | }
213 | //Read Voltage Reference 10Bit
214 | void readVref(void){
215 | //Reads the value of AN2 and AN3 and returns the 10bit Value
216 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
217 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
218 |
219 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
220 | Nop();Nop();Nop();
221 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
222 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
223 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
224 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
225 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
226 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
227 | }
228 | //Capture data
229 | void capture_data(void){
230 | busy=1;
231 | //Auto Mode
232 | if (capture_mode==0) { //Auto Mode "Free Running"
233 | int temp=0;
234 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
235 | while(temp<400){
236 |
237 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
238 | AN[temp]=ADCBUF0>>2;
239 | temp++;
240 | AN[temp]=ADCBUF1>>2;
241 | temp++;
242 | __delay32(delay_cycles);
243 |
244 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
245 |
246 | }
247 | busy=0;
248 | }
249 | //CH1 Normal Mode
250 | else if (capture_mode==1){ // Trigger by Channel 1 Comp3A
251 | // Trig Polarity set by "P"
252 | // Trig Level set by "L"
253 |
254 | CMPCON3bits.INSEL=0; // 3A selected
255 | CMPCON3bits.CMPON=1; //Comparator ON
256 |
257 | if (sampling_mode==0){ //Normal Mode
258 | IFS1bits.AC3IF =0; //clear interrupt flag=0
259 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
260 | }
261 | //CH1 Sliding Mode
262 | else if (sampling_mode==1){ //Sliding Mode
263 |
264 | adc_index=0;
265 | while (adc_index <400){
266 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 ) + 11;
267 |
268 | IFS1bits.AC3IF =0; //clear interrupt flag=0
269 | busy=1;
270 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
271 | }
272 | busy=0;
273 | }
274 | }
275 | //CH2 Normal Mode
276 | else if (capture_mode==2){ // Trigger by Channel 2 Comp3B
277 | // Trig Polarity set by "P"
278 | // Trig Level set by "L"
279 | CMPCON3bits.INSEL=1; // 3B selected
280 | CMPCON3bits.CMPON=1; //Comparator ON
281 |
282 | if (sampling_mode==0){ //Normal Mode
283 | IFS1bits.AC3IF =0; //clear interrupt flag=0
284 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
285 | }
286 | //CH2 Sliding Mode
287 | else if (sampling_mode==1){ //Sliding Mode
288 |
289 | adc_index=0;
290 | while (adc_index <400){
291 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 ) + 11;
292 |
293 | IFS1bits.AC3IF =0; //clear interrupt flag=0
294 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
295 | }
296 | busy=0;
297 | }
298 | }
299 |
300 |
301 | //busy=0;
302 | }
303 | void set_sampling(unsigned char rate){
304 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
305 | if(rate == 1){ // 2 us/sample 500kbps 20us/div
306 | delay_cycles=11;sampling_mode=0;}
307 | else if(rate == 2){ // 5 us/sample 200kbps 50us/div
308 | delay_cycles=11+96;sampling_mode=0;}
309 | else if(rate == 3){ // 10 us/sample 100kbps 0.1ms/div
310 | delay_cycles=11+256;sampling_mode=0; }
311 | else if(rate == 4){ // 20 us/sample 50kbps 0.2ms/div
312 | delay_cycles=11+576;sampling_mode=0;}
313 | else if(rate == 5){ // 50 us/sample 20kbps 0.5ms/div
314 | delay_cycles=11+1536;sampling_mode=0;}
315 | else if(rate == 6){ // 100 us/sample 10kbps 1ms/div
316 | delay_cycles=11+3136;sampling_mode=0;}
317 | else if(rate == 7){ // 200 us/sample 5kbps 2ms/div
318 | delay_cycles=11+6336;sampling_mode=0;}
319 | else if(rate == 8){ // 500 us/sample 2kbps 5ms/div
320 | delay_cycles=11+15936;sampling_mode=0;}
321 | else if(rate == 9){ // 1000 us/sample 1kbps 10ms/div
322 | delay_cycles=11+31936;sampling_mode=0;}
323 | else if(rate == 10){ // 2000 us/sample 500bps 20ms/div
324 | delay_cycles=11+63936;sampling_mode=0;}
325 | else if(rate == 11){ // 5000 us/sample 200ps 50ms/div
326 | delay_cycles=11+159936;sampling_mode=0;}
327 | else if(rate == 12){ // 10000 us/sample 100bps 0.1s/div
328 | delay_cycles=11+319936;sampling_mode=0;}
329 | else if(rate == 13){ // 20000 us/sample 50bps 0.2s/div
330 | delay_cycles=11+639936;sampling_mode=0;}
331 | else if(rate == 14){ // 50000 us/sample 20bps 0.5s/div
332 | delay_cycles=11+1599936;sampling_mode=0;}
333 | else if(rate == 15){ // 100000 us/sample 10bps 1.0s/div
334 | delay_cycles=11+3199936;sampling_mode=0;}
335 | //----------------------------------Sliding Mode
336 | else if(rate == 16){ // 1us shift/sample 1msps 10us/div
337 | sliding_delay=320;sampling_mode=1;}
338 | else if(rate == 17){ // 0.5us shift/sample 2msps 5us/div
339 | sliding_delay=160;sampling_mode=1;}
340 | else if(rate == 18){ // 0.2us shift/sample 5msps 2us/div
341 | sliding_delay=64;sampling_mode=1;}
342 | else if(rate == 19){ // 0.1us shift/sample 10msps 1us/div
343 | sliding_delay=32;sampling_mode=1;}
344 | else if(rate == 20){ // 0.05us shift/sample 20msps 0.5us/div
345 | sliding_delay=16;sampling_mode=1;}
346 |
347 |
348 | //for sliding_delay = 320 1.0usec increments every 32 = 1Mbps
349 | // = 160 0.5usec increment every 16 = 2Mbps
350 | // = 64 0.2usec increment every 6.4 = 5Mbps
351 | // = 32 0.1usec increment every 3.2 = 10Mbps
352 | // = 16 0.05usec increment every 1.6 = 20Mbps
353 | }
354 |
355 |
356 |
357 |
358 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_V2with FFT.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | // Added the Interrupt Mode for Normal sampling
8 | // Added the Interrupt Mode for Sliding CH1
9 | // Added the FFT mode
10 | // ------------------------------------------------------------
11 | //
12 | //
13 | //
14 | //-------------------------------------------------------------
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | //Fuzes 16 MHz crystal
23 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
24 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
25 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
26 | //FCY = Primary Osc X 2
27 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
28 | _FGS(CODE_PROT_OFF); //Turn off code protect
29 | _FPOR( PWRT_OFF ); //Turn off power up timer
30 |
31 |
32 |
33 |
34 | //Function Prototypes
35 | void readVref(void);
36 | void capture_data(void);
37 | void set_sampling(unsigned char rate);
38 | void get_normal_data(void);
39 | void get_fft1_data(void);
40 | void get_fft2_data(void);
41 |
42 | unsigned char input_string[3],AN[405],data;
43 | char capture_mode=0,sampling_mode=0, error=0,fft=0;
44 | int data_index;
45 | unsigned long delay_cycles=10,sliding_delay;
46 | unsigned long sliding_delay_cycles, adc_index;
47 |
48 |
49 | #define busy LATEbits.LATE4 // Busy
50 | #define hw_reset LATEbits.LATE5 // HW_Reset
51 |
52 |
53 | //ISR for CMP3
54 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void){
55 | //Normal Triggered Non-Sliding Mode
56 | if (sampling_mode==0){
57 | if(fft==0){ //AN0 & AN1
58 | get_normal_data();
59 | busy=0;
60 | IEC1bits.AC3IE =0; //Disable interrupt
61 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
62 | }
63 | else if(fft==1){ //AN0
64 | get_fft1_data();
65 | busy=0;
66 | IEC1bits.AC3IE =0; //Disable interrupt
67 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
68 | }
69 | else if(fft==2){ // AN1
70 | get_fft2_data();
71 | busy=0;
72 | IEC1bits.AC3IE =0; //Disable interrupt
73 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
74 | }
75 | }
76 | //Triggered Sliding Mode
77 | else if (sampling_mode==1){ //Sliding Mode
78 | if(fft==0){ //AN0 & AN1
79 | __delay32(sliding_delay_cycles);
80 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
81 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
82 | AN[adc_index]=ADCBUF0>>2;
83 | adc_index++;
84 | AN[adc_index]=ADCBUF1>>2;
85 | adc_index++;
86 |
87 | IEC1bits.AC3IE =0; //Disable interrupt
88 | }
89 | else if(fft==1){ //AN0
90 | __delay32(sliding_delay_cycles);
91 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
92 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
93 | AN[adc_index]=ADCBUF0>>2;
94 | adc_index++;
95 | IEC1bits.AC3IE =0; //Disable interrupt
96 | }
97 | if(fft==2){ // AN1
98 | __delay32(sliding_delay_cycles);
99 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
100 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
101 | AN[adc_index]=ADCBUF1>>2;
102 | adc_index++;
103 | IEC1bits.AC3IE =0; //Disable interrupt
104 | }
105 | }
106 | }
107 |
108 | //----------------------------------------------------------------------
109 | //Main Program
110 | int main( ){
111 | __delay32(3200);//initial delay 100uSec
112 | initUart(); //Initialise the UART
113 | __delay32(3200);//initial delay 100uSec
114 |
115 | hw_reset=0;
116 | //TRISA=0; //PortA all inputs
117 | TRISE=0; //PortE all outputs
118 | initialiseADC ();
119 | initialiseComp();
120 | setupOC1PWM();
121 | setupOC2PWM();
122 |
123 | busy=1;
124 |
125 | //AjScope
126 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
127 |
128 | __delay32(3200000); //initial delay 1Sec
129 |
130 | busy=0;
131 |
132 |
133 | while(1){
134 |
135 | for (data_index=1;data_index<=3;++data_index)
136 | input_string[data_index-1]= getHex();
137 |
138 | if (input_string[0]==65){ // "A" ABORT
139 | hw_reset=1;
140 | }
141 | else;
142 |
143 | //putHex(input_string[0]);
144 | //putHex(input_string[1]);
145 | //putHex(input_string[2]);
146 |
147 |
148 |
149 | if ( error==0) {
150 |
151 | if (input_string[0]==73){ //"I" Identify
152 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
153 | }
154 | else if (input_string[0]==65) //"A" Abort
155 | putHex(65);
156 | else if (input_string[0]==82){ //"R" Read Vref
157 | putHex(82);
158 | readVref();
159 | }
160 | else if (input_string[0]==68){ //"D" Send Data
161 | putHex(68);
162 | if(input_string[1]==1){ //CH1
163 | for(adc_index=0;adc_index<400;adc_index++){ //CH1 Data
164 | putHex(AN[adc_index]);//8 bit AN0 Value
165 | adc_index++;
166 | }
167 | }
168 | else if (input_string[1]==2){//CH2
169 | for(adc_index=0;adc_index<400;adc_index++){ //Ch2 Data
170 | putHex(AN[adc_index+1]);//8 bit AN0 Value
171 | adc_index++;
172 | }
173 | }
174 | else {//FFT
175 | for(adc_index=0;adc_index<400;adc_index++){ //All Data
176 | putHex(AN[adc_index]);//8 bit AN0 Value
177 | }
178 | }
179 | }
180 | else if (input_string[0]==83){ //"S" Sample Rate
181 | putHex(83);
182 | set_sampling(input_string[1]);
183 | }
184 | else if (input_string[0]==78) //"N" Noise Filter
185 | putHex(78);
186 | else if (input_string[0]==67){ //"C" Capture Data
187 | putHex(67);
188 | capture_data();
189 | }
190 | else if (input_string[0]==76){ //"L" Trig Level
191 | putHex(76);
192 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
193 | }
194 | else if (input_string[0]==84){ //"T" Trig Source
195 | putHex(84);
196 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
197 | }
198 | else if (input_string[0]==80){ //"P" Trig Polarity
199 | putHex(80);
200 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
201 | }
202 | else if (input_string[0]==71){ //"G" Gains
203 | putHex(71);
204 | //Gain 1/2/5 Setting 0/1/3
205 | //Pga 1/2 Setting 1/2
206 | setpga(input_string[1], 1); //gain, pga= 1
207 | setpga(input_string[2], 2); //gain, pga= 2
208 | }
209 | else if (input_string[0]==79){ //"O" Offset Ch1
210 | putHex(79);
211 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
212 | }
213 | else if (input_string[0]==111){ //"o" Offset Ch2
214 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
215 | putHex(111);
216 | }
217 | else if (input_string[0]==70){ //"F" FFT mode
218 | putHex(70);
219 | fft=input_string[1]; // 0/1/2 AN0&1/AN0/AN1
220 | }
221 | else if (input_string[0]==100) //"d" Delay Post Trigger
222 | putHex(100);
223 | else if (input_string[0]==116){ //"t" Test LED
224 | putHex(116);
225 | busy = ~ busy;
226 | }
227 | else { //"E" Error
228 | putHex(69);
229 | goto restart;
230 | }
231 | }
232 |
233 |
234 | //loop
235 | }
236 |
237 |
238 | restart:
239 | return(0);
240 | }
241 | //Read Voltage Reference 10Bit
242 | void readVref(void){
243 | //Reads the value of AN2 and AN3 and returns the 10bit Value
244 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
245 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
246 |
247 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
248 | Nop();Nop();Nop();
249 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
250 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
251 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
252 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
253 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
254 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
255 | }
256 | //Capture data
257 | void capture_data(void){
258 | busy=1;
259 | //Auto Mode "Free Running"
260 | if (capture_mode==0) {
261 | if(fft==0){ //AN0 & AN1
262 | get_normal_data();
263 | busy=0;
264 | }
265 | else if(fft==1){ //AN1
266 | get_fft1_data();
267 | busy=0;
268 | }
269 | else if(fft==2){ //AN2
270 | get_fft2_data();
271 | busy=0;
272 | }
273 | }
274 | //CH1 Triggered Normal Non-Sliding Mode
275 | else if (capture_mode==1){ // Trigger by Channel 1 Comp3A
276 | // Trig Polarity set by "P"
277 | // Trig Level set by "L"
278 | CMPCON3bits.INSEL=0; // 3A selected
279 | CMPCON3bits.CMPON=1; //Comparator ON
280 |
281 | if (sampling_mode==0){ //Normal Non-Sliding Mode
282 | //ISR Collects the Data based on fft=0/1/2 modes
283 | IFS1bits.AC3IF =0; //clear interrupt flag=0
284 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
285 | }
286 | //CH1 Triggered Sliding Mode
287 | else if (sampling_mode==1){ //Sliding Mode
288 |
289 | adc_index=0;
290 | while (adc_index <400){
291 | if(fft==0)
292 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 ) + 11;
293 | else
294 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 ) + 11;
295 |
296 | IFS1bits.AC3IF =0; //clear interrupt flag=0
297 | //ISR Collects the Data based on fft=0/1/2 modes
298 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
299 | }
300 | busy=0;
301 | }
302 | }
303 | //CH2 Normal Mode
304 | else if (capture_mode==2){ // Trigger by Channel 2 Comp3B
305 | // Trig Polarity set by "P"
306 | // Trig Level set by "L"
307 | CMPCON3bits.INSEL=1; // 3B selected
308 | CMPCON3bits.CMPON=1; //Comparator ON
309 |
310 | if (sampling_mode==0){ //Normal Mode
311 | //ISR Collects the Data based on fft=0/1/2 modes
312 | IFS1bits.AC3IF =0; //clear interrupt flag=0
313 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
314 | }
315 | //CH2 Sliding Mode
316 | else if (sampling_mode==1){ //Sliding Mode
317 |
318 | adc_index=0;
319 | while (adc_index <400){
320 | if(fft==0)
321 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 ) + 11;
322 | else
323 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 ) + 11;
324 |
325 | IFS1bits.AC3IF =0; //clear interrupt flag=0
326 | //ISR Collects the Data based on fft=0/1/2 modes
327 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
328 | }
329 | busy=0;
330 | }
331 | }
332 |
333 |
334 | //busy=0;
335 | }
336 | void set_sampling(unsigned char rate){
337 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
338 | if(rate == 1){ // 2 us/sample 500kbps 20us/div
339 | delay_cycles=11;sampling_mode=0;}
340 | else if(rate == 2){ // 5 us/sample 200kbps 50us/div
341 | delay_cycles=11+96;sampling_mode=0;}
342 | else if(rate == 3){ // 10 us/sample 100kbps 0.1ms/div
343 | delay_cycles=11+256;sampling_mode=0; }
344 | else if(rate == 4){ // 20 us/sample 50kbps 0.2ms/div
345 | delay_cycles=11+576;sampling_mode=0;}
346 | else if(rate == 5){ // 50 us/sample 20kbps 0.5ms/div
347 | delay_cycles=11+1536;sampling_mode=0;}
348 | else if(rate == 6){ // 100 us/sample 10kbps 1ms/div
349 | delay_cycles=11+3136;sampling_mode=0;}
350 | else if(rate == 7){ // 200 us/sample 5kbps 2ms/div
351 | delay_cycles=11+6336;sampling_mode=0;}
352 | else if(rate == 8){ // 500 us/sample 2kbps 5ms/div
353 | delay_cycles=11+15936;sampling_mode=0;}
354 | else if(rate == 9){ // 1000 us/sample 1kbps 10ms/div
355 | delay_cycles=11+31936;sampling_mode=0;}
356 | else if(rate == 10){ // 2000 us/sample 500bps 20ms/div
357 | delay_cycles=11+63936;sampling_mode=0;}
358 | else if(rate == 11){ // 5000 us/sample 200ps 50ms/div
359 | delay_cycles=11+159936;sampling_mode=0;}
360 | else if(rate == 12){ // 10000 us/sample 100bps 0.1s/div
361 | delay_cycles=11+319936;sampling_mode=0;}
362 | else if(rate == 13){ // 20000 us/sample 50bps 0.2s/div
363 | delay_cycles=11+639936;sampling_mode=0;}
364 | else if(rate == 14){ // 50000 us/sample 20bps 0.5s/div
365 | delay_cycles=11+1599936;sampling_mode=0;}
366 | else if(rate == 15){ // 100000 us/sample 10bps 1.0s/div
367 | delay_cycles=11+3199936;sampling_mode=0;}
368 | //----------------------------------Sliding Mode
369 | else if(rate == 16){ // 1us shift/sample 1msps 10us/div
370 | sliding_delay=320;sampling_mode=1;}
371 | else if(rate == 17){ // 0.5us shift/sample 2msps 5us/div
372 | sliding_delay=160;sampling_mode=1;}
373 | else if(rate == 18){ // 0.2us shift/sample 5msps 2us/div
374 | sliding_delay=64;sampling_mode=1;}
375 | else if(rate == 19){ // 0.1us shift/sample 10msps 1us/div
376 | sliding_delay=32;sampling_mode=1;}
377 | else if(rate == 20){ // 0.05us shift/sample 20msps 0.5us/div
378 | sliding_delay=16;sampling_mode=1;}
379 |
380 |
381 | //for sliding_delay = 320 1.0usec increments every 32 = 1Mbps
382 | // = 160 0.5usec increment every 16 = 2Mbps
383 | // = 64 0.2usec increment every 6.4 = 5Mbps
384 | // = 32 0.1usec increment every 3.2 = 10Mbps
385 | // = 16 0.05usec increment every 1.6 = 20Mbps
386 | }
387 | void get_normal_data(void){
388 | int temp=0;
389 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
390 | while(temp<400){
391 |
392 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
393 | AN[temp]=ADCBUF0>>2;
394 | temp++;
395 | AN[temp]=ADCBUF1>>2;
396 | temp++;
397 | __delay32(delay_cycles);
398 |
399 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
400 |
401 | }
402 |
403 |
404 | }
405 | void get_fft1_data(void){
406 | int temp=0;
407 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
408 | while(temp<400){
409 |
410 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
411 | AN[temp]=ADCBUF0>>2;
412 | temp++;
413 | __delay32(delay_cycles+6);
414 |
415 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
416 | // sets PEND0 to 1
417 | }
418 | }
419 | void get_fft2_data(void){
420 | int temp=0;
421 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
422 | while(temp<400){
423 |
424 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
425 | AN[temp]=ADCBUF1>>2;
426 | temp++;
427 | __delay32(delay_cycles+6);
428 |
429 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
430 | // sets PEND0 to 1
431 | }
432 | }
433 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_V1with FFT.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | // Added the Interrupt Mode for Normal sampling
8 | // Added the Interrupt Mode for Sliding CH1
9 | // Added the FFT mode
10 | // ------------------------------------------------------------
11 | //
12 | //
13 | //
14 | //-------------------------------------------------------------
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | //Fuzes 16 MHz crystal
23 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
24 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
25 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
26 | //FCY = Primary Osc X 2
27 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
28 | _FGS(CODE_PROT_OFF); //Turn off code protect
29 | _FPOR( PWRT_OFF ); //Turn off power up timer
30 |
31 |
32 |
33 |
34 | //Function Prototypes
35 | void readVref(void);
36 | void capture_data(void);
37 | void set_sampling(unsigned char rate);
38 |
39 | unsigned char input_string[3],AN[405],data;
40 | char capture_mode=0,sampling_mode=0, error=0,fft=0;
41 | int data_index, sliding_delay;
42 | unsigned long delay_cycles=10;
43 | unsigned long sliding_delay_cycles, adc_index;
44 |
45 |
46 | #define busy LATEbits.LATE4 // Busy
47 | #define hw_reset LATEbits.LATE5 // HW_Reset
48 |
49 |
50 | //ISR for CMP3
51 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void){
52 | //Normal Mode
53 | if (sampling_mode==0){ //Normal Mode
54 | if(fft==0){ //AN0 & AN1
55 | int temp=0;
56 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
57 | while(temp<400){
58 |
59 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
60 | AN[temp]=ADCBUF0>>2;
61 | temp++;
62 | AN[temp]=ADCBUF1>>2;
63 | temp++;
64 | __delay32(delay_cycles);
65 |
66 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
67 | // sets PEND0 to 1
68 | }
69 | busy=0;
70 | IEC1bits.AC3IE =0; //Disable interrupt
71 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
72 | }
73 | else if(fft==1){ //AN0
74 | int temp=0;
75 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
76 | while(temp<400){
77 |
78 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
79 | AN[temp]=ADCBUF0>>2;
80 | temp++;
81 | //AN[temp]=ADCBUF1>>2;
82 | //temp++;
83 | __delay32(delay_cycles+3);
84 |
85 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
86 | // sets PEND0 to 1
87 | }
88 | busy=0;
89 | IEC1bits.AC3IE =0; //Disable interrupt
90 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
91 | }
92 | else if(fft==2){ // AN1
93 | int temp=0;
94 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
95 | while(temp<400){
96 |
97 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
98 | //AN[temp]=ADCBUF0>>2;
99 | //temp++;
100 | AN[temp]=ADCBUF1>>2;
101 | temp++;
102 | __delay32(delay_cycles+3);
103 |
104 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
105 | // sets PEND0 to 1
106 | }
107 | busy=0;
108 | IEC1bits.AC3IE =0; //Disable interrupt
109 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
110 | }
111 | }
112 | //Sliding Mode
113 | else if (sampling_mode==1){ //Sliding Mode
114 | if(fft==0){ //AN0 & AN1
115 | __delay32(sliding_delay_cycles);
116 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
117 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
118 | AN[adc_index]=ADCBUF0>>2;
119 | adc_index++;
120 | AN[adc_index]=ADCBUF1>>2;
121 | adc_index++;
122 |
123 | IEC1bits.AC3IE =0; //Disable interrupt
124 | }
125 | else if(fft==1){ //AN0
126 | __delay32(sliding_delay_cycles);
127 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
128 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
129 | AN[adc_index]=ADCBUF0>>2;
130 | adc_index++;
131 | //AN[adc_index]=ADCBUF1>>2;
132 | //adc_index++;
133 |
134 | IEC1bits.AC3IE =0; //Disable interrupt
135 | }
136 | if(fft==2){ // AN1
137 | __delay32(sliding_delay_cycles);
138 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
139 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
140 | //AN[adc_index]=ADCBUF0>>2;
141 | //adc_index++;
142 | AN[adc_index]=ADCBUF1>>2;
143 | adc_index++;
144 |
145 | IEC1bits.AC3IE =0; //Disable interrupt
146 | }
147 | }
148 | }
149 |
150 | //----------------------------------------------------------------------
151 | //Main Program
152 | int main( ){
153 | __delay32(3200);//initial delay 100uSec
154 | initUart(); //Initialise the UART
155 | __delay32(3200);//initial delay 100uSec
156 |
157 | hw_reset=0;
158 | //TRISA=0; //PortA all inputs
159 | TRISE=0; //PortE all outputs
160 | initialiseADC ();
161 | initialiseComp();
162 | setupOC1PWM();
163 | setupOC2PWM();
164 |
165 | busy=1;
166 |
167 | //AjScope
168 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
169 |
170 | __delay32(3200000); //initial delay 1Sec
171 |
172 | busy=0;
173 |
174 |
175 | while(1){
176 |
177 | for (data_index=1;data_index<=3;++data_index)
178 | input_string[data_index-1]= getHex();
179 |
180 | if (input_string[0]==65){ // "A" ABORT
181 | hw_reset=1;
182 | }
183 | else;
184 |
185 | //putHex(input_string[0]);
186 | //putHex(input_string[1]);
187 | //putHex(input_string[2]);
188 |
189 |
190 |
191 | if ( error==0) {
192 |
193 | if (input_string[0]==73){ //"I" Identify
194 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
195 | }
196 | else if (input_string[0]==65) //"A" Abort
197 | putHex(65);
198 | else if (input_string[0]==82){ //"R" Read Vref
199 | putHex(82);
200 | readVref();
201 | }
202 | else if (input_string[0]==68){ //"D" Send Data
203 | putHex(68);
204 | if(input_string[1]==1){ //CH1
205 | for(adc_index=0;adc_index<400;adc_index++){ //CH1 Data
206 | putHex(AN[adc_index]);//8 bit AN0 Value
207 | adc_index++;
208 | }
209 | }
210 | else if (input_string[1]==2){//CH2
211 | for(adc_index=0;adc_index<400;adc_index++){ //Ch2 Data
212 | putHex(AN[adc_index+1]);//8 bit AN0 Value
213 | adc_index++;
214 | }
215 | }
216 | else {//FFT
217 | for(adc_index=0;adc_index<400;adc_index++){ //All Data
218 | putHex(AN[adc_index]);//8 bit AN0 Value
219 | }
220 | }
221 | }
222 | else if (input_string[0]==83){ //"S" Sample Rate
223 | putHex(83);
224 | set_sampling(input_string[1]);
225 | }
226 | else if (input_string[0]==78) //"N" Noise Filter
227 | putHex(78);
228 | else if (input_string[0]==67){ //"C" Capture Data
229 | putHex(67);
230 | capture_data();
231 | }
232 | else if (input_string[0]==76){ //"L" Trig Level
233 | putHex(76);
234 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
235 | }
236 | else if (input_string[0]==84){ //"T" Trig Source
237 | putHex(84);
238 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
239 | }
240 | else if (input_string[0]==80){ //"P" Trig Polarity
241 | putHex(80);
242 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
243 | }
244 | else if (input_string[0]==71){ //"G" Gains
245 | putHex(71);
246 | //Gain 1/2/5 Setting 0/1/3
247 | //Pga 1/2 Setting 1/2
248 | setpga(input_string[1], 1); //gain, pga= 1
249 | setpga(input_string[2], 2); //gain, pga= 2
250 | }
251 | else if (input_string[0]==79){ //"O" Offset Ch1
252 | putHex(79);
253 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
254 | }
255 | else if (input_string[0]==111){ //"o" Offset Ch2
256 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
257 | putHex(111);
258 | }
259 | else if (input_string[0]==70){ //"F" FFT mode
260 | putHex(70);
261 | fft=input_string[1]; // 0/1/2 AN0&1/AN0/AN1
262 | }
263 | else if (input_string[0]==100) //"d" Delay Post Trigger
264 | putHex(100);
265 | else if (input_string[0]==116){ //"t" Test LED
266 | putHex(116);
267 | busy = ~ busy;
268 | }
269 | else { //"E" Error
270 | putHex(69);
271 | goto restart;
272 | }
273 | }
274 |
275 |
276 | //loop
277 | }
278 |
279 |
280 | restart:
281 | return(0);
282 | }
283 | //Read Voltage Reference 10Bit
284 | void readVref(void){
285 | //Reads the value of AN2 and AN3 and returns the 10bit Value
286 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
287 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
288 |
289 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
290 | Nop();Nop();Nop();
291 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
292 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
293 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
294 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
295 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
296 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
297 | }
298 | //Capture data
299 | void capture_data(void){
300 | busy=1;
301 | //Auto Mode
302 | if (capture_mode==0) { //Auto Mode "Free Running"
303 | if(fft==0){ //AN0 & AN1
304 | int temp=0;
305 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
306 | while(temp<400){
307 |
308 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
309 | AN[temp]=ADCBUF0>>2;
310 | temp++;
311 | AN[temp]=ADCBUF1>>2;
312 | temp++;
313 | __delay32(delay_cycles);
314 |
315 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
316 |
317 | }
318 | busy=0;
319 | }
320 | else if(fft==1){ //AN1
321 | int temp=0;
322 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
323 | while(temp<400){
324 |
325 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
326 | AN[temp]=ADCBUF0>>2;
327 | temp++;
328 | //AN[temp]=ADCBUF1>>2;
329 | //temp++;
330 | __delay32(delay_cycles+3);
331 |
332 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
333 |
334 | }
335 | busy=0;
336 | }
337 | else if(fft==2){ //AN2
338 | int temp=0;
339 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
340 | while(temp<400){
341 |
342 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
343 | //AN[temp]=ADCBUF0>>2;
344 | //temp++;
345 | AN[temp]=ADCBUF1>>2;
346 | temp++;
347 | __delay32(delay_cycles+3);
348 |
349 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
350 |
351 | }
352 | busy=0;
353 | }
354 | }
355 | //CH1 Normal Mode
356 | else if (capture_mode==1){ // Trigger by Channel 1 Comp3A
357 | // Trig Polarity set by "P"
358 | // Trig Level set by "L"
359 |
360 | CMPCON3bits.INSEL=0; // 3A selected
361 | CMPCON3bits.CMPON=1; //Comparator ON
362 |
363 | if (sampling_mode==0){ //Normal Mode
364 | IFS1bits.AC3IF =0; //clear interrupt flag=0
365 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
366 | }
367 | //CH1 Sliding Mode
368 | else if (sampling_mode==1){ //Sliding Mode
369 |
370 | adc_index=0;
371 | while (adc_index <400){
372 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 ) + 11;
373 |
374 | IFS1bits.AC3IF =0; //clear interrupt flag=0
375 | busy=1;
376 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
377 | }
378 | busy=0;
379 | }
380 | }
381 | //CH2 Normal Mode
382 | else if (capture_mode==2){ // Trigger by Channel 2 Comp3B
383 | // Trig Polarity set by "P"
384 | // Trig Level set by "L"
385 | CMPCON3bits.INSEL=1; // 3B selected
386 | CMPCON3bits.CMPON=1; //Comparator ON
387 |
388 | if (sampling_mode==0){ //Normal Mode
389 | IFS1bits.AC3IF =0; //clear interrupt flag=0
390 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
391 | }
392 | //CH2 Sliding Mode
393 | else if (sampling_mode==1){ //Sliding Mode
394 |
395 | adc_index=0;
396 | while (adc_index <400){
397 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 ) + 11;
398 |
399 | IFS1bits.AC3IF =0; //clear interrupt flag=0
400 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
401 | }
402 | busy=0;
403 | }
404 | }
405 |
406 |
407 | //busy=0;
408 | }
409 | void set_sampling(unsigned char rate){
410 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
411 | if(rate == 1){ // 2 us/sample 500kbps 20us/div
412 | delay_cycles=11;sampling_mode=0;}
413 | else if(rate == 2){ // 5 us/sample 200kbps 50us/div
414 | delay_cycles=11+96;sampling_mode=0;}
415 | else if(rate == 3){ // 10 us/sample 100kbps 0.1ms/div
416 | delay_cycles=11+256;sampling_mode=0; }
417 | else if(rate == 4){ // 20 us/sample 50kbps 0.2ms/div
418 | delay_cycles=11+576;sampling_mode=0;}
419 | else if(rate == 5){ // 50 us/sample 20kbps 0.5ms/div
420 | delay_cycles=11+1536;sampling_mode=0;}
421 | else if(rate == 6){ // 100 us/sample 10kbps 1ms/div
422 | delay_cycles=11+3136;sampling_mode=0;}
423 | else if(rate == 7){ // 200 us/sample 5kbps 2ms/div
424 | delay_cycles=11+6336;sampling_mode=0;}
425 | else if(rate == 8){ // 500 us/sample 2kbps 5ms/div
426 | delay_cycles=11+15936;sampling_mode=0;}
427 | else if(rate == 9){ // 1000 us/sample 1kbps 10ms/div
428 | delay_cycles=11+31936;sampling_mode=0;}
429 | else if(rate == 10){ // 2000 us/sample 500bps 20ms/div
430 | delay_cycles=11+63936;sampling_mode=0;}
431 | else if(rate == 11){ // 5000 us/sample 200ps 50ms/div
432 | delay_cycles=11+159936;sampling_mode=0;}
433 | else if(rate == 12){ // 10000 us/sample 100bps 0.1s/div
434 | delay_cycles=11+319936;sampling_mode=0;}
435 | else if(rate == 13){ // 20000 us/sample 50bps 0.2s/div
436 | delay_cycles=11+639936;sampling_mode=0;}
437 | else if(rate == 14){ // 50000 us/sample 20bps 0.5s/div
438 | delay_cycles=11+1599936;sampling_mode=0;}
439 | else if(rate == 15){ // 100000 us/sample 10bps 1.0s/div
440 | delay_cycles=11+3199936;sampling_mode=0;}
441 | //----------------------------------Sliding Mode
442 | else if(rate == 16){ // 1us shift/sample 1msps 10us/div
443 | sliding_delay=320;sampling_mode=1;}
444 | else if(rate == 17){ // 0.5us shift/sample 2msps 5us/div
445 | sliding_delay=160;sampling_mode=1;}
446 | else if(rate == 18){ // 0.2us shift/sample 5msps 2us/div
447 | sliding_delay=64;sampling_mode=1;}
448 | else if(rate == 19){ // 0.1us shift/sample 10msps 1us/div
449 | sliding_delay=32;sampling_mode=1;}
450 | else if(rate == 20){ // 0.05us shift/sample 20msps 0.5us/div
451 | sliding_delay=16;sampling_mode=1;}
452 |
453 |
454 | //for sliding_delay = 320 1.0usec increments every 32 = 1Mbps
455 | // = 160 0.5usec increment every 16 = 2Mbps
456 | // = 64 0.2usec increment every 6.4 = 5Mbps
457 | // = 32 0.1usec increment every 3.2 = 10Mbps
458 | // = 16 0.05usec increment every 1.6 = 20Mbps
459 | }
460 |
461 |
462 |
463 |
464 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_V3_Complete.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | // Added the Interrupt Mode for Normal sampling
8 | // Added the Interrupt Mode for Sliding CH1
9 | // Added the FFT mode with seperate functions resolving __delay32() problem
10 | // 04 Aug 2013: Changed to Tx in interrupt mode
11 | // 06 Aug 2013: Single Byte Command Identifier and Variable Length Commands
12 | // Abort Single Byte Restarts Main Program
13 | // Sends Busy "B" and Clears Busy "b"
14 | // ------------------------------------------------------------
15 | // Problems:
16 | // Cannot read BUSY
17 | //
18 | //
19 | //
20 | //-------------------------------------------------------------
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | //Fuzes 16 MHz crystal
29 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
30 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
31 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
32 | //FCY = Primary Osc X 2
33 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
34 | _FGS(CODE_PROT_OFF); //Turn off code protect
35 | _FPOR( PWRT_OFF ); //Turn off power up timer
36 |
37 |
38 |
39 |
40 | //Function Prototypes
41 | void readVref(void);
42 | void capture_data(void);
43 | void set_sampling(unsigned char rate);
44 | void get_normal_data(void);
45 | void get_fft1_data(void);
46 | void get_fft2_data(void);
47 |
48 | unsigned char input_string[3],AN[405],data;
49 | char capture_mode=0,sampling_mode=0, error=0,fft=0,busy1=10;
50 | int data_index;
51 | unsigned long delay_cycles=10,sliding_delay;
52 | unsigned long sliding_delay_cycles, adc_index;
53 |
54 |
55 | #define busy LATEbits.LATE4 // Busy
56 | #define hw_reset LATEbits.LATE5 // HW_Reset
57 |
58 |
59 | //ISR for CMP3
60 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void){
61 | //Normal Triggered Non-Sliding Mode
62 | if (sampling_mode==0){
63 | if(fft==0){ //AN0 & AN1
64 | get_normal_data();
65 | busy=0;
66 | putHex(98);
67 | IEC1bits.AC3IE =0; //Disable interrupt
68 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
69 | }
70 | else if(fft==1){ //AN0
71 | get_fft1_data();
72 | busy=0;
73 | putHex(98);
74 | IEC1bits.AC3IE =0; //Disable interrupt
75 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
76 | }
77 | else if(fft==2){ // AN1
78 | get_fft2_data();
79 | busy=0;
80 | putHex(98);
81 | IEC1bits.AC3IE =0; //Disable interrupt
82 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
83 | }
84 | }
85 | //Triggered Sliding Mode
86 | else if (sampling_mode==1){ //Sliding Mode
87 | if(fft==0){ //AN0 & AN1
88 | __delay32(sliding_delay_cycles);
89 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
90 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
91 | AN[adc_index]=ADCBUF0>>2;
92 | adc_index++;
93 | AN[adc_index]=ADCBUF1>>2;
94 | adc_index++;
95 |
96 | IEC1bits.AC3IE =0; //Disable interrupt
97 | }
98 | else if(fft==1){ //AN0
99 | __delay32(sliding_delay_cycles);
100 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
101 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
102 | AN[adc_index]=ADCBUF0>>2;
103 | adc_index++;
104 | IEC1bits.AC3IE =0; //Disable interrupt
105 | }
106 | if(fft==2){ // AN1
107 | __delay32(sliding_delay_cycles);
108 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
109 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
110 | AN[adc_index]=ADCBUF1>>2;
111 | adc_index++;
112 | IEC1bits.AC3IE =0; //Disable interrupt
113 | }
114 | }
115 | }
116 |
117 | //----------------------------------------------------------------------
118 | //Main Program
119 | int main( ){
120 | __delay32(3200);//initial delay 100uSec
121 | initUart(); //Initialise the UART
122 | __delay32(3200);//initial delay 100uSec
123 |
124 | hw_reset=0;
125 | //TRISA=0; //PortA all inputs
126 | TRISE=0; //PortE all outputs
127 | initialiseADC ();
128 | initialiseComp();
129 | setupOC1PWM();
130 | setupOC2PWM();
131 |
132 | busy=1;
133 |
134 |
135 | //AjScope
136 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
137 |
138 | __delay32(3200000); //initial delay 1Sec
139 |
140 | busy=0;
141 |
142 |
143 | while(1){
144 | input_string[0] =getHex();
145 |
146 |
147 | if ( error==0) {
148 |
149 | if (input_string[0]==73){ //"I" Identify
150 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);putHex(101);
151 | }
152 | else if (input_string[0]==65){ //"A" Abort
153 | putHex(65);
154 | goto restart;
155 | }
156 | else if (input_string[0]==66){ //"B" Read Busy
157 | putHex(66);
158 | //busy1=busy;
159 | putHex(busy1);
160 | }
161 | else if (input_string[0]==82){ //"R" Read Vref
162 | putHex(82);
163 | readVref();
164 | }
165 | else if (input_string[0]==68){ //"D" Send Data
166 | putHex(68);
167 | input_string[1]=getHex();
168 | if(input_string[1]==1){ //CH1
169 | for(adc_index=0;adc_index<400;adc_index++){ //CH1 Data
170 | putHex(AN[adc_index]);//8 bit AN0 Value
171 | adc_index++;
172 | }
173 | }
174 | else if (input_string[1]==2){//CH2
175 | for(adc_index=0;adc_index<400;adc_index++){ //Ch2 Data
176 | putHex(AN[adc_index+1]);//8 bit AN0 Value
177 | adc_index++;
178 | }
179 | }
180 | else {//FFT
181 | for(adc_index=0;adc_index<400;adc_index++){ //All Data
182 | putHex(AN[adc_index]);//8 bit AN0 Value
183 | }
184 | }
185 | }
186 | else if (input_string[0]==83){ //"S" Sample Rate
187 | putHex(83);
188 | input_string[1]=getHex();
189 | set_sampling(input_string[1]);
190 | }
191 | else if (input_string[0]==78) //"N" Noise Filter
192 | putHex(78);
193 | else if (input_string[0]==67){ //"C" Capture Data
194 | putHex(67);
195 | capture_data();
196 | }
197 | else if (input_string[0]==76){ //"L" Trig Level
198 | putHex(76);
199 | input_string[1]=getHex();
200 | input_string[2]=getHex();
201 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
202 | }
203 | else if (input_string[0]==84){ //"T" Trig Source
204 | putHex(84);
205 | input_string[1]=getHex();
206 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
207 | }
208 | else if (input_string[0]==80){ //"P" Trig Polarity
209 | putHex(80);
210 | input_string[1]=getHex();
211 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
212 | }
213 | else if (input_string[0]==71){ //"G" Gains
214 | putHex(71);
215 | input_string[1]=getHex();
216 | input_string[2]=getHex();
217 | //Gain 1/2/5 Setting 0/1/3
218 | //Pga 1/2 Setting 1/2
219 | setpga(input_string[1], 1); //gain, pga= 1
220 | setpga(input_string[2], 2); //gain, pga= 2
221 | }
222 | else if (input_string[0]==79){ //"O" Offset Ch1
223 | putHex(79);
224 | input_string[1]=getHex();
225 | input_string[2]=getHex();
226 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
227 | }
228 | else if (input_string[0]==111){ //"o" Offset Ch2
229 | putHex(111);
230 | input_string[1]=getHex();
231 | input_string[2]=getHex();
232 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
233 |
234 | }
235 | else if (input_string[0]==70){ //"F" FFT mode
236 | putHex(70);
237 | input_string[1]=getHex();
238 | fft=input_string[1]; // 0/1/2 AN0&1/AN0/AN1
239 | }
240 | else if (input_string[0]==100) //"d" Delay Post Trigger
241 | putHex(100);
242 | else if (input_string[0]==116){ //"t" Test LED
243 | putHex(116);
244 | busy = ~ busy;
245 | }
246 | else { //"E" Error
247 | putHex(69);
248 | goto restart;
249 | }
250 | }
251 |
252 |
253 | //loop
254 | }
255 |
256 |
257 | restart:
258 | return(0);
259 | }
260 | //Read Voltage Reference 10Bit
261 | void readVref(void){
262 | //Reads the value of AN2 and AN3 and returns the 10bit Value
263 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
264 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
265 |
266 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
267 | Nop();Nop();Nop();
268 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
269 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
270 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
271 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
272 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
273 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
274 | }
275 | //Capture data
276 | void capture_data(void){
277 | busy=1;putHex(66);
278 | //Auto Mode "Free Running"
279 | if (capture_mode==0) {
280 | if(fft==0){ //AN0 & AN1
281 | get_normal_data();
282 | busy=0;
283 | putHex(98);
284 | }
285 | else if(fft==1){ //AN1
286 | get_fft1_data();
287 | busy=0;
288 | putHex(98);
289 | }
290 | else if(fft==2){ //AN2
291 | get_fft2_data();
292 | busy=0;
293 | putHex(98);
294 | }
295 | }
296 | //CH1 Triggered Normal Non-Sliding Mode
297 | else if (capture_mode==1){ // Trigger by Channel 1 Comp3A
298 | // Trig Polarity set by "P"
299 | // Trig Level set by "L"
300 | CMPCON3bits.INSEL=0; // 3A selected
301 | CMPCON3bits.CMPON=1; //Comparator ON
302 |
303 | if (sampling_mode==0){ //Normal Non-Sliding Mode
304 | //ISR Collects the Data based on fft=0/1/2 modes
305 | IFS1bits.AC3IF =0; //clear interrupt flag=0
306 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
307 | }
308 | //CH1 Triggered Sliding Mode
309 | else if (sampling_mode==1){ //Sliding Mode
310 |
311 | adc_index=0;
312 | while (adc_index <400){
313 | if(fft==0)
314 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 );
315 | else
316 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 );
317 |
318 | IFS1bits.AC3IF =0; //clear interrupt flag=0
319 | //ISR Collects the Data based on fft=0/1/2 modes
320 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
321 | }
322 | busy=0;
323 | putHex(98);
324 | }
325 | }
326 | //CH2 Normal Mode
327 | else if (capture_mode==2){ // Trigger by Channel 2 Comp3B
328 | // Trig Polarity set by "P"
329 | // Trig Level set by "L"
330 | CMPCON3bits.INSEL=1; // 3B selected
331 | CMPCON3bits.CMPON=1; //Comparator ON
332 |
333 | if (sampling_mode==0){ //Normal Mode
334 | //ISR Collects the Data based on fft=0/1/2 modes
335 | IFS1bits.AC3IF =0; //clear interrupt flag=0
336 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
337 | }
338 | //CH2 Sliding Mode
339 | else if (sampling_mode==1){ //Sliding Mode
340 |
341 | adc_index=0;
342 | while (adc_index <400){
343 | if(fft==0)
344 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 );
345 | else
346 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 ) ;
347 |
348 | IFS1bits.AC3IF =0; //clear interrupt flag=0
349 | //ISR Collects the Data based on fft=0/1/2 modes
350 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
351 | }
352 | busy=0;
353 | putHex(98);
354 | }
355 | }
356 |
357 |
358 | //busy=0;
359 | }
360 | void set_sampling(unsigned char rate){
361 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
362 | if(rate == 1){ // 2 us/sample 500kbps 20us/div
363 | delay_cycles=11;sampling_mode=0;}
364 | else if(rate == 2){ // 5 us/sample 200kbps 50us/div
365 | delay_cycles=11+96;sampling_mode=0;}
366 | else if(rate == 3){ // 10 us/sample 100kbps 0.1ms/div
367 | delay_cycles=11+256;sampling_mode=0; }
368 | else if(rate == 4){ // 20 us/sample 50kbps 0.2ms/div
369 | delay_cycles=11+576;sampling_mode=0;}
370 | else if(rate == 5){ // 50 us/sample 20kbps 0.5ms/div
371 | delay_cycles=11+1536;sampling_mode=0;}
372 | else if(rate == 6){ // 100 us/sample 10kbps 1ms/div
373 | delay_cycles=11+3136;sampling_mode=0;}
374 | else if(rate == 7){ // 200 us/sample 5kbps 2ms/div
375 | delay_cycles=11+6336;sampling_mode=0;}
376 | else if(rate == 8){ // 500 us/sample 2kbps 5ms/div
377 | delay_cycles=11+15936;sampling_mode=0;}
378 | else if(rate == 9){ // 1000 us/sample 1kbps 10ms/div
379 | delay_cycles=11+31936;sampling_mode=0;}
380 | else if(rate == 10){ // 2000 us/sample 500bps 20ms/div
381 | delay_cycles=11+63936;sampling_mode=0;}
382 | else if(rate == 11){ // 5000 us/sample 200ps 50ms/div
383 | delay_cycles=11+159936;sampling_mode=0;}
384 | else if(rate == 12){ // 10000 us/sample 100bps 0.1s/div
385 | delay_cycles=11+319936;sampling_mode=0;}
386 | else if(rate == 13){ // 20000 us/sample 50bps 0.2s/div
387 | delay_cycles=11+639936;sampling_mode=0;}
388 | else if(rate == 14){ // 50000 us/sample 20bps 0.5s/div
389 | delay_cycles=11+1599936;sampling_mode=0;}
390 | else if(rate == 15){ // 100000 us/sample 10bps 1.0s/div
391 | delay_cycles=11+3199936;sampling_mode=0;}
392 | //----------------------------------Sliding Mode
393 | else if(rate == 16){ // 1us shift/sample 1msps 10us/div
394 | sliding_delay=320;sampling_mode=1;}
395 | else if(rate == 17){ // 0.5us shift/sample 2msps 5us/div
396 | sliding_delay=160;sampling_mode=1;}
397 | else if(rate == 18){ // 0.2us shift/sample 5msps 2us/div
398 | sliding_delay=64;sampling_mode=1;}
399 | else if(rate == 19){ // 0.1us shift/sample 10msps 1us/div
400 | sliding_delay=32;sampling_mode=1;}
401 | else if(rate == 20){ // 0.05us shift/sample 20msps 0.5us/div
402 | sliding_delay=16;sampling_mode=1;}
403 |
404 |
405 | //for sliding_delay = 320 1.0usec increments every 32 = 1Mbps
406 | // = 160 0.5usec increment every 16 = 2Mbps
407 | // = 64 0.2usec increment every 6.4 = 5Mbps
408 | // = 32 0.1usec increment every 3.2 = 10Mbps
409 | // = 16 0.05usec increment every 1.6 = 20Mbps
410 | }
411 | void get_normal_data(void){
412 | int temp=0;
413 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
414 | while(temp<400){
415 |
416 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
417 | AN[temp]=ADCBUF0>>2;
418 | temp++;
419 | AN[temp]=ADCBUF1>>2;
420 | temp++;
421 | __delay32(delay_cycles);
422 |
423 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
424 |
425 | }
426 |
427 |
428 | }
429 | void get_fft1_data(void){
430 | int temp=0;
431 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and store 400 samples
432 | while(temp<400){
433 |
434 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
435 | AN[temp]=ADCBUF0>>2;
436 | temp++;
437 | __delay32(delay_cycles+6);
438 |
439 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
440 | // sets PEND0 to 1
441 | }
442 | }
443 | void get_fft2_data(void){
444 | int temp=0;
445 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN1 store 400 samples
446 | while(temp<400){
447 |
448 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
449 | AN[temp]=ADCBUF1>>2;
450 | temp++;
451 | __delay32(delay_cycles+6);
452 |
453 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
454 | // sets PEND0 to 1
455 | }
456 | }
457 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_V4_withACK.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | // Added the Interrupt Mode for Normal sampling
8 | // Added the Interrupt Mode for Sliding CH1
9 | // Added the FFT mode with seperate functions resolving __delay32() problem
10 | // 04 Aug 2013: Changed to Tx in interrupt mode
11 | // 06 Aug 2013: Single Byte Command Identifier and Variable Length Commands
12 | // Abort Single Byte Restarts Main Program
13 | // Sends Busy "B" and Clears Busy "b"
14 | // ------------------------------------------------------------
15 | // Problems:
16 | // Cannot read BUSY but a Busy indication sent on 232
17 | //
18 | //
19 | //
20 | //-------------------------------------------------------------
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | //Fuzes 16 MHz crystal
29 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
30 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
31 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
32 | //FCY = Primary Osc X 2
33 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
34 | _FGS(CODE_PROT_OFF); //Turn off code protect
35 | _FPOR( PWRT_OFF ); //Turn off power up timer
36 |
37 |
38 |
39 |
40 | //Function Prototypes
41 | void readVref(void);
42 | void capture_data(void);
43 | void set_sampling(unsigned char rate);
44 | void get_normal_data(void);
45 | void get_fft1_data(void);
46 | void get_fft2_data(void);
47 |
48 | unsigned char input_string[3],AN[405],data;
49 | char capture_mode=0,sampling_mode=0, error=0,fft=0,busy1=10;
50 | int data_index;
51 | unsigned long delay_cycles=10,sliding_delay;
52 | unsigned long sliding_delay_cycles, adc_index;
53 |
54 |
55 | #define busy LATEbits.LATE4 // Busy
56 | #define hw_reset LATEbits.LATE5 // HW_Reset
57 |
58 |
59 | //ISR for CMP3
60 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void){
61 | //Normal Triggered Non-Sliding Mode
62 | if (sampling_mode==0){
63 | if(fft==0){ //AN0 & AN1
64 | get_normal_data();
65 | busy=0;
66 | putHex(98);
67 | IEC1bits.AC3IE =0; //Disable interrupt
68 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
69 | }
70 | else if(fft==1){ //AN0
71 | get_fft1_data();
72 | busy=0;
73 | putHex(98);
74 | IEC1bits.AC3IE =0; //Disable interrupt
75 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
76 | }
77 | else if(fft==2){ // AN1
78 | get_fft2_data();
79 | busy=0;
80 | putHex(98);
81 | IEC1bits.AC3IE =0; //Disable interrupt
82 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
83 | }
84 | }
85 | //Triggered Sliding Mode
86 | else if (sampling_mode==1){ //Sliding Mode
87 | if(fft==0){ //AN0 & AN1
88 | __delay32(sliding_delay_cycles);
89 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
90 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
91 | AN[adc_index]=ADCBUF0>>2;
92 | adc_index++;
93 | AN[adc_index]=ADCBUF1>>2;
94 | adc_index++;
95 |
96 | IEC1bits.AC3IE =0; //Disable interrupt
97 | }
98 | else if(fft==1){ //AN0
99 | __delay32(sliding_delay_cycles);
100 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
101 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
102 | AN[adc_index]=ADCBUF0>>2;
103 | adc_index++;
104 | IEC1bits.AC3IE =0; //Disable interrupt
105 | }
106 | if(fft==2){ // AN1
107 | __delay32(sliding_delay_cycles);
108 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
109 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
110 | AN[adc_index]=ADCBUF1>>2;
111 | adc_index++;
112 | IEC1bits.AC3IE =0; //Disable interrupt
113 | }
114 | }
115 | }
116 |
117 | //----------------------------------------------------------------------
118 | //Main Program
119 | int main( ){
120 | __delay32(3200);//initial delay 100uSec
121 | initUart(); //Initialise the UART
122 | __delay32(3200);//initial delay 100uSec
123 |
124 | hw_reset=0;
125 | TRISA=1; //PortA all inputs
126 | TRISE=0; //PortE all outputs
127 | initialiseADC ();
128 | initialiseComp();
129 | setupOC1PWM();
130 | setupOC2PWM();
131 |
132 | busy=1;
133 |
134 |
135 | //AjScope
136 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);
137 | putHex(101); putHex(13);putHex(10);
138 |
139 | __delay32(3200000); //initial delay 1Sec
140 |
141 | busy=0;
142 |
143 |
144 | while(1){
145 | input_string[0] =getHex();
146 |
147 |
148 | if ( error==0) {
149 |
150 | if (input_string[0]==73){ //"I" Identify
151 | putHex(65);putHex(106);putHex(32);putHex(83);putHex(99);putHex(111);putHex(112);
152 | putHex(101);putHex(32);
153 | putHex(82);putHex(101);putHex(97);putHex(100);putHex(121);putHex(32);
154 | putHex(13);putHex(10);
155 | }
156 | else if (input_string[0]==65){ //"A" Abort
157 | putHex(65);
158 | goto restart;
159 | }
160 | else if (input_string[0]==66){ //"B" Read Busy
161 | putHex(66);
162 | //busy1=busy;
163 | putHex(busy1);
164 | }
165 | else if (input_string[0]==82){ //"R" Read Vref
166 | putHex(82);
167 | readVref();
168 | }
169 | else if (input_string[0]==68){ //"D" Send Data
170 | putHex(68);
171 | input_string[1]=getHex();
172 | if(input_string[1]==1){ //CH1
173 | for(adc_index=0;adc_index<400;adc_index++){ //CH1 Data
174 | putHex(AN[adc_index]);//8 bit AN0 Value
175 | adc_index++;
176 | }
177 | }
178 | else if (input_string[1]==2){//CH2
179 | for(adc_index=0;adc_index<400;adc_index++){ //Ch2 Data
180 | putHex(AN[adc_index+1]);//8 bit AN0 Value
181 | adc_index++;
182 | }
183 | }
184 | else {//FFT
185 | for(adc_index=0;adc_index<400;adc_index++){ //All Data
186 | putHex(AN[adc_index]);//8 bit AN0 Value
187 | }
188 | }
189 | }
190 | else if (input_string[0]==83){ //"S" Sample Rate
191 | putHex(83);
192 | input_string[1]=getHex();
193 | set_sampling(input_string[1]);
194 | }
195 | else if (input_string[0]==78) //"N" Noise Filter
196 | putHex(78);
197 | else if (input_string[0]==67){ //"C" Capture Data
198 | putHex(67);
199 | capture_data();
200 | }
201 | else if (input_string[0]==76){ //"L" Trig Level
202 | putHex(76);
203 | input_string[1]=getHex();
204 | input_string[2]=getHex();
205 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
206 | }
207 | else if (input_string[0]==84){ //"T" Trig Source
208 | putHex(84);
209 | input_string[1]=getHex();
210 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
211 | }
212 | else if (input_string[0]==80){ //"P" Trig Polarity
213 | putHex(80);
214 | input_string[1]=getHex();
215 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
216 | }
217 | else if (input_string[0]==71){ //"G" Gains
218 | putHex(71);
219 | input_string[1]=getHex();
220 | input_string[2]=getHex();
221 | //Gain 1/2/5 Setting 0/1/3
222 | //Pga 1/2 Setting 1/2
223 | setpga(input_string[1], 1); //gain, pga= 1
224 | setpga(input_string[2], 2); //gain, pga= 2
225 | }
226 | else if (input_string[0]==79){ //"O" Offset Ch1
227 | putHex(79);
228 | input_string[1]=getHex();
229 | input_string[2]=getHex();
230 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
231 | }
232 | else if (input_string[0]==111){ //"o" Offset Ch2
233 | putHex(111);
234 | input_string[1]=getHex();
235 | input_string[2]=getHex();
236 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
237 |
238 | }
239 | else if (input_string[0]==70){ //"F" FFT mode
240 | putHex(70);
241 | input_string[1]=getHex();
242 | fft=input_string[1]; // 0/1/2 AN0&1/AN0/AN1
243 | }
244 | else if (input_string[0]==100) //"d" Delay Post Trigger
245 | putHex(100);
246 | else if (input_string[0]==116){ //"t" Test LED
247 | putHex(116);
248 | busy = ~ busy;
249 | }
250 | else { //"E" Error
251 | putHex(69);
252 | goto restart;
253 | }
254 | }
255 |
256 |
257 | //loop
258 | }
259 |
260 |
261 | restart:
262 | return(0);
263 | }
264 | //Read Voltage Reference 10Bit
265 | void readVref(void){
266 | //Reads the value of AN2 and AN3 and returns the 10bit Value
267 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
268 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
269 |
270 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
271 | Nop();Nop();Nop();
272 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
273 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
274 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
275 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
276 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
277 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
278 | }
279 | //Capture data
280 | void capture_data(void){
281 | busy=1;putHex(66);
282 | //Auto Mode "Free Running"
283 | if (capture_mode==0) {
284 | if(fft==0){ //AN0 & AN1
285 | get_normal_data();
286 | busy=0;
287 | putHex(98);
288 | }
289 | else if(fft==1){ //AN1
290 | get_fft1_data();
291 | busy=0;
292 | putHex(98);
293 | }
294 | else if(fft==2){ //AN2
295 | get_fft2_data();
296 | busy=0;
297 | putHex(98);
298 | }
299 | }
300 | //CH1 Triggered Normal Non-Sliding Mode
301 | else if (capture_mode==1){ // Trigger by Channel 1 Comp3A
302 | // Trig Polarity set by "P"
303 | // Trig Level set by "L"
304 | CMPCON3bits.INSEL=0; // 3A selected
305 | CMPCON3bits.CMPON=1; //Comparator ON
306 |
307 | if (sampling_mode==0){ //Normal Non-Sliding Mode
308 | //ISR Collects the Data based on fft=0/1/2 modes
309 | IFS1bits.AC3IF =0; //clear interrupt flag=0
310 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
311 | }
312 | //CH1 Triggered Sliding Mode
313 | else if (sampling_mode==1){ //Sliding Mode
314 |
315 | adc_index=0;
316 | while (adc_index <400){
317 | if(fft==0)
318 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 );
319 | else
320 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 );
321 |
322 | IFS1bits.AC3IF =0; //clear interrupt flag=0
323 | //ISR Collects the Data based on fft=0/1/2 modes
324 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
325 | }
326 | busy=0;
327 | putHex(98);
328 | }
329 | }
330 | //CH2 Normal Mode
331 | else if (capture_mode==2){ // Trigger by Channel 2 Comp3B
332 | // Trig Polarity set by "P"
333 | // Trig Level set by "L"
334 | CMPCON3bits.INSEL=1; // 3B selected
335 | CMPCON3bits.CMPON=1; //Comparator ON
336 |
337 | if (sampling_mode==0){ //Normal Mode
338 | //ISR Collects the Data based on fft=0/1/2 modes
339 | IFS1bits.AC3IF =0; //clear interrupt flag=0
340 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
341 | }
342 | //CH2 Triggered Sliding Mode
343 | else if (sampling_mode==1){ //Sliding Mode
344 |
345 | adc_index=0;
346 | while (adc_index <400){
347 | if(fft==0)
348 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 );
349 | else
350 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 ) ;
351 |
352 | IFS1bits.AC3IF =0; //clear interrupt flag=0
353 | //ISR Collects the Data based on fft=0/1/2 modes
354 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
355 | }
356 | busy=0;
357 | putHex(98);
358 | }
359 | }
360 |
361 |
362 | //busy=0;
363 | }
364 | void set_sampling(unsigned char rate){
365 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
366 | if(rate == 1){ // 2 us/sample 500kbps 20us/div
367 | delay_cycles=11;sampling_mode=0;}
368 | else if(rate == 2){ // 5 us/sample 200kbps 50us/div
369 | delay_cycles=11+96;sampling_mode=0;}
370 | else if(rate == 3){ // 10 us/sample 100kbps 0.1ms/div
371 | delay_cycles=11+256;sampling_mode=0; }
372 | else if(rate == 4){ // 20 us/sample 50kbps 0.2ms/div
373 | delay_cycles=11+576;sampling_mode=0;}
374 | else if(rate == 5){ // 50 us/sample 20kbps 0.5ms/div
375 | delay_cycles=11+1536;sampling_mode=0;}
376 | else if(rate == 6){ // 100 us/sample 10kbps 1ms/div
377 | delay_cycles=11+3136;sampling_mode=0;}
378 | else if(rate == 7){ // 200 us/sample 5kbps 2ms/div
379 | delay_cycles=11+6336;sampling_mode=0;}
380 | else if(rate == 8){ // 500 us/sample 2kbps 5ms/div
381 | delay_cycles=11+15936;sampling_mode=0;}
382 | else if(rate == 9){ // 1000 us/sample 1kbps 10ms/div
383 | delay_cycles=11+31936;sampling_mode=0;}
384 | else if(rate == 10){ // 2000 us/sample 500bps 20ms/div
385 | delay_cycles=11+63936;sampling_mode=0;}
386 | else if(rate == 11){ // 5000 us/sample 200ps 50ms/div
387 | delay_cycles=11+159936;sampling_mode=0;}
388 | else if(rate == 12){ // 10000 us/sample 100bps 0.1s/div
389 | delay_cycles=11+319936;sampling_mode=0;}
390 | else if(rate == 13){ // 20000 us/sample 50bps 0.2s/div
391 | delay_cycles=11+639936;sampling_mode=0;}
392 | else if(rate == 14){ // 50000 us/sample 20bps 0.5s/div
393 | delay_cycles=11+1599936;sampling_mode=0;}
394 | else if(rate == 15){ // 100000 us/sample 10bps 1.0s/div
395 | delay_cycles=11+3199936;sampling_mode=0;}
396 | //----------------------------------Sliding Mode
397 | else if(rate == 16){ // 1us shift/sample 1msps 10us/div
398 | sliding_delay=320;sampling_mode=1;}
399 | else if(rate == 17){ // 0.5us shift/sample 2msps 5us/div
400 | sliding_delay=160;sampling_mode=1;}
401 | else if(rate == 18){ // 0.2us shift/sample 5msps 2us/div
402 | sliding_delay=64;sampling_mode=1;}
403 | else if(rate == 19){ // 0.1us shift/sample 10msps 1us/div
404 | sliding_delay=32;sampling_mode=1;}
405 | else if(rate == 20){ // 0.05us shift/sample 20msps 0.5us/div
406 | sliding_delay=16;sampling_mode=1;}
407 |
408 |
409 | //for sliding_delay = 320 1.0usec increments every 32 = 1Mbps
410 | // = 160 0.5usec increment every 16 = 2Mbps
411 | // = 64 0.2usec increment every 6.4 = 5Mbps
412 | // = 32 0.1usec increment every 3.2 = 10Mbps
413 | // = 16 0.05usec increment every 1.6 = 20Mbps
414 | }
415 | void get_normal_data(void){
416 | int temp=0;
417 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
418 | while(temp<400){
419 |
420 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
421 | AN[temp]=ADCBUF0>>2;
422 | temp++;
423 | AN[temp]=ADCBUF1>>2;
424 | temp++;
425 | __delay32(delay_cycles);
426 |
427 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
428 |
429 | }
430 |
431 |
432 | }
433 | void get_fft1_data(void){
434 | int temp=0;
435 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and store 400 samples
436 | while(temp<400){
437 |
438 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
439 | AN[temp]=ADCBUF0>>2;
440 | temp++;
441 | __delay32(delay_cycles+6);
442 |
443 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
444 | // sets PEND0 to 1
445 | }
446 | }
447 | void get_fft2_data(void){
448 | int temp=0;
449 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN1 store 400 samples
450 | while(temp<400){
451 |
452 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
453 | AN[temp]=ADCBUF1>>2;
454 | temp++;
455 | __delay32(delay_cycles+6);
456 |
457 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
458 | // sets PEND0 to 1
459 | }
460 | }
461 |
--------------------------------------------------------------------------------
/MPLAB C30_Code/015_Scope2/Scope2_final_115.c:
--------------------------------------------------------------------------------
1 | // AjScope2 with 3byteCommands with "Reset"
2 | // 02 Aug 2013: Basic Command Decode Matrix
3 | // Read VRef AN2 AN3 and return result as 4 bytes
4 | // Set Offset OC1 & OC2 PWM
5 | // 03 Aug 2013: Added the Auto Mode Capture with Sample rate Settings
6 | // Added the LED Test Mode
7 | // Added the Interrupt Mode for Normal sampling
8 | // Added the Interrupt Mode for Sliding CH1
9 | // Added the FFT mode with seperate functions resolving __delay32() problem
10 | // 04 Aug 2013: Changed to Tx in interrupt mode
11 | // 06 Aug 2013: Single Byte Command Identifier and Variable Length Commands
12 | // Abort Single Byte Restarts Main Program
13 | // Sends Busy "B" and Clears Busy "b"
14 | // 08 Aug 2013 Removed the ACK for Capture , Data &Busy
15 | // 09 Aug 2013 Removed the initial valies from char capture_mode,sampling_mode, error,fft;
16 | // Added back the busy complete "Done"
17 | // Added 100usec delay between sent data
18 | // 1o Aug 2013 Increased delay for 400 data to 200usec
19 | // ------------------------------------------------------------
20 | // Problems:
21 | // Cannot read BUSY but a Busy indication sent on 232
22 | //
23 | //
24 | //
25 | //-------------------------------------------------------------
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 |
33 | //Fuzes 16 MHz crystal
34 | _FOSC(CSW_FSCM_OFF & OSC2_IO & HS);//No Clock Switching,OSC2 is an output, HS Crystal
35 | _FOSCSEL(PRIOSC_PLL); // Primary Osc With PLL FPWM= Primary Osc X 32 ,
36 | //FOSC = Primary Osc X 4 FADC = Primary Osc X 16 ;
37 | //FCY = Primary Osc X 2
38 | _FWDT(FWDTEN_OFF); //Turn off WatchDog Timer
39 | _FGS(CODE_PROT_OFF); //Turn off code protect
40 | _FPOR( PWRT_OFF ); //Turn off power up timer
41 |
42 |
43 |
44 |
45 | //Function Prototypes
46 | void readVref(void);
47 | void capture_data(void);
48 | void set_sampling(unsigned char rate);
49 | void get_normal_data(void);
50 | void get_fft1_data(void);
51 | void get_fft2_data(void);
52 |
53 | unsigned char input_string[3],AN[405],data;
54 | unsigned char capture_mode,sampling_mode, error,fft;
55 | int data_index;
56 | unsigned long delay_cycles=10,sliding_delay;
57 | unsigned long sliding_delay_cycles, adc_index;
58 |
59 |
60 | #define busy LATEbits.LATE4 // Busy
61 | #define hw_reset LATEbits.LATE5 // HW_Reset
62 |
63 |
64 | //ISR for CMP3
65 | void __attribute__((__interrupt__, __auto_psv__)) _CMP3Interrupt(void){
66 | //Normal Triggered Non-Sliding Mode
67 | if (sampling_mode==0){
68 | if(fft==0){ //AN0 & AN1
69 | get_normal_data();
70 | busy=0;
71 | putHex(68);putHex(111);putHex(110);putHex(101);
72 | IEC1bits.AC3IE =0; //Disable interrupt
73 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
74 | }
75 | else if(fft==1){ //AN0
76 | get_fft1_data();
77 | busy=0;
78 | putHex(68);putHex(111);putHex(110);putHex(101);
79 | IEC1bits.AC3IE =0; //Disable interrupt
80 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
81 | }
82 | else if(fft==2){ // AN1
83 | get_fft2_data();
84 | busy=0;
85 | putHex(68);putHex(111);putHex(110);putHex(101);
86 | IEC1bits.AC3IE =0; //Disable interrupt
87 | //IFS1bits.AC3IF =0; //clear interrupt flag=0
88 | }
89 | }
90 | //Triggered Sliding Mode
91 | else if (sampling_mode==1){ //Sliding Mode
92 | if(fft==0){ //AN0 & AN1
93 | __delay32(sliding_delay_cycles);
94 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
95 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
96 | AN[adc_index]=ADCBUF0>>2;
97 | adc_index++;
98 | AN[adc_index]=ADCBUF1>>2;
99 | adc_index++;
100 |
101 | IEC1bits.AC3IE =0; //Disable interrupt
102 | }
103 | else if(fft==1){ //AN0
104 | __delay32(sliding_delay_cycles);
105 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
106 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
107 | AN[adc_index]=ADCBUF0>>2;
108 | adc_index++;
109 | IEC1bits.AC3IE =0; //Disable interrupt
110 | }
111 | if(fft==2){ // AN1
112 | __delay32(sliding_delay_cycles);
113 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
114 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
115 | AN[adc_index]=ADCBUF1>>2;
116 | adc_index++;
117 | IEC1bits.AC3IE =0; //Disable interrupt
118 | }
119 | }
120 | }
121 |
122 | //----------------------------------------------------------------------
123 | //Main Program
124 | int main( ){
125 | __delay32(3200);//initial delay 100uSec
126 | initUart(); //Initialise the UART
127 | __delay32(3200);//initial delay 100uSec
128 |
129 | hw_reset=0;
130 | TRISA=1; //PortA all inputs
131 | TRISE=0; //PortE all outputs
132 | initialiseADC ();
133 | initialiseComp();
134 | setupOC1PWM();
135 | setupOC2PWM();
136 |
137 | busy=1;
138 |
139 |
140 | //AjScope
141 | putHex(65);putHex(106);putHex(83);putHex(99);putHex(111);putHex(112);
142 | putHex(101); putHex(13);putHex(10);
143 |
144 | __delay32(3200000); //initial delay 1Sec
145 |
146 | busy=0;
147 |
148 |
149 | while(1){
150 | input_string[0] =getHex();
151 |
152 |
153 | if ( error==0) {
154 |
155 | if (input_string[0]==73){ //"I" Identify
156 | putHex(65);putHex(106);putHex(32);putHex(83);putHex(99);putHex(111);putHex(112);
157 | putHex(101);putHex(32);
158 | putHex(82);putHex(101);putHex(97);putHex(100);putHex(121);putHex(32);
159 | putHex(13);putHex(10);
160 | }
161 | else if (input_string[0]==65){ //"A" Abort
162 | putHex(65);
163 | goto restart;
164 | }
165 | else if (input_string[0]==66){ //"B" Read Busy
166 | putHex(66);
167 | }
168 | else if (input_string[0]==82){ //"R" Read Vref
169 | putHex(82);
170 | readVref();
171 | }
172 | else if (input_string[0]==68){ //"D" Send Data
173 | //------putHex(68);
174 | input_string[1]=getHex();
175 | if(input_string[1]==1){ //CH1 200
176 | for(adc_index=0;adc_index<400;adc_index++){ //CH1 Data
177 | putHex(AN[adc_index]);//8 bit AN0 Value
178 | adc_index++;
179 | __delay32(3200); //200us delay
180 | }
181 | }
182 | else if (input_string[1]==2){//CH2 200
183 | for(adc_index=0;adc_index<400;adc_index++){ //Ch2 Data
184 | putHex(AN[adc_index+1]);//8 bit AN0 Value
185 | adc_index++;
186 | __delay32(3200); //200us delay
187 | }
188 | }
189 | else if (input_string[1]==3){//400 samples CH1/CH2/FFT
190 | for(adc_index=0;adc_index<400;adc_index++){ //All Data
191 | putHex(AN[adc_index]);//8 bit AN0 Value
192 | __delay32(3200); //100us delay
193 | }
194 | }
195 | }
196 | else if (input_string[0]==83){ //"S" Sample Rate
197 | putHex(83);
198 | input_string[1]=getHex();
199 | set_sampling(input_string[1]);
200 | }
201 | else if (input_string[0]==78) //"N" Noise Filter
202 | putHex(78);
203 | else if (input_string[0]==67){ //"C" Capture Data
204 | //----------putHex(67);
205 | capture_data();
206 | }
207 | else if (input_string[0]==76){ //"L" Trig Level
208 | putHex(76);
209 | input_string[1]=getHex();
210 | input_string[2]=getHex();
211 | CMPDAC3bits.CMREF=input_string[1]*256 + input_string[2];//Comp3ref
212 | }
213 | else if (input_string[0]==84){ //"T" Trig Source
214 | putHex(84);
215 | input_string[1]=getHex();
216 | capture_mode=input_string[1]; // 0/1/2 auto/Ch1/Ch2
217 | }
218 | else if (input_string[0]==80){ //"P" Trig Polarity
219 | putHex(80);
220 | input_string[1]=getHex();
221 | CMPCON3bits.CMPPOL=input_string[1]; // 0/1 =Normal /Inverted polarity
222 | }
223 | else if (input_string[0]==71){ //"G" Gains
224 | putHex(71);
225 | input_string[1]=getHex();
226 | input_string[2]=getHex();
227 | //Gain 1/2/5 Setting 0/1/3
228 | //Pga 1/2 Setting 1/2
229 | setpga(input_string[1], 1); //gain, pga= 1
230 | setpga(input_string[2], 2); //gain, pga= 2
231 | }
232 | else if (input_string[0]==79){ //"O" Offset Ch1
233 | putHex(79);
234 | input_string[1]=getHex();
235 | input_string[2]=getHex();
236 | OC1RS=input_string[1]*256 + input_string[2];//Set PWM1
237 | }
238 | else if (input_string[0]==111){ //"o" Offset Ch2
239 | putHex(111);
240 | input_string[1]=getHex();
241 | input_string[2]=getHex();
242 | OC2RS=input_string[1]*256 + input_string[2];//Set PWM2
243 |
244 | }
245 | else if (input_string[0]==70){ //"F" FFT mode
246 | putHex(70);
247 | input_string[1]=getHex();
248 | fft=input_string[1]; // 0/1/2 AN0&1/AN0/AN1
249 | }
250 | else if (input_string[0]==100) //"d" Delay Post Trigger
251 | putHex(100);
252 | else if (input_string[0]==116){ //"t" Test LED
253 | putHex(116);
254 | busy = ~ busy;
255 | }
256 | else { //"E" Error
257 | putHex(69);
258 | goto restart;
259 | }
260 | }
261 |
262 |
263 | //loop
264 | }
265 |
266 |
267 | restart:
268 | return(0);
269 | }
270 | //Read Voltage Reference 10Bit
271 | void readVref(void){
272 | //Reads the value of AN2 and AN3 and returns the 10bit Value
273 | // AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
274 | unsigned char AN2msb,AN2lsb,AN3msb,AN3lsb;
275 |
276 | ADCPC0bits.SWTRG1 = 1; //start conversion of AN3 and AN2
277 | Nop();Nop();Nop();
278 | while(ADCPC0bits.PEND1){} //conv pending becomes 0 when conv complete
279 | AN2lsb = ADCBUF2 &0x00ff; // lsb of the ADC result
280 | AN2msb=(ADCBUF2 &0xff00)>>8; // msb of the ADC result
281 | AN3lsb = ADCBUF3 &0x00ff; // lsb of the ADC result
282 | AN3msb=(ADCBUF3 &0xff00)>>8; // msb of the ADC result
283 | putHex(AN2msb);putHex(AN2lsb);putHex(AN3msb);putHex(AN3lsb);
284 | }
285 | //Capture data
286 | void capture_data(void){
287 | busy=1;//---------putHex(66);
288 | //Auto Mode "Free Running"
289 | if (capture_mode==0) {
290 | if(fft==0){ //AN0 & AN1
291 | get_normal_data();
292 | busy=0;
293 | putHex(68);putHex(111);putHex(110);putHex(101);// Done for busy over
294 | }
295 | else if(fft==1){ //AN1
296 | get_fft1_data();
297 | busy=0;
298 | putHex(68);putHex(111);putHex(110);putHex(101);
299 | }
300 | else if(fft==2){ //AN2
301 | get_fft2_data();
302 | busy=0;
303 | putHex(68);putHex(111);putHex(110);putHex(101);
304 | }
305 | }
306 | //CH1 Triggered Normal Non-Sliding Mode
307 | else if (capture_mode==1){ // Trigger by Channel 1 Comp3A
308 | // Trig Polarity set by "P"
309 | // Trig Level set by "L"
310 | CMPCON3bits.INSEL=0; // 3A selected
311 | CMPCON3bits.CMPON=1; //Comparator ON
312 |
313 | if (sampling_mode==0){ //Normal Non-Sliding Mode
314 | //ISR Collects the Data based on fft=0/1/2 modes
315 | IFS1bits.AC3IF =0; //clear interrupt flag=0
316 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
317 | }
318 | //CH1 Triggered Sliding Mode
319 | else if (sampling_mode==1){ //Sliding Mode
320 |
321 | adc_index=0;
322 | while (adc_index <400){
323 | if(fft==0)
324 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 );
325 | else
326 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 );
327 |
328 | IFS1bits.AC3IF =0; //clear interrupt flag=0
329 | //ISR Collects the Data based on fft=0/1/2 modes
330 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
331 | }
332 | busy=0;
333 | putHex(68);putHex(111);putHex(110);putHex(101);
334 | }
335 | }
336 | //CH2 Normal Mode
337 | else if (capture_mode==2){ // Trigger by Channel 2 Comp3B
338 | // Trig Polarity set by "P"
339 | // Trig Level set by "L"
340 | CMPCON3bits.INSEL=1; // 3B selected
341 | CMPCON3bits.CMPON=1; //Comparator ON
342 |
343 | if (sampling_mode==0){ //Normal Mode
344 | //ISR Collects the Data based on fft=0/1/2 modes
345 | IFS1bits.AC3IF =0; //clear interrupt flag=0
346 | IEC1bits.AC3IE =1; //Enable CMP3 interrupt
347 | }
348 | //CH2 Triggered Sliding Mode
349 | else if (sampling_mode==1){ //Sliding Mode
350 |
351 | adc_index=0;
352 | while (adc_index <400){
353 | if(fft==0)
354 | sliding_delay_cycles =(sliding_delay * (adc_index >>1)/10 );
355 | else
356 | sliding_delay_cycles =(sliding_delay * (adc_index )/10 ) ;
357 |
358 | IFS1bits.AC3IF =0; //clear interrupt flag=0
359 | //ISR Collects the Data based on fft=0/1/2 modes
360 | IEC1bits.AC3IE =1; //Enable CMP3A interrupt
361 | }
362 | busy=0;
363 | putHex(68);putHex(111);putHex(110);putHex(101);
364 | }
365 | }
366 |
367 |
368 | //busy=0;
369 | }
370 | void set_sampling(unsigned char rate){
371 | // 11 for rounding off to 2usec +64*N for additional 2*N usec
372 | if(rate == 1){ // 2 us/sample 500kbps 20us/div
373 | delay_cycles=11;sampling_mode=0;}
374 | else if(rate == 2){ // 5 us/sample 200kbps 50us/div
375 | delay_cycles=11+96;sampling_mode=0;}
376 | else if(rate == 3){ // 10 us/sample 100kbps 0.1ms/div
377 | delay_cycles=11+256;sampling_mode=0; }
378 | else if(rate == 4){ // 20 us/sample 50kbps 0.2ms/div
379 | delay_cycles=11+576;sampling_mode=0;}
380 | else if(rate == 5){ // 50 us/sample 20kbps 0.5ms/div
381 | delay_cycles=11+1536;sampling_mode=0;}
382 | else if(rate == 6){ // 100 us/sample 10kbps 1ms/div
383 | delay_cycles=11+3136;sampling_mode=0;}
384 | else if(rate == 7){ // 200 us/sample 5kbps 2ms/div
385 | delay_cycles=11+6336;sampling_mode=0;}
386 | else if(rate == 8){ // 500 us/sample 2kbps 5ms/div
387 | delay_cycles=11+15936;sampling_mode=0;}
388 | else if(rate == 9){ // 1000 us/sample 1kbps 10ms/div
389 | delay_cycles=11+31936;sampling_mode=0;}
390 | else if(rate == 10){ // 2000 us/sample 500bps 20ms/div
391 | delay_cycles=11+63936;sampling_mode=0;}
392 | else if(rate == 11){ // 5000 us/sample 200ps 50ms/div
393 | delay_cycles=11+159936;sampling_mode=0;}
394 | else if(rate == 12){ // 10000 us/sample 100bps 0.1s/div
395 | delay_cycles=11+319936;sampling_mode=0;}
396 | else if(rate == 13){ // 20000 us/sample 50bps 0.2s/div
397 | delay_cycles=11+639936;sampling_mode=0;}
398 | else if(rate == 14){ // 50000 us/sample 20bps 0.5s/div
399 | delay_cycles=11+1599936;sampling_mode=0;}
400 | else if(rate == 15){ // 100000 us/sample 10bps 1.0s/div
401 | delay_cycles=11+3199936;sampling_mode=0;}
402 | //----------------------------------Sliding Mode
403 | else if(rate == 16){ // 1us shift/sample 1msps 10us/div
404 | sliding_delay=320;sampling_mode=1;}
405 | else if(rate == 17){ // 0.5us shift/sample 2msps 5us/div
406 | sliding_delay=160;sampling_mode=1;}
407 | else if(rate == 18){ // 0.2us shift/sample 5msps 2us/div
408 | sliding_delay=64;sampling_mode=1;}
409 | else if(rate == 19){ // 0.1us shift/sample 10msps 1us/div
410 | sliding_delay=32;sampling_mode=1;}
411 | else if(rate == 20){ // 0.05us shift/sample 20msps 0.5us/div
412 | sliding_delay=16;sampling_mode=1;}
413 |
414 |
415 | //for sliding_delay = 320 1.0usec increments every 32 = 1Mbps
416 | // = 160 0.5usec increment every 16 = 2Mbps
417 | // = 64 0.2usec increment every 6.4 = 5Mbps
418 | // = 32 0.1usec increment every 3.2 = 10Mbps
419 | // = 16 0.05usec increment every 1.6 = 20Mbps
420 | }
421 | void get_normal_data(void){
422 | int temp=0;
423 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1 store 200 samples each
424 | while(temp<400){
425 |
426 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
427 | AN[temp]=ADCBUF0>>2;
428 | temp++;
429 | AN[temp]=ADCBUF1>>2;
430 | temp++;
431 | __delay32(delay_cycles);
432 |
433 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN3 and AN2
434 |
435 | }
436 |
437 |
438 | }
439 | void get_fft1_data(void){
440 | int temp=0;
441 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and store 400 samples
442 | while(temp<400){
443 |
444 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
445 | AN[temp]=ADCBUF0>>2;
446 | temp++;
447 | __delay32(delay_cycles+6);
448 |
449 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
450 | // sets PEND0 to 1
451 | }
452 | }
453 | void get_fft2_data(void){
454 | int temp=0;
455 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN1 store 400 samples
456 | while(temp<400){
457 |
458 | while(ADCPC0bits.PEND0){} //conv pending becomes 0 when conv complete
459 | AN[temp]=ADCBUF1>>2;
460 | temp++;
461 | __delay32(delay_cycles+6);
462 |
463 | ADCPC0bits.SWTRG0 = 1; //start conversion of AN0 and AN1
464 | // sets PEND0 to 1
465 | }
466 | }
467 |
--------------------------------------------------------------------------------