Home

low_cost_pc-based_quad_channel_r

image

Contents

1. K 0 H 0 1 AA v v Sample CH1 and Sample CH2 and transmit reading using real time frame structure transmit reading using real time frame structure Sample CH3 and transmit reading using real time frame structure vy Sample CH4 and transmit reading using real time frame structure EEE516J4 Honours Project Page 112 Chapter 10 PIC Software Development Friday 21 June 2002 mas DEC TimeBase Note the Mark11 c program is not complete and the flowcharts above are draft flowcharts EEE516J4 Honours Project Final Report TimeBase Y TimeBasemUX bSample TRUE Transmit array to PC using storage mode frame structure array J CH1 ADC reading gt sampling capacitor 20us delay for to charge array J CH2 ADC reading gt sampling capacitor 20us delay for to charge array J CH3 ADC reading gt sampling capacito 20us delay for to charge array J CH4 ADC reading gt sampling capacitor 20us delay for to charge bSample FALSE Page 113 Colin K McCord Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord 11 0 TEST RESULTS
2. About Scope x xi Low cost PC based real time Communication storage oscilloscope Basic Version 1 0410 COMM Z BeudRete 115200 x By Colin K McCord Date 19 April 2002 Advenced Universitry of Ulster Jordanstown Byte Size 8 x Parity No Parity x Course BEng hons Electronic Systems Module H Project EEES16J fr lodule Honours Project E 6J4 sopis fi metoh First Supervisor Dr S Katzen Second Supemisor Dr C Tuner Restore Defaults O O Cancel f Figure 7 01 Screen dump of about dialog Figure 7 0m Screen dump of about configuration Cre Disp Tog The scope program is capable of generating software waveforms see figure 7 0n this was used to test the graphical display and triggering methods before the simulation program and PIC hardware was ready for testing Note this menu will be removed in the final released version E Sid Configuration Sidebar Col 8 Time 20mS DfV R Copy Crt c Base b Ende Commurscatoors Col e Qeable Communkations criso ST fiviov C emo fy CHI Sne Wave Fl Bort CuleP AY CH1 Random Wave F2 A Print Preview Coley Ay CH2 Sine Wave F3 Punt Setup WW CH2 Random Wave E Ext Another view exists figure 7 00 but has not been implement It was expected that the user would enter a file name and press Rec to stream real time data to disk and press Play to play back recorded real time data
3. x A CH3 Sine Wave AY CHS Random Wave CH4 Sine Wave CHa Random Wave Figure 7 0n Screen dump of debug menu When in pause mode the scroll bar labelled position would have been used to manually scroll F Advanced Sampling Control Panel Raf r through the record data Possioa 4 pj 2 tee The tick boxes for channels 1 to 4 were to be used Stopped for telling the PIC which channel to sample The AS reason why the enable disable channels in F Channel Disp tab could not be used for this task is Number of readings to take per SMR 1000 channel in storage mode because multiple scope windows can be opened FM Channel 2 Alternate F Chennel 3 Chop before tr itt r sy lore transmitting with different channels enable disable hence a global set of enable disable channels is required Figure 7 00 Screen dump of ASCP to specify which channels to sample EEE516J4 Honours Project Page 48 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord 7 1 Data Flow Diagram Program CMainFrame Main Window AA Y CChildFrame 5 i Scope Window y CConfigurationDig i t CControlsView L CConfigPage1 Control Sideb
4. lol x Fe Edt View Toos Window Hep Pego Ugit Esae Sample Disp Trg Time Base iV CHI iv DIV X lV cHe 1Vv 0IV Y M CH3 fiv ON v a VDV oy Ready Figure 11 3 2d Screen dump of scope program sample rate 1 kHz CH4 25Hz sinewave CH1 5V CH2 5V CH3 5V EEE516J4 Honours Project Page 134 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 11 3 2 1 Dual Channel Operation Using Two Signal Generators Fluke PM5139 function generator calibrated connected to channel 1 red Thandar TG 101 function generator not calibrated connected to channel 2 green Sample rate is 1000Hz scope time base is 0 01 Channel 1 connected to 10Hz sine wave 5Vpp channel 2 connected to 30Hz sine wave 4Vpp see figure 11 3 2 1a Channel 1 10 divisions per cycle hence the calculated frequency is 1 10 0 01 10Hz Channel 2 4 2 divisions per cycle hence the calculated frequency is 1 4 2 0 01 23 8 Hz note channel 2 signal generator is not calibrated this is the true frequency Fie Edit View Tools Window Help MiG FIO mt Efa Sample Disp Trig Time a Base VCH hivjoV M eH ISVvIDV CH3 fi Figure 11 3 2 1a Screen dump of scope program sample rate 1 kHz CH1 10Hz sinewave CH2 30Hz sinewave Scope Scopel lol xi File Edit View Tools Window Help his BEA S sires 2 Sample Disp Trig Ti Base z M CHI fvN V CH
5. void CScopeView PrepareTraces PC eeteesetesosesseesssesl sess se Seca Sete eee eee bese see eSe Fuction void CScopeView PrepareTraces Description Creates trace memory DCs and bitmaps Return Void Date 15 03 2002 Verison At salt By Colin McCord Se Sr ee a ee a ee ee eee eee CClientDC dc this Screen DC Channel 1 CBitmap m_bitmapOldCH1 NULL Pointer to old display bitmap m bitmapCH1 new CBitmap Create a new bitmap Create new bitmap and delete old Channel 1 if m_dcCH1 GetSafeHdc NULL m_dcCH1 CreateCompatibleDC amp dc m_bitmapCH1 gt CreateCompatibleBitmap amp dc m_ nClientWidth m nClientHeight m_bitmapOldCH1 m_dcCH1 SelectObject m_bitmapCH1 m_bitmapOldCH1 gt DeleteObject Make Sure there is not a memory leak Channels 2 4 prepared in exactly the same way as channel 1 This function draws Channel 1 void CScopeView OnDrawCH1 Re a a EEE a Se a en ee Fuction void CScopeView OnDrawCH1 Description Draws CH1 waveform in memory then updates display Return Void Date 04 04 2002 Verison 1 9 By Colin McCord CClientDC dc this int i n yl y2 a 1 m_Skip m MUX CBrush Brush Brush CreateSolidBrush BLACK Set brush colour to black CRect CRectTEMP Channel 1 Member DC not setup yet if m_dcCH1 GetSafeHdc NULL PrepareTraces If channel 1 pen is not crea
6. WriteDIB Writes a DIB to file Returns TRUE on success szFile Name of file to write to DIB Handle of the DIB BITMAPFILEHEADER hdr LPBITMAPINFOHEADER lpbi if hDIB return FALSE CFile file if file Open szFile CFile modeWrite CFile modeCreate return FALSE lpbi LPBITMAPINFOHEADER hDIB int nColors 1 lt lt lpbi gt biBitCount Fill in the fields of the file header hdr bfType WORD M lt lt 8 B is always BM hdr bfSize GlobalSize hDIB sizeof hdr EEE516J4 Honours Project Page 76 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord hdr bfReservedl 0 hdr bfReserved2 0 hdr bfOffBits DWORD sizeof hdr lpbi gt biSize nColors sizeof RGBQUAD Write the file header file Write amp hdr sizeof hdr Write the DIB header and the bits file Write lpbi GlobalSize hDIB return TRUE 7 11 Owner Drawn Menus with Bitmaps The scope program uses owner drawn menus with bitmaps To save time a freeware class BCMenu h written by Brent Corkum was used download from W4 This class can mimic the new MS Office XP style of menus Used in scope program or the old MS Office 97 style of menus Figures 7 11a shows a screen dump of Microsoft Word XP with its file menu open while figure 7 11b shows the file menu of the Scope program Notice that the menu style of the Scope program is si
7. else m_wndSplitter SetColumniInfo 0 rect Width 0 m_wndSplitter SetColumniInfo 1 0 0 m_wndSplitter RecalcLayout This function hides and shows the side panel void CChildFrame HideShowPanel CRect rect GetWindowRect amp rect if m_bSplitterCreated if m_bShowPanel true Hide side panel m_wndSplitter SetColumninfo 0 rect Width 0 m_wndSplitter SetColumniInfo 1 0 0 m_bShowPanel false else Show Side Panel if rect Width gt 200 m_wndSplitter SetColumniInfo 0 rect Width 250 0 m_wndSplitter SetColumniInfo 0 0 0 m_wndSplitter SetColumniInfo 1 250 0 m_bShowPanel true m_wndSplitter RecalcLayout EEE516J4 Honours Project Page 64 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord 7 8 Saving Opening Scope Data The scope program has the capability of saving and opening waveform data along with the current settings e g selected time base sample rate enabled channels scope resolution etc This is one of the key advantages that the PC based scope has over traditional analogue scopes Traditionally users of analogue scopes had to draw on graph paper the scope waveforms if a permanent record was required This saving of scope data feature is far more useful than taking a screen dump of the screen or copying the scope waveform to the windows clipboard Obviously taking a scr
8. 11 3 2 2 Quad Channel Operation Fie Edt Pe Toos Window i Me salu Bans H mmg a ven vov z seny HAH ES ine Bolten oe WDY A el Eile Edt Yew Tools Window nee Sample Disp Trig Time x Base Men fvov Mene fiviov gt Moen fhvov x Figure 11 3 2 2b Screen dump of scope program CH1 CH2 CH3 CH4 sinewave triggering on CH1 EEE516J4 Honours Project Page 140 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord All waveforms in figure 11 3 2 2b were stable note that there should be a 20uS delay see mark9 c between each waveform e g chop mode For example channel 1 should lead channel 2 by 20uS channel 2 should lead channel 3 by 20uUS etc Each square represents 0 01 seconds 10mS hence this small offset is not noticeable at this resolution 11 3 2 3 5 000Hz Sample Rate Single Channel mark9 c modified basically the sample rate has been changed to 5000Hz TimeBaseMUX 10 and sampling of channels 2 to 4 has been removed Note Sample rate 5000Hz 10 horizontal samples per division Hence scope time base is 2 milliseconds per division Time base is fixed on this version of the scope program 50Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3a 10 divisions per cycle hence the calculated frequency is 1 10 0 002 50Hz F Scope Scopel loj x Fle Edt Vew Toos Window Hep PICO Aiea EEEa Sample Disp Trig
9. 205Hz Scope Scopel 0 x B Fie Edt Vew Toos Window Hep x O f aS BEFA Sample Disp Trig Time I Base Figure 11 2 3 1f Screen dump of scope program sample rate 2 000Hz input wave 200Hz sinewave 0 5V EEE516J4 Honours Project Page 127 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 500Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 1g resolution 100 x 80 that s 10 x 8 divisions clearly under sampled Scope Scope1 E la x E Fie Edt View Toos Window Help x Mls Balm ia 2 G g a Sample Disp Trig Time o a Base mem fivov roe M a Fo mav a inn CE HL A EAA A A Figure 11 2 3 1g Screen dump of scope program sample rate 2 000HZz input wave 500Hz sinewave 0 5V 1 000Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 1h resolution 100 x 80 that s 10 x 8 divisions something real strange has happened here clearly the result of under sampling e Scope Scope1 E la x 2 He Edt View Toos Window Help 15 xj Ai j PEFR Sample Disp Trig Time Base vV CHI ft vov M CH2 pee iE VN fl MTT UIT Figure 11 2 3 1h Screen dump of scope program sample rate 2 000HZz input wave 1 00Hz sinewave 0 5V 20Hz trianglewave 0 5V connected to CH1 ANO see figure 11 2 3 1i resolution 200 x 160 that s 20 x 16 divisions 9 9 division
10. iY oo Dak t g Somple Disp Trig Sample Disp Trig Trigger CH1 X Trigger CH1 Dd 16 NEG FC POS FC NEG POS Otset Level Offset Level C Level Edge C Level Edge Ready NM Ready NUM Figure 7 0g Six screen dumps of scope exe demonstrating different trigger settings The user can select which channel to trigger off CH1 CH2 CH3 or CH4 Notice that there is another option called IND this means independent triggering where each channel has its one unique trigger point It is not sure how useful this feature is as generally for dual and quad trace operation waveforms are normally related is some way and timing analysis is normally required It was decided to include this function for increased program flexibility as this allows for four unrelated waveforms to be monitored simultaneously on the same scope display Besides it normal practice for EEE516J4 Honours Project Page 45 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord commercial products to have useless features Bells and Whistles which will probably never be used in practice but helps give their product an edge over the competition The Disp tab of the controls dialog can enable disable channels simply by clicking the tick box beside each channel change scope time base and channel voltage scales see figure 7 0h Notice in figure 7 0h there are two enabled channels both of which have zero offset hence the
11. 11 1 Test Session 1 FG Wilson Lab 26 02 2002 The circuit diagram shown in figure 11 1a was constructed on prototype board with RS232 communication connected to laptop COM1 1GHz AMD processor 256MHz SDRAM 8MB 3D accelerator card running windows XP VCC 40 bg a 1 KTI 2 39 E CH1 m c5 c3 2 3 1uF 1uF 4 37 16 5 36 J A 1 C1 vec V 2 niu 5V to 10V 6 35 3 Voltage Fa Cae Beutler 7 34 8 33 _ ca 4 t nas ys tur 7 9 32 Is 5 ca 1uF 10 31 lo 1 O 9 14 30 4 14 6 sh a 29 2 O 13 28 10 7 7 O 14 27 3 Q O 15 26 2 13 8 O a 16 25 4 O N 17 24 9 8 9 O 4 10 20MHz 18 23 5 amp 19 22 i c6 C7 20 21 33pF 33pF PIC16F877 20 P 15 Figure 11 1a Test Circuit Diagram 1 11 1 1 Test 1 Test RS232 Communications TX only Program mark1 c version 1 0 was compiled and loaded into PIC using Microchip MPLAB This program is extremely simple basically it transmits Testing continuously with a 1 second delay between each Testing The DOS based test program test exe version 1 05 was used in RX terminal mode to receive the incoming characters Screen dump of text exe after a couple of minutes RX Terminal Waiting for message press a key to stop Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Tes
12. 5 4 1 Simulation of the Circuit using Electronic Workbench From figure 5 4 1b using 2 5 to 2 5V input it is clear that a 2 5 to 2 5V sine wave input has been applied and the output is 0 to 5V Figure 5 4 1c clearly shows an input of 1v to 1v and an output of to 3 5V to 1 5V Notice the input and output waveforms are the same phase and polarity Oscilloscope Oscilloscope TH 884 7259 ns 894 7239 as MH 305 2260 as TR 3 4 8500 ns KAL 9 6250 ns va 2 4733 v 2 4733 Wa 990 5942 av WA 990 4940 ny Vea 1 9711 wi 4 9739 V 27 3459 av w v w 4 C20 U vW 4 9730 V 5 z es Figure 5 4 1b Screen dump of oscilloscope CH A input CH B Figure 5 4 1c Screen dump of oscilloscope CH A Input CH B Output Output 954 9266 ns 964 9266 me 2970 Boh 9220 ns 24 6901 V 24 6901 v 2 ae20 v 434361 nv 4 ooe i gt V wh 2265 av Figure 5 3 1d Screen TTE of TEET cH A Input CH B Figure 5 3 1e Screen TNT of TE CH A Input CH B Output Output EEE516J4 Honours Project Page 27 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord From figure 5 4 1d using 25 to 25V input it is clear that a 25 to 25V sine wave input has been applied and the output is 0 to 5V Figure 5 4 1e clearly shows a sine wave input of 250 to 250v using 250 to 250V input and an output of to OV to 5V Notice the input and output waveforms are the same phase and polarit
13. Table of CRC values for low order byte const char Table CRC_Lo 256 OX00 OXCO OXC1 OX01 OXC3 0X03 OX02 OXC2 OXC6 0X06 0X07 0x04 OXCC OXOC OX0D OXCD OXOF OXCF OXCE OXOE OXOA OXCA OX08 OXC8 OXD8 OX18 0X19 OXD9 OX1B OXDB OXDA OX1A OXIE OX1D OX1C OXDC 0X14 OXD4 OXD5 0X15 OXD7 OX17 OX16 OXD6 OX11 OXD1 OXDO OX10 OXFO 0X30 OX31 OXF1 0X33 OXF3 OXF2 0X37 OXF5 OX35 0X34 OXF4 OX3C OXFC OXFD OX3D OXFF OX3F OX3B OXFB 0X39 OXf9 OXF8 0x38 0X28 OXE8 OXE9 0X29 OXEB OX2E OXEF OXEF OXED OXED OXEC OX2C OXE4 OX24 0X25 OXES5 OX22 OXE2 OXE3 0X23 OXE1 0X21 0X20 OXEO OXAO 0x60 0x61 0x62 OX66 OXA6 0XA7 OX67 OXA5 0X65 0X64 OXA4 OX6C OXAC OX6E OXAE OXAA OX6A OX6B OXAB 0X69 OXA9 OXA8 OX68 OX78 OX7B OX7A OXBA OXBE OX7E OX7F OXBF OX7D OXBD OXBC OX7C OX77 OXB7 OXB6 OX76 0X72 OXB2 OXB3 OX73 OXB1 OX71 OX70 OX51 0X93 0X53 0X52 0X92 0X96 0X56 OX57 OX97 OX55 0X95 OX5D OX9D OX5F OX9F OX9E OX5E OX5A OX9A OX9B OX5B 0X99 0x48 0X49 OX89 OX4B OX8B OX8A OX4A OX4E OX8E OX8F OX4F OX44 0X84 0x85 0x45 0X87 0X47 0X46 OX86 0X82 0X42 0X43 0x40 long int CRC16 char message int length main long int crcANS char test 5 test 0 test 1 test 2 test 3 test 4 ENUA crcANS CRC16 test 5 Sleep long int CRC16 char message int length char CRC Hi
14. The circuit has built in protection diodes to make sure the ADC does not get damaged by high or negative voltages but there is no protection at the inputs to the op amps Clearly this is a problem what happens if the wrong range is selected and 200V is fed into the 2 5V to 2 5V range this will destroy the op amps allow the diodes at the PIC ADC pin should protect the PIC hence it is inexpensive to fix It is also important to note that resistors normally have a maximum voltage rating of about 200V hence for safety reasons it is better for the 100kQ resistor for the 250V to 250V input range to be made up of several resistors in series i e 3 x 33kQ 1 x 1kQ The RS232 transport medium was chosen the main reasons why it was chosen is because it is easy to program reliable and every PC has at least one RS232 port The main disadvantage of RS232 is that it is slow 115Kbps max and will limited the maximum real time sample rate when compared to other mediums e g USB 12Mbps The USB port is ideal for this type of application but because a USB port can have many devices daisy chained the communication protocol must be complaint with the USB standard This USB communication protocol standard is quite large and complex and it was decided that it would take too much time to implement Note the scope program is designed to flexible hence sometime in the future the transport medium could be changed allowing for faster real time sample rates
15. fully Vew Toos Window H Hans aes Figure 11 1 3g Screen dump of scope program sample rate 100Hz input wave 100Hz sinewave 0 5V 200Hz sinewave 0 5V connected to CH1 ANO see figure 11 1 3h 5 divisions per cycle hence the calculated frequency of this waveform is 1 5 0 1 2Hz This signal is clearly an alias of the original signal false signal Sample Dist Trg Time a Base M CHI fiv DIV Figure 11 1 3h Screen dump of scope program sample rate 100Hz input wave 200Hz sinewave 0 5V EEE516J4 Honours Project Page 119 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 11 1 4 Conclusion Clearly the three tests that were carried out were completely successful and work can now start on the main real time embedded program Test 3 was extremely useful as it was able to test fully the graphically display for a fixed sample rate The triggering negative to positive 0 to positive in this case worked but the waveform was not completely stable as the amplitude of samples varied slightly due to noise or and tolerance of ADC hence the waveform was continuously changing very slightly sampling when the PIC is sleeping may reduce noise hence a more stable waveform could be displayed too slow to be practical The PIC datasheet recommends not to use the ADCs internal oscillator when the PIC is running above 1MHz unless sampling is done when PIC is sleeping mark3
16. Friday 21 June 2002 Final Report Colin K McCord Abstract from crcLT Ist MPASM CCS PCM C Compiler Version 2 707 8851 Filename C WORK COLIN MPLAB PROJECT CRC CRCLT LST ROM used 600 7 Largest free fragment is 2048 RAM used 12 7 at main level 21 12 worst case Stack 2 locations MPLAB IDE C WORK COLIN MPLAB PROJECT CRC rsa Fle pee Edt Deag PICSTART Plus ke Toots eee c work colin mplab project cre crdt c test 1 test 2 test 3 test 4 ercANS CRC16 test 5 long int CRC16 char xmessage int length char CRC_Hi OxFF High byte of CRC initialised x char CRC_Lo OxFF Low byte of CRC initialised x long int CRC int indey A j Will inday inta CRE lankin tahle Stopwatch m watch t oj Time 286 00 us Address Symbol Value Processor Frequenc 4 000000 MH 21 MAIN CRCANS H 90D9 SSE Ce y Clear On Reset Close Help in64Co f 85 WR No Wrep INS PiCi6Fe 7 pc0x256 M030 f zdcc Bk On Sim4MHz Debug Astr 4 e GS Sciwo Berco Empa Mc wo Gic wo Gicwo Merc ARAJE 21 2 Figure 6 8 1b Result of lookup table CRC test Total execution time for the lookup table CRC test program was 286 00uS 4Mhz that s 286 Cycles Clearly the lookup table CRC 286us runs over 5 times 5 7 faster than the raw calculation CRC 1 64ms for this example But unfortunately it is also clear that the lookup table CRC used 600 words of program m
17. Friday 21 June 2002 Final Report Colin K McCord Figure 7 0k demonstrates the multiple windows feature there are 5 views The top left display shows all four channels triggering on CH1 at a time base of 50ms DIV The middle left display shows CH1 with a time base of 10ms DIV The bottom left display shows CH4 with a 10ms DIV time base The top right display shows CH1 and CH3 at a time base of 0 1s DIV The bottom right display shows all four channels at an extremely high resolution at a time base of 5ms DIV and triggering off CH2 The only problem is that all scope windows have the same name Untilled clearly this needs to be improved e g Untilled1 Untilled2 etc as this is confusing to user the reason for this is because the default automatic naming of the windows was overwritten so that filenames could be placed on the title bar There is no limit on how many windows that can be opened simultaneously perhaps until the computer runs out of memory which on a modern PC could be 1000s of windows The scope program is also capable of exporting the scope display to the windows clipboard in the form of a bitmap and exporting the scope display to a bitmap file bmp The scope program also has its own file format sdf for saving and opening waveform data and scope settings Note functionally for printing the scope display directly from the scope program is not fully complete some additional work is required in this area
18. Note 20MHz clock must be used for 115 000 bps the error is to large at slower speeds use delay clock 20000000 20MHz clock change this value if using different clock speed use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 use fast_io E Fast access to PortE don t fiddle with TRISE Forward declaration of functions void SetBaudRate main set_tris_e 0x17 TRISE 00010111 RE2 RE1 and REO TTL Inputs SetBaudRate while TRUE Note printf could be used but this function is wasteful and will not be used puter S Transmit T putc e Transmit e putc s Transmit s putc t Transmit t putc i Transmit i putc n Transmit n OUteE gs Transmit g puted t Transmit putc Transmit puke Transmit delay ms 1000 Preset delay repeat every second void SetBaudRate switch PORTE amp 0x07 Read dip switches and setup baud rate case 0 set_uart_ speed 4800 break case 1 set_uart_ speed 9600 break case 2 set_uart_speed 14400 break case 3 set_uart_speed 19200 break case 4 set_uart_speed 32768 break case 5 set_uart_speed 38400 break case 6 set_uart_speed 57600 break case 7 set_uart_speed 115200 break EEE516J4 Honours Project Page 99 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord 10 5 Ma
19. Time Base Iv CHi CH2 CH3 Ready Figure 11 3 2 3h Screen dump of scope program sample rate 5000HZz input wave 1 000Hz sinewave 0 5V 2500Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3i Under sampled EEE516J4 Honours Project Page 144 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord oj x Sample Disp Trg Time Base Men fivolVv Che CH3 Ready Figure 11 3 2 3i Screen dump of scope program sample rate 5000Hz input wave 2 500Hz sinewave 0 5V 11 3 3 Test 10 Test External RAM chip The circuit diagram shown in figure 11 3 3a was constructed on prototype board with RS232 communication connected to laptop COM1 1000Mhz AMD processor 256Mhz SDRAM 8MB 3D accelerator card running windows XP EEE516J4 Honours Project Page 145 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord IA 1 2 ig 3 26 6 7 2 4 25 6 A 5 24 5 A 6 23 a AT 7 22 3 I 8 21 2 AT 9 20 1 I 10 19 0 11 18 12 17 13 16 14 15 M6264P 15 258 Bs 3 6 5 vec g 1 40 a ie 3s D7 2 39 ToT CH1 Del c5 C3 3 38 e 4uF 1uF CH2 of ae j ia 16 vec CH3 4 37 5 36 Bi c1 1 c1 vec aL Cnt Da 7MuF ssvtostov V 6 35 3 o4 Voltage DIP SW IRI fIR2 fIR3 DA J Doubler 1k 1k 7 34 Di 8 33 _ 2 i
20. break 10 9 Mark 9 c Real Time Mode Four Channels Chop Interrupt Time Base This program uses timer 2 PIC built in timer as the time base the timer causes an interrupt every 20US The variable TimeBaseMU is the time base multiplier e g 100 Hz 10ms hence TimeBaseMUX 500 Note no sampling is done during the interrupt routine as all interrupts are disabled while an interrupt is being processed hence the interrupt routine needs to take less than 20uS to execute or timing would be inaccurate e g say the interrupt routine execution time was longer than 20uS during this time timer 2 cannot cause any more interrupts hence accurate timing is lost The main program loops continuously checking the bSample flag if the flag is true the function Sample_RealTime is called else it continues to loop The bSample flag is set in the time base interrupt routine keeping the interrupt routine short Interrupt driven time base has one big advantage over using preset delays delay routines do not take into consideration processing delays e g waiting for UART buffer to empty while the PICs real time timer will EEE516J4 Honours Project Page 105 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord continue to count no matter what the PIC is doing and will cause an interrupt every 20uS assuming interrupt routine is finished before it is time to called it again This pr
21. create a splitter with 1 row 2 columns if m_wndSplitter CreateStatic this 1 2 TRACEO Failed to CreateStaticSplitter n return FALSE add the first splitter pane the default view in column 0 if m_wndSplitter CreateView 0 0 pContext gt m_pNewViewClass CSize 350 100 pContext TRACEO Failed to create first pane n return FALSE add the second splitter pane an input view in column 1 if m_wndSplitter CreateView 0 1 RUNTIME CLASS CControlsView CSize 0 0 pContext TRACEO Failed to create second pane n return FALSE activate the input view SetActiveView CView m _wndSplitter GetPane 0 1 m_wndSplitter LockBar TRUE m_wndSplitter SetColumnInfo 1 250 100 m_bSplitterCreated TRUE m_bShowPanel true return TRUE This function is called when the display is resized it sets the ratio of the split void CChildFrame OnSize UINT nType int cx int cy CMDIChildWnd OnSize nType cx cy CRect rect GetWindowRect amp rect EEE516J4 Honours Project Page 63 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord if m_bSplitterCreated m_bSplitterCreated set in OnCreateClient if m_bShowPanel true if rect Width gt 250 m_wndSplitter SetColumniInfo 0 rect Width 250 0 m_wndSplitter SetColumnInfo 0 0 0 m_wndSplitter SetColumniInfo 1 250 0
22. setup_adc_ports A_ANALOG RAO RA4 Analogue REO RE2 digital setup adc ADC CLOCK DIV 32 set_adc_channel 0 delay _us 20 Delay for sampling cap to charge while TRUE adcValue read_adc Get ADC reading Convert 16 bit adcValue to Real time frame structure CH1 adcHI char adcValue gt gt 5 amp Oxlf 010 0 d9 d8 d7 d6 d5 adcLO char adcValue amp Ox1f 0x80 110 0 d4 d3 d2 d1 d0o putc adcHI Transmit Byte 1 d9 d5 putc adcLO Transmit Byte 2 d4 d0 set_adc_ channel 1 delay _us 20 Delay for sampling cap to charge adcValue read_adc Get ADC reading Convert 16 bit adcValue to Real time frame structure CH2 adcHI char adcValue gt gt 5 amp Ox1lf 0x20 010 1 d9 d8 d7 d6 d5 adcLO char adcValue amp 0x1f 0xA0 1 0 1 d4 d3 d2 d1 d0 putc adcHI Transmit Byte 1 d9 d5 putc adcL0 Transmit Byte 2 d4 d0 set_adc_channel 0 delay ms 10 Preset delay repeat every 10ms that s 100 Hz void SetBaudRate switch PORTE amp 0x07 Read dip switches and setup baud rate case 0 set_uart_ speed 4800 break case 1 set_uart_speed 9600 break case 2 set_uart_speed 14400 break case 3 set_uart_speed 19200 break case 4 set_uart_speed 32768 break case 5 set_uart_speed 38400 break case 6 set_uart_speed 57600 break case 7 set_uart_speed 115200
23. unsigned short CRC16 unsigned char message unsigned short data_length Table of CRC values for high order byte static unsigned char Table CRC_Hil OX00 OXC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 OXC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 OXCO 0x80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 OXC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 0XC0 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0x80 0X41
24. 0X00 0XC1 0X81 0X40 0X00 OXC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 EEE516J4 Honours Project Page 36 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord OXCO OX80 OX41 OX00 OXC1 OX81 0X40 OX00 OXC1 0X81 0X40 OX01 OXCO 0X80 0X41 0x00 OXC1 0x81 0x40 0x01 OXCO OX80 OX41 OX01 OXCO 0x80 0x41 OX00 OXC1 OX81 0x40 Table of CRC values for low order byte static char Table CRC_Lo OX00 OXCO OXC1 OX01 OXC3 0X03 OX02 OXC2 OXC6 OX06 OX07 OXC7 OX05 OXC5 OXC4 0x04 OXCC OXO0OC OXOD OXCD OXOF OXCF OXCE OXOE OXOA OXCA OXCB 0X0B OXC9 OX09 0x08 OXC8 OXD8 OX18 0X19 OXD9 OX1B OXDB OXDA OX1A OX1E OXDE OXDF OX1F OXDD OX1D OX1C OXDC 0X14 OXD4 OXD5 0X15 OXD7 0X17 0X16 OXD6 OXD2 0X12 0X13 OXD3 OX11 OXD1 OXDO OX10 OXFO 0X30 OX31 OXF1 0X33 OXF3 OXF2 0X32 0X36 OXF6 OXE 0X37 OXF5 0X35 0X34 OXF4 OX3C OXFC OXFD 0X3D OXFF 0X3F OX3E OXFE OXFA 0X3A OX3B OXFB 0X39 OX 9 OXF8 0X38 0X28 OXE8 OXE9 0X29 OXEB OX2B OX2A OXEA OXEE OX2E OXEF OXEF OXED OXED OXEC OX2C OXE4 0X24 0X25 OXE5 0X27 OXE7 OXE6 0X26 0X22 OXE2 OXE3 0X23 OXE1 0X21 0X20 OXEO OXAO 0X60 0X61 OXA1 0X63 OXA3 OXA2 OX62 OX OXA6 OXA7 OX67 OXA5 0x65 OX64 OXA4 OX6C OXAC OXAD OX6D OXAF OX6F OX6E OXAE OXAA OX6A OX6B OXAB 0X69 OXA9 OXA8 OX
25. 5 000Hz distorted waveform clearly there are two main reason for this the first is that the UART transmit buffer fills up and the program must wait until the transmit buffer is free to accepted another character hence there is an additional time delay The second is that incoming characters were coming in faster than the scope program was processing them hence the buffer was overflowing causing gaps to appear in the data The solution of both is simple to solve the first problem one of the PICs real time timers can be used for the time base hence any delay caused by the UART will not affect the time base timer will continue to count The second problem can easily be solved by making the scope program read the serial port faster and increasing its buffer 11 3 Test Session 3 FG Wilson Lab 22 03 2002 11 3 1 Test 8 Dual Channel Test Program mark8 c was compiled and loaded into the PIC Basically this program chops between channel 1 and channel 2 e g sample CH1 trans sample CH2 trans delay repeat The test was a complete success the scope exe program was able to display both channels correctly Allow big triggering problem e g if channel 1 was selected for trigger it was almost impossible to get a stable channel 2 trace and if channel 2 was selected for trigger it was difficult to get a stable channel 1 trace This is a software problem and should be fixable Screen dump of the scope program version 1 036 19 03 2002 during t
26. CH1 leads CH2 by 90 Allow since the PIC knows how must time has elapsed PIC timer since sampling the pervious channel this information could be transmitted to the PC where the scope program could software correct the phase of each waveform Obviously this mode is only useful for periodical waveforms e g sinewaves and not for example an ECG signal Evidently the maximum real time sample rate is 5 75 kHz which is the maximum throughput of the real time frame structure through RS232 at the maximum baud rate 115kbaud Clearly there is no reason why more than one serial link could not be used to increase this real time sample rate for example two bytes are sent per ADC reading hence COM1 could be used to transmit the first byte and COM2 could be used to transmit the second byte 11 5 kHz sample rate Obviously the chosen PIC has only one hardware UART hence a software UART is required for the second com port easy to achieve using CCS compiler but this will push the PIC to the limits but should be ok at 20MHz No extra hardware i e no extra cost except for another serial cable is required as the MAX232 is a dual line driver chip hence there is a spare set of drivers that can be used for this additional com port Undoubtedly if the PIC struggles to cope with the additional software UART a separate hardware UART could be used Since the RS232 communications is the bottleneck when operating in the real time mode it is important that the r
27. EEE516J4 Honours Project Page 19 Chapter 4 The PIC16F877 Microcontroller Friday 21 June 2002 Final Report Colin K McCord 4 3 Overview of the Hardware USART The Universal Synchronous Asynchronous Receiver Transmitter USART module is one of the two serial I O modules The USART can be configured for asynchronous operation UART for communication with a PC or synchronous operation for communicating with peripheral devices such as DAC or DAC integrated circuit Note bit SPEN RCSTA 7 and bits TRISC 7 6 have to be set in order to configure pin PC6 TX CK and RC7 RX DT for USART operation CSS C compiler will automatically configure these bits but it is important to be aware that if using fast_io C mode to manually configure port C bits 7 amp 6 must also be manually set if using the hardware UART 4 3 1 Baud Rate Generator BRG This is basically a programmable 8 bit counter followed by a switchable frequency 4 flip flop chain which can be set up to give the appropriate sampling and shifting rates for the desired baud rate based on the PIC s crystal frequency XTAL e g for 2OMHz XTAL 20 giving XTAL Baud Rate Low Speed Mode _ 4 3 1 1 64 x X 1 Baud Rate High Speed Mode AT 4 3 1 2 16x X 1 6 _ XTAL x10 4 3 1 3 64 x BAUD It may be advantageous to use the high baud rate BRGH 1 even for slower baud clocks as this may reduce baud rate error in some cases EEE516J4 Honours P
28. Interrupt_TO Interrupt_T1 Interrupt_T2 Setup Timer 0 1 Enable Global amp 2 Interrupts Mark 7 c source code Ree Soe ae oe a Se aan eae ae eee oe eee eee FILE mark _7 c PROJECT Low Cost PC Based Oscilloscope DESC Test timer interrupts SSSSS gt SS55 gt 55 5555555555555 5555S 555555555555 5555S S gt gt gt DATE 05 03 2002 BY Colin K McCord VERSION 1 1 include lt 16F877 h gt device PIC16F877 16 ADC 10 fuses HS NOWDT NOPROTECT NOLVP byte PORTE 0x09 PortE lives in File 9 Note 20MHz clock must be used for 115 000 bps the error is to large at slower speeds use delay clock 20000000 use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 use fast_io E Fast access to PortE don t fiddle with TRISE define TO_INTS PER SEC 76 20 000 000 4 256 256 define Tl_INTS PER _SEC 76 20 000 000 4 1 65536 byte int_count0 Number of TO interrupts left before a 0 5s has elapsed byte int_countl Number of T1 interrupts left before a 0 25s has elapsed byte int _count2 Number of T2 interrupts left before a 100 msec has elapsed int rtcc RTCC timer0 interrupt called every time RTCC overflows 255 gt 0 Timer0_ISR EEE516J4 Honours Project Page 102 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord if int_
29. Only draw if CH2 is enabled memDC BitBlt 0 0 m_nClientWidth m_nClientHeight amp m_dcCH2 0 0 SRCPAINT SRCPAIN 4 if pDoc gt m_bCH3_ ENABLE true Only draw if CH3 is enabled memDC BitBlt 0 0 m_nClientWidth m_nClientHeight am_dcCH3 0 0 SRCPAINT SRCPAIN 4 if pDoc gt m_bCH4 ENABLE true Only draw if CH4 is enabled EEE516J4 Honours Project Page 62 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord memDC BitBl1lt 0 0 m_nClientWidth m_nClientHeight amp m_dcCH4 0 0 SRCPAINT SRCPAINT finally send the result to the display dc BitBlt 0 0 m_nClientWidth m_nClientHeight memDC 0 0 SRCCOPY memDC SelectObject oldBitmap This function created by wizard has been modified to override standard windows refresh features BOOL CScopeView Create LPCTSTR lpszClassName LPCTSTR lpszWindowName DWORD dwStyle const RECT amp rect CWnd pParentWnd UINT nID CCreateContext pContext Overrides the Normal Refresh stops flicker static CString className AfxRegisterWndClass CS_HREDRAW CS_VREDRAW return CWnd Create className lpszWindowName dwStyle rect pParentWnd nID pContext 7 7 Creating the Split Window View This function creates the split view it is called automatically by the framework BOOL CChildFrame OnCreateClient LPCREATESTRUCT lpcs CCreateContext pContext
30. OxFF High byte of CRC initialised af char CRC_Lo OxFF Low byte of CRC initialised a74 long int CRC int index 0 Will index into CRC lookup table while length index CRC_Hi messaget Calculate the CRC CRC_Hi CRC_Lo Table_CRC_Hi index CRC Lo Table CRC Lo index CRC CRC Hi CRC CRC lt lt 8 CRC_Lo return CRC 0X41 0X81 OXC1 0X01 0x40 0x80 Oxco 0x00 0X41 0X81 0xXC1 0x01 0X41 0x81 Oxco 0x01 0X41 OXCT7 OXCB OXDE OXD2 0X32 OX3E OX2B OX27 OXA1 OXAD OXB8 OXB4 OXBO 0X94 0x59 OX8D 0X83 0x00 0X40 0x81 OXCO 0x00 0x41 0x80 Oxcl 0x00 0X40 0X8 OXCO 0x00 0x40 0x80 OXCO 0x00 0x05 OXOB OXDF 0X12 0X36 OXFE OX2A OXET7 0X63 OX6D OXB9 Ox74 0x50 0x54 0x58 OX4D Ox41 Colin K McCord Oxcl 0x01 0X4 0x80 Oxcl 0x01 0x41 0x81 Oxcl 0x01 0X40 0x80 Oxcl 0x01 0x41 0x80 Oxcl jo OXC5 OXC9 OX1F 0X13 OXF6 OXFA OXEA OXE6 OXA3 OXAF 0x79 0x75 0x90 OX9C 0x98 0X4C 0x81 0x81 0XC0 0x01 0x41 0x81 OXCO 0x01 0X40 0x81 OXCO 0x01 0x41 0x81 OXCO 0x01 0x41 0x81 Oxc4 0x09 OXDD OXD3 OXF7 OX3A OXEE 0X26 OXA2 OX6F OXBB OXB5 0x91 OX5C 0X88 OX8C 0x80 EEE516J4 Honours Project Page 40 Chapter 6 Communication Protocol Development
31. WriteFile m_hCom buffer 1 amp iBytesWritten NULL 7 6 Solving the Flickering Problem When updating the screen the screen must not flicker This problem was solved by drawing the waveform into a memory CDC bitmap and then updating the display by drawing only the changes Code for updating the display grid and trace already drawn in their CDC void CScopeView OnPaint CPaintDC dc this device context for painting CDC memDC CBitmap memBitmap CBitmap oldBitmap bitmap originally found in CMemDC no real plotting work is performed here just putting the existing bitmaps on the client to avoid flicker establish a memory dc draw to it and then BitBlt it to the client memDC CreateCompatibleDC amp dc memBitmap CreateCompatibleBitmap amp dc m_nClientWidth m_nClientHeight oldBitmap CBitmap memDC SelectObject amp memBitmap if memDC GetSafeHdc NULL first drop the grid on the memory dc memDC BitBlt 0 0 m_nClientWidth m_nClientHeight amp m_dcGrid 0 0 SRCCOPY now add the plot on top as a pattern via SRCPAINT works well with dark background and a light plot Only paint channels that s are enabled as this will reduce CPU load if pDoc gt m_bCH1_ENABLE true Only draw if CH1 is enabled memDC BitB1lt 0 0 m_nClientWidth m_nClientHeight amp m_dcCHl 0 0 SRCPAINT SRCPAIN 4 if pDoc gt m_bCH2_ENABLE true
32. amp m dcCH4 0 0 SRCPAINT SRCPAINT Copy contents of memDC to clipboard OpenClipboard EmptyClipboard SetClipboardData CF_ BITMAP bitmap GetSafeHandle CloseClipboard Clean up memDC SelectObject pOldBitmap bitmap Detach 7 10 Exporting the Scope Display as a Bitmap BMP File The scope program has the ability to save the scope display as a bitmap file The user clicks on Export in the File menu see figure 7 10a then a standard windows save dialogue box appears see figure 7 10b to ask the user were to save the file EEE516J4 Honours Project Page 72 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord Scope Scopel Export Scope Display 2 x E Fie Edt View Tools Window Hep 5 ED New cvn By ef i Save in Z Desktop z a ck EB Cot o CORW SIMPLAB My Network Places amp D on Laptop 1 SMr 1 Mcrum ICD ORDER PI Dial up Connections GMy Webs Ctl S New Folder DvO a Network 3 2 Floppy A GIEDUCATIONAL WORK 5 JProtel SBACKUP E SJFinal Report KScope bmp amp Print PC on Laptop H Internet Downloads GI Shortcut to Interim Re X Print Preview LMiniProjet 2WIN 2000 HD D Print Setup gt it Exit Figure 7 10a User clicks Export Figure 7 10b Save dialogue box appears ETETE v3 1 E lojxi Figure 7 10c shows the contains of the exported Eei yew Zoom i
33. ba r Figure 11 2 3 1b Screen dump of scope program sample rate 2 000Hz input wave 20Hz sinewave 0 5V 50Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 1c resolution 200 x 160 that s 20 x 16 divisions 3 9 division per cycle hence the calculated frequency of the waveform is 1 3 9 0 005 51 3Hz SCOP lol x B Hie Edt Vew Toos Window Help _ 18 x j ala Efa Sample Disp Trig Time Base z V CHi 5V DIV eia fiviov e i Ready CAP Figure 11 2 3 1c Screen dump of scope program sample rate 2 000Hz input wave 50Hz sinewave 0 5V EEE516J4 Honours Project Page 126 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 100Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 1d resolution 200 x 160 that s 20 x 16 divisions 1 95 division per cycle hence the calculated frequency of the waveform is 1 1 95 0 005 102 5Hz Scope Scope1 E 5 x 3 Bie Edt Vew Toos Window Help x Om B S a Esa Sample Disp Trig Time an Base l HHH i E HHHH HHHH HH Ready Figure 11 2 3 1d Screen dump of scope program sample rate 2 000HZz input wave 100Hz sinewave 0 5V 200Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 1e resolution 100 x 80 that s 10 x 8 divisions 0 975 division per cycle hence the calculated frequency of the waveform is 1 0 975 0 005
34. e g the PIC should ignore random noise or corrupt frames Hence a 16 bit CRC same as used for storage mode is used to make sure that the frame is valid before the PIC implements the control message The CRC takes some time to calculate hence there are crude checks that are carried out first before a CRC is calculated as false control messages random noise would severely affect system performance Hence the PIC waits for the SOF frame and ignores all other characters until a frame is detected once a frame is detected it then waits for 5 more bytes If these 5 bytes are not received within a certain time e g max of 1 5ms gap between bytes the PIC will timeout and return to what it was doing before the message was detected If 5 bytes are received the frame is CRC check and if valid the message is decoded and implemented Note it is possible that random noise could generate a SOF e g 0x01 and 5 further bytes but the CRC will make sure that the false frame is not implemented b7 b6 b5 b4 b3 b2 b1 bO R v3 vz vE SETUP_REG2 Number of Samples Fray Rn ae 1 0 Channel n disabled 1 Channel n enabled Figure 6 96 SETUP_REG1 SETUP_REG1 is shown in figure 6 9b this register specifies real time storage mode sample rate multiplier sample awake sleeping and which channels are enabled disabled Note sampling when the PIC is sleeping is only an option for very slow sample rates as it takes a long time for the PIC to r
35. pApp gt m_nInputRange printf infile d n pApp gt m_nSampleMode printf infile Sd n pApp gt m_SampleRateSelection printf printf infile d n m_bCH2_ENABLE printf infile d n m_bCH3_ ENABLE printf infile d n m_bCH4 ENABLE print printf print printf f infile sd n m_TimeBaseSelection infile d n m_nCH1l VOLTS infile d n m_nCH2 VOLTS infile d n m_nCH3 VOLTS infile d n m_nCH4 VOLTS infile d n m_nTrigger infile d n m_ nTriggerType infile Sd n SView gt m_ColorGridBackGround Sd n SView gt m_nRefreshRate r print print print print printf r Ih Ih Ih Hh Hh Hh Hh ih Fh Fh Hh Hh Fh Hh Fh Hh Hh Hh Hh Fh Hh Hh Hh Fh Fh h f f f f f infile d n m_bCH1 ENABLE f f f f f infile fclose infile SetTitle m_ Filename Notice that function Save uses the old ASIC C method for saving files this method is 100 windows compatible including long filenames and is preferred by most C programmers Basically a pointer to the file is setup infile and the ASIC C function fprintf is used to save scope data to the file using the ASCII format Writing the file in binary and not ASCII would produce a more efficient file but this file would not be readable in notepad for example First the four data arrays one for each channel are saved then all t
36. the following function is called void CScopeDoc OnFileSaveAs 07 04 2002 by CKM CFileDialog dlg FALSE T sdf m Filename OFN_HIDEREADONLY T Scope Data File sdf sdf if IDOK dlg DoModal Check for existence if _access dlg GetPathName 0 1 if AfxMessageBox File dlg GetPathName Already exists Do you want to replace the existing file MB YESNO MB _ICONINFORMATION IDYES return i m Filename dlg GetPathName Save Basically the OnFileSaveAs function using a windows standard CFileDialog box to ask the user to specify a filename and directory The function also checks if the selected filename already exists if it does the user gets the option to override the file or to cancel save operation Function Save is called if a valid filename has been entered and user has not cancelled the save operation ux Save in Desktop fa ck ERY My Computer 2D on Laptop 1 My Network Places Dial up Connections Sm 1 3 Merum CD ORDER ovo GMy Webs 332 Floppy A GIJEDUCATIONAL WORK a Network SBACKUP amp Fie1 sdf GIProtel 2C on Laptop H amp JFinal Report Shortcut to Interim Re C Work Space internet Downloads E Untitied sdf 3 EMnProjet SWIN 2000 HD D Save as type Scope Data File sdf Y Cancel 4 Figure 7 8b Windows standard CFileDialog box This function creates and writes
37. their codes and this one is quite simple this one makes it very easy to build these cool menus with bitmaps into your application I ve removed the Icon loading stuff and replaced it with Bitmaps The bitmaps allow you to use the 16X15 toolbar bitmaps directly from your toolbars in the resource editor As well there is no scaling of the bitmaps so they always look good You can also load Bitmap resources and define bitmaps for your check marks I ve also added the default checkmark drawing stuff separators proper alignment of keyboard accelerator text keyboard shortcuts proper alignment of popup menu items proper system colour changes when the Display Appearance changes plus bug fixes to the Ben Ashley s LoadMenu function for EEE516J4 Honours Project Page 77 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord complex submenu systems made quite a few other modifications as well too many to list or remember also use the disabled bitmap dithering function of Jean Edouard Lachand Robert to create the disabled state bitmaps must admit it does a much better job then the DrawState function If you find any bugs memory leaks or just better ways of doing things please let me know used Visual C 5 0 and have not tested compatibility with earlier VC versions I ve tested it on Win 95 NT at various resolutions and colour palette sizes Brent Corkum W4 Title block from BCMenu h J KR RK
38. use to generate a 0 to 5V e g 5V peak to peak with a DC offset of 2 5V sinewave at a variable frequency e g 2Hz 5Hz 10Hz etc Note Sample rate 1000Hz 10 horizontal samples per division Hence scope time base is 0 01 seconds per division that s 100Hz note time base is fixed on this version of the scope program and was set to 115Kbaud 2 5Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3a high resolution 800 x 160 that s 80 x 16 divisions 40 division per cycle hence the calculated frequency of the waveform is 1 40 0 01 2 5Hz Fi inj x 3 fle Edt View Tool Window Help 8 x MGSO BE RADAR fe ll a f HHH is Figure 11 2 3a Screen dump of scope program sample rate 1 000Hz input wave 2 5Hz sinewave 0 5V 5Hz sine wave 0 5V connected to CH1 ANO see figure 11 2 3b resolution 200 x 160 that s 20 x 16 divisions 19 division per cycle hence the calculated frequency of the waveform is 1 19 0 01 5 26Hz EEE516J4 Honours Project Page 121 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Sample Disp Trig Time Base 4 ASAA i evre r Figure 11 2 3b Screen dump of scope program sample rate 1 000Hz input wave 5Hz sinewave 0 5V 10Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3c resolution 200 x 160 that s 20 x 16 divisions 10 division per cycle hence the calculated frequency of the waveform is
39. 0 C Sinewave Freq Hz 75 0 C Squarewave Squarewave C Random Amp V 5 C Random Amp V 3 l Channel 3 ri C Sinewave Freq Hz 0 e Freq Hz ooo G jor Amp 93 Amp VY i Simulated Mode RX History TX History g gt Aut os a Real Time norpa ha Z Enable Options Simulated Sample Rate 1000 Exit Figure 8 0a Screen dump of sim exe V1 007a 29 03 2002 If a channel is disabled all of its controls are greyed i e ch3 and ch4 are disabled in figure 8 0a notice that the user has the option to specify real time storage or auto controlled by PC At present auto and storage mode have not been implemented There are two large edit boxes that were designed to be used to display RX and TX history in a low level format for debugging purposes this feature was not implemented because there were no communication problems during development The program was used to test the communication protocols real time storage control and graphical scope display including triggering methods at different baud rates Note accurate timing is not simulated as this is difficult to achieve hence the best way of testing the timing is on an actual PIC hence the frequency settings for each channel are to be used as a guild and are not accurate Note the amplitude value of each channel is between 0 to 5V assuming this range is selected on the scope program e g input range It was foreseen that the scope program would contr
40. 10 This class is also applied to the right click pop up menu void CMainFrame OnContextMenu CWnd pWnd CPoint point BCMenu popmenu popmenu LoadMenu IDR_GRID_ POPUP popmenu LoadToolbar IDR_MAINFRAME BCMenu psub BCMenu popmenu GetSubMenu 0 psub gt TrackPopupMenu TPM _LEFTALIGN TPM RIGHTBUTTON point x point y this popmenu DestroyMenu EEE516J4 Honours Project Page 80 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord 7 12 Windows 95 98 Compatibility Problem scope v1 008a 20 12 2001 The Scope program is being developed on Windows 2000 service pack 2 Windows 2000 is a stable and reliable operating system unlike other Microsoft operating systems e g Windows 95 Windows 98 and Windows ME It is important that the scope program runs on all versions of Microsoft Windows as Windows 95 98 and ME are still widely used On the 20 of December 2001 the scope program Version 1 008a was tested on Windows 98 and it was discovered there was a significant problem The CPU load was high and the system memory resources were disappearing extremely quickly after about a minute the system was completely unusable At first it was not understood why this was happening as the program worked on Windows 2000 without any problems with a CPU load of less than 2 The tests were carried out on the same system dual boot Windows 2000 or Window 98 OSR 2 800MHz
41. 2 amp EOR with A001 Sols 0110 1 A001 010 0000 0000 0001 NEW CRC 00 0 LSB is 0 gt gt 4 no 3 SSA 0110 0 1 LSB is 1 gt gt 1 no 4 amp EOR with A001 SPL 0011 00 1 A001 1010 0000 0000 0001 NEW CRC 1001 00 0 LSB is 0 gt gt 4 no 5 eaa 0100 100 1 LSB is 1 gt gt 1 no 6 amp EOR with A001 gt gt 1 0010 0100 Al A001 1010 0000 0000 0001 EEE516J4 Honours Project Page 37 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord NEW CRC 1000 0100 11 0 LSB is 0 gt gt 4 no 7 gt gt 1 0100 0010 O1 1 LSB is 1 gt gt 1 no 8 amp EOR with A001 gt gt 0010 0001 00 1 A001 1010 0000 0000 0001 NEW CRC 1000 0001 00 0 0x813E Swap high amp Low Bytes Cal CRC 16001 decimal or 3E81 Hex 6 8 1 Comparison of Raw Calculation CRC amp Lookup Table CRC Theoretically the raw calculation CRC function produces it result slower than the lookup table CRC function but the lookup table will eat up program memory 512 words The objective of this simple experiment is to prove that this is the case and to find out exactly the performance of each this information will be used to help decide on which technique is best for this project Simulations were carried out using Microchip MPLAB Raw calculation CRC test program crc c i
42. 23 5 i AT 19 22 0 A ce L c7 20 21 33pF 33pF 7 PIC16F877 20 P Figure 5 2a Digital circuit diagram version 1 3 19 03 2002 Port D is used for the first 8 bits of the 13 bit address bus 2 8192 address RC4 to RCO is used for the upper 5 bits of the address bus and Port B is used for the 8 bit data bus The only component making use of the data and address buses is the external RAM chip hence there is only the need for one control line R W this control line R W puts the RAM chip in read or write mode If the data and buses are shared with other components sometime in the future the RAM chip must be disable while communicating with these devices this requires an additional control line OE To reduce cost even further a 28 pin version of the chosen PIC PIC16F876 could be used but this means a serial RAM chip must be used The operation of a serial RAM chip is much slower than a parallel RAM chip as each bit of the address and data must be clocked in one bit at a time The purpose of the RAM chip is to compensate for the RS232 bottleneck serial link surly a serial RAM chip would have the same bottleneck Yes it does but the maximum baud rates are much faster than RS232 hence a serial RAM chip is a real possibility especially now the PIC is running at 20 MHz must used 20MHz for high RS232 baud rate The ADC input channels RA3 RAO labelled CH4 CH1 are connected to the output of the analogue cir
43. 26 to 28 Pages 28 to 29 Page 29 Pages 30 to 42 Pages 30 to 31 Page 31 Page 32 Pages 32 to 33 Pages 33 to 34 Pages 34 to 35 Page 35 Pages 36 to 41 Pages 38 to 41 Page 42 Pages 43 to 85 Page 49 Pages 49 to 50 Pages 50 to 52 Pages 52 to 58 Pages 58 to 59 Pages 60 to 62 Pages 62 to 63 Pages 63 to 64 Pages 65 to 70 Pages 71 to 72 Pages 72 to 77 Table of Contents Friday 21 June 2002 Final Report 7 11 Owner Drawn Menus with Bitmaps 7 11 1 Integrating Brent Corkum s BCMenu Class with the Scope Program 7 12 Windows 95 98 Compatibility Problem scope v1 008a 20 12 2001 7 13 Windows XP Compatibility Problem scope v1 01 7a 05 02 2002 7 14 Additional Video Card Features That May Explain Low CPU Usage 8 0 The Simulator Program 8 1 How Channel Simulation is Achieved 9 0 Test Program 9 1 User Manual 9 2 How is RS232 Communication Achieved 10 0 PIC Software Development 10 1 Mark 1 c Test RS232 Communications 10 2 Mark 2 c Fully Test RS232 Communications 10 3 Mark 3 c Real time Mode 1 channel fixed sampling delay 10 4 Mark 4 c Test RS232 Baud Rate Set by dip Switches 10 5 Mark 5 c Fully Test RS232 Communications Adjustable Baud Rate 10 6 Mark6 c Real time mode 1 channel fixed delay adjustable baud rate 10 7 Mark 7 c Test Timer Interrupts 10 8 Mark 8 c Real time mode dual channel fixed delay adjustable baud rate 10 9 Mark 9 c Real time mode four channels ch
44. 4 times a second and timer 2 interrupt is used to transmit Interrupt_T2 10 times a second The DOS based test program test exe version 1 05 was used in the RX terminal mode to receive incoming characters This test fully tests the timer interrupts which will be used for time base communications etc Screen dump of text exe after a couple of seconds Waiting for message press a key to stop Main Interrupt_T2 Interrupt_T2 Interrupt_Tl Interrupt_T2 Interrupt_T2 Interrupt T2 Interrupt TO Interrupt Tl Interrupt T2 Interrupt T2 Int errupt T2 Interrupt Tl Interrupt T2 Interrupt T2 Interrupt_TO Interrup t_Tl Interrupt T2 Main Interrupt T2 Interrupt T2 Interrupt Tl Interr upt_T2 Interrupt_T2 Interrupt_T2 Interrupt_TO Interrupt_Tl Interrupt_T EEE516J4 Honours Project Page 130 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 2 Interrupt_T2 Interrupt_T2 Interrupt_Tl Interrupt_T2 Interrupt_T2 I1 nterrupt_TO Interrupt_Tl Interrupt_T2 Main Interrupt_T2 Interrupt T2 Interrupt_Tl Interrupt T2 Interrupt_T2 Interrupt_T2 Interrupt_TO Inte rrupt_Tl Interrupt_T2 Interrupt_T2 Interrupt_Tl Interrupt_T2 Interrupt _T2 Interrupt_T2 Interrupt_TO Interrupt_Tl Interrupt_T2 Main Interru pt_T2 Interrupt_T2 Interrupt_Tl Interrupt_T2 Interrupt_T2 Interrupt_T2 Interrupt_TO Interrupt_Tl Interrupt_T2 Int
45. 7 2 The Grid The grid design is shown in figure 7 2a there are 10 vertical and 10 horizontal points per square The standard resolution has 10 horizontal squares and 8 vertical squares m Z Bi The grid is dynamic flexible and is one of the key aspects of the scope program If the scope window is resized the grid will automatically resize The grid resolution is also user configurable allow the resolution of each square is fixed the number of vertical and horizontal squares are user configurable 80 There are two important arrays that must be filled after the scope window has been resized or the grid resolution has been changed m_nGridY amp m_nGridX these arrays are used to access individual grid points 2 Figure 7 2a Grid layout For example the grid layout shown in figure 7 2a has 100 horizontal X points and 80 vertical Y points The scope window size is retrieved from the system and stored in variables m_nClientWidth and EEE516J4 Honours Project Page 50 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord m_nClientHeight m_nClientWidth is divided by 100 X and m_nClientHeight is divided by 80 Y this gives the gap in pixels between each grid point note variables have been converted to floating point numbers for increased accuracy The array m_nGridX n is filled by looping from n 1 to n 100 X and multiplying n by t
46. AMD processor 256MB PC133 RAM and Creative Labs 3D Blaster GeForce 3 Titanium 200 64MB 3D accelerator video card s Scope Scopel Be O Eile Edit View Window Help l j xj Dee aa Time Base z Channel A Scale t 2 RE See Pm we Channel B S E EnS a EUN UE G E E a a PAG Pith E ANFEN EEEN raner a r TTT TTY TY YT tT z c System resources 66 free lola fe elel TTT itt User resources 67 free CTANTAABRUNEUNAREANAA GDI resources 66 free Memory Manager Unused physical memory Lastvalue 4096 Peak value 214323200 AStart ABRIS edSystem Monitor JResource Meter JAA AScope Scope1 aSo 1321 Figure 7 12a Screen dump of System Monitor Resource Meter and Scope V1 008a running in Windows 98 Figure 7 12a clearly shows that there is a problem CPU load is high systems resources are dropping fast and free physical memory has been completely used up Note that this screen dump was taken after 10 seconds the system resources continue dropping after a minute the system resources were less than 10 and the system was completely unusable The reason why the screen dump figure 7 12a was taken after 10 seconds was because the system resources got so low that it was impossible to capture the screen Screen dump figure 7 12b was taken after 40 seconds notice that it was impossible to get a colour image after a minute it was completely
47. Channel4 __Incrementi ADC Value ADC Value Y A e Transmit Read Read Read Read Array Channel 1 Channel 2 Channel 3 Channel 4 ADC ADC ADC ADC Array i Array i Channel 1 Increment i Channel 3 Increment i ADC Value ADC Value x LY Figure 6 2b Illustration of storage mode with four channels chop mode Alternate sampling can applied to storage mode but there is no real advantage over chop mode Recall that the main reason of having alternate mode was to maximise the sample rate of each channel in the real time mode This no longer apples as storage mode removes the RS232 bottleneck the new bottleneck is now the speed of the PICs ADC hence alternate mode cannot increase channel sample rates EEE516J4 Honours Project Page 31 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord 6 3 Control Protocol The PIC checks the UART buffer regularly or UART interrupt checking to see if a control message is being received Once a control message has been detected the PIC leaves the main program and checks CRC check that the message is valid if not return to the main program if valid decode and implement the message This process is illustrated in figure 6 3a vei P a CS IPROT Main Program ControlPROT d Vea y Receive and Set SWP check message gt Call Function Co
48. Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Scope Scope1 5 x B Fie Edt Vew Toos Window Hep x ng e E amp Ba IF Sample Disp Trig Time an Base M CHI jiv OlV CH2 moe hvov x Ready Figure 11 2 3f Screen dump of scope program sample rate 1 000Hz input wave 100Hz sinewave 0 5V 200Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3g resolution 100 x 80 that s 10 x 8 divisions 0 5 divisions per cycle hence the calculated frequency of this waveform is 1 0 5 0 01 200Hz But waveform is under sampled and heavily distorted recall that the pulse interpolator display type scope exe uses this requires at least 10 sample cycle before a recognisable sine wave can be plotted Scope Scopel o x C Bie Edt Vew Toos Window Help x i Ora Risa eee Sample Disp Trig Time f x Base HHH 2 a Ai M cHe m HICK NEPRI CCT a A ANA AA Figure 11 2 3g Screen dump of scope program sample rate 1 000Hz input wave 200Hz sinewave 0 5V 500Hz sine wave 0 5V connected to CH1 ANO see figure 11 2 3h resolution 100 x 80 that s 10 x 8 divisions something real strange has happened here clearly the result of under sampling EEE516J4 Honours Project Page 124 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Scope Scope1 lol x C Ble Edt
49. EEE516J4 Honours Project Page 93 Chapter 9 Test Program Friday 21 June 2002 Final Report Colin K McCord E a E Function com handler Description Interrupt s normal program operation when incoming character s are detected and store s them on the buffer Input none Output Incoming character s stored on buffer Return none Pt a Bl a ET ed ged Ped BR CEL a eS ed i put inporthb COM RBR if i_put amp buffer SIZE i _put buffer outporthb 18259 E0OTI Transmitting a single character void trans int c Vit See etesenSssteeses sete eset ese cee ee eee eee aoe ee Ge eee eee eee Function trans Description Wait s until UART is ready and then transmits a single character Input Character c Output Transmit c through COM port using RS232 Return none pain jiin paat a piat f a a faat a a ha pady paa paiay a a et Day paa while inportb COM LSR amp 0x20 outportb COM THR c Receiving a single character int readchr char c Rs teeta ete eee ee eel eee eee te ees Function readchr Description Check s if character has been received store s received character into c Input Address of character c Output c now contains received character Return 0 when character is present else 1 aR tl ant Agi god eh A a CH ro oC EE oe R EE NE eek rn Ns RE BP OY if i_get i_put return 1 C AT get
50. LineTo 8 m nGridY m_nCH1POS Draw Zero point dotted line for i 10 i lt m_nGridX x 3 i 6 for n 0 n lt 3 n m_dcCH1 SetPixel i n m_nGridY m_nCH1POS LIGHTRED draw offset Arrow m_dcCH1 MoveTo m_nGridX x 2 m_nCH1 Offset 8 m_dcCH1 LineTo m_nGridX x 2 m_nCH1 Offset 5 2 m_dcCH1 LineTo m_nGridX x 2 m_nCH1 Offset 5 2 m_dcCH1 LineTo m_nGridX x 2 m_nCH1 Offset 8 m_dcCH1 SelectObject pOldPen Invalidate TRUE Redraw Display The code marked in red is the actual drawing of the waveform basically the array is scanned and drawn to the channel DC m_dcCH1 using the grid coordinate arrays m_nGridX and m_nGridY The code looks more complex because of the following variables m_nTriggerCH1 specifies the array trigger offset m_nCH1_ Offset specifies the channel offset m_Skip specifies the number of array locations to skip to achieve the required time base m_MUX specifies the number of array location to duplicate to achieve the required time base and m_nVPD_CH 1 sets the voltage scale Note drawing of the zero point and offset arrows are also drawn in this function and all four channels are drawn in exactly the same way EEE516J4 Honours Project Page 57 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord This function is called by the system when the scope display is resized void CScopeView OnSize UINT nType int cx int cy CView OnSize n
51. OF FIGURES 1 0 Project Background Page 1 to 3 1 0a 20MHz Analogue Dual Trace CRT about 400 W2 Page 1 1 0b 150MHz Analogue Digital CRT about 1 600 W1 Page 1 1 0c Diagram of a typical cathode ray tube CRT construction Page 1 1 0d 100MHz 4 channel digital storage oscilloscope about 1 800 W2 Page 2 1 0e 100MHz handheld digital storage oscilloscope about 1 000 W2 Page 2 1 0f 100kHz dual channel PC based storage oscilloscope about 250 W2 Page 2 1 0g 20kHz single channel PC based storage oscilloscope about 95 W2 Page 2 3 0 Fundamentals Pages 5 to 15 3 1a Block diagram of a basic CRT oscilloscope Page 5 3 1b Types of CRT oscilloscopes Page 5 3 2a Example showing how a sinewave is digitally sampled Page 6 3 3a Comparison of dot pulse interpolator and sine interpolator displays Page 7 3 4a Demonstrating aliasing Page 8 3 4 1a The key low pass filter design parameters Page 9 3 4 3a Step 1 Open anti aliasing wizard Page 11 3 4 3b Step 2 Enter 3dB cut off frequency Page 11 3 4 3c Step 3 Enter sampling frequency Page 11 3 4 3d Step 4 Enter ADC resolution Page 11 3 4 3e Step 5 Ideal signal to noise ratio is calculated Page 11 3 4 3f Step 6 Click build Butterworth the finish Page 11 3 4 3g Anti aliasing filter designed by the anti aliasing wizard Page 12 3 5a Simplified illustration of the von Neumann architecture Page 12 3 5b Simplified illustration of the Harvard architecture Page 13 3 6a Il
52. Qty Each Cost 300 373 Quad 741 op amp LM348N 2 0 40 0 80 134 2988 16 way dip socket 2 0 12 0 12 543 380 1KQ Metal Oxide Film 1 Resistor 6 0 02 0 11 543 627 10KO Metal Oxide Film 1 Resistor 9 0 02 0 17 543 457 2KQ Metal Oxide Film 1 Resistor 3 0 02 0 06 543 860 100KQ Metal Oxide Film 1 Resistor 3 0 02 0 06 543 860 1500 Metal Oxide Film 1 Resistor 3 0 02 0 06 352 5340 1N4007 Diode 6 0 04 0 23 330 760 1W DC to DC converter 5V input 15 15V output 1 5 05 5 05 Total 6 66 System Powering Circuit Order Cost Number tem Qty Fach Cost 701 853 MC7805CT 5V 1A Voltage Regulator 1 0 30 0 30 920 757 100uF 50V Electrolytic Capacitor 2 0 10 0 21 746 063 100pF Ceramic Capacitor 2 0 13 0 26 178 701 Clip On Heat Sink 1 0 36 0 36 Total 1 13 Total component cost 15 18 6 66 1 13 22 97 EEE516J4 Honours Project Page 29 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord 6 0 COMMUNICATION PROTOCOL DEVELOPMENT There are two main communication protocols real time and storage Note there is an additional communication protocol required to control the PIC e g change sample rate change from real time to storage etc Because RS232 has separate transmit and receive lines there is no chance of a collision with the real time storage data Let s call this additional communication protocol the control protocol note an
53. S Switch SCI Serial Communications Interface SPBRG Serial Port Baud Rate Generator SPEN Serial Port Enable bit SPI Serial Peripheral Interface SREN Single Receive Enable bit TACQ Amplifier Setting Time Te Hold Capacitor Charging Time Tcorr Temperature Coefficient TX Transmit TXSTA Transmit Status and Control Register UART Universal Asynchronous Receiver Transmitter USART Universal Synchronous Asynchronous Receiver Transmitter USB Universal Serial Bus V Voltage Vec Supply Voltage Vpp Supply Voltage Vi Input Voltage Vin Input Voltage Vo Output Voltage Vour Output Voltage Vss Ground WWW World Wide Web X Horizontal XTAL Crystal frequency Y Vertical Q Ohms EEE516J4 Honours Project Page IV Colin K McCord Notation Friday 21 June 2002 Final Report TABLE OF CONTENTS 1 0 Project Background 2 0 Design Specifications 2 1 2 2 Core Objectives Further Development 3 0 Fundamentals 3 1 3 2 3 3 3 4 3 5 3 6 The Basic CRT Oscilloscope Digital Sampling Oscilloscopes Display Formats Aliasing 3 4 1 Typical Low Pass Filter Design Parameters 3 4 2 Typical Low Pass Filters 3 4 3 Software Generation of an Anti Aliasing Filter The PIC Microcontroller RS232 Serial Interface 4 0 The PIC16F877 Microcontroller 4 1 4 2 4 3 Overview of the File Registers Overview of the 8 channel 10 bit ADC Overview of the Hardware USART 4 3 1 Baud Rate Generator BRG 5 0
54. These arrays are global and can be accessed from any part of the program Sampled readings for each channel are stored in these arrays filled by the communication protocol note the method used to fill these arrays is depended on which mode is selected e g for scroll mode every location is moved one placed to the left and the new reading is placed at the end of the array Note the 10 bit ADC readings have already been converted into voltage depending on the selected input voltage range and multiplied by 1000 to increase resolution without having to use floating point numbers e g for range 10 to 10V 10V 10000 OV 0 and 10V 10000 EEE516J4 Honours Project Page 52 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord The basic principle is that the program continuously scans through these arrays updating the display at a user configurable refresh rate Software interrupt timer for redrawing traces void CScopeView OnTimer UINT nIDEvent if nIDEvent nTimerRefresh KillTimer nTimerRefresh Trigger Cal Trigger Points Set scales m_ nVPD CH1l pDoc gt m_nCH1_ VOLTS m_ nVPD_CH2 pDoc gt m_nCH2 VOLTS m nVPD_CH3 pDoc gt m_nCH3_ VOLTS m nVPD CH4 pDoc gt m_nCH4 VOLTS Draw Traces OnDrawCH1 OnDrawCH2 OnDrawCH3 OnDrawCH4 f Enable Timer again SetTimer nTimerRefresh m nRefreshRate NULL CView OnTim
55. Time Base Jv CHI CH2 fi CH3 fiviov r fi j Figure 11 3 2 3a Screen dump of scope program sample rate 5000Hz input wave 50Hz sinewave 0 5V 100Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3b 5 divisions per cycle hence the calculated frequency is 1 5 0 002 100Hz EEE516J4 Honours Project Page 141 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord J Scope x File Edt ev Toos Window Help mar HL oRARiSEeEFEe ERE v A SG Time SS00000 000 255850050 F HHE HE zo mmm ET Con fivon 2 on el ee l CH3 E Figure 11 3 2 3b Screen dump of scope program sample rate 5000Hz input wave 100Hz sinewave 0 5V 200Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3c 2 5 divisions per cycle hence the calculated frequency is 1 2 5 0 002 200Hz File Edt Yew Toob Window Help J Beane i ere v CHI 5v0 Y Gre fi CH3 fi E Figure 11 3 2 3c Screen dump of scope program sample rate 5000Hz input wave 200Hz sinewave 0 5V 300Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3d 1 7 divisions per cycle hence the calculated frequency is 1 1 7 0 002 294 1Hz EEE516J4 Honours Project Page 142 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Figure 11 3 2 3d Screen dump of scope program sample rate 5000HZz input wave 3
56. WRITE 0 exclusive access NULL no security OPEN EXISTING 07 no overlapped I O NULL null template Check the returned handle for INVALID HANDLE VALUE and then set the buffer sizes m_bPortReady SetupComm m_hCom 1000 1000 set buffer sizes m bPortReady GetCommState m_hCom amp m_dcb m_dcb BaudRate baud m_dcb ByteSize byte m_dcb Parity parity m_dcb StopBits ONESTOPBIT m bPortReady SetCommState m_hCom amp m_dcb m_bPortReady GetCommTimeouts m_hCom amp m_CommTimeouts m_CommTimeouts ReadIntervalTimeout 3 m_CommTimeouts ReadTotalTimeoutConstant 3 m_CommTimeouts ReadTotalTimeoutMultiplier m_CommTimeouts WriteTotalTimeoutConstant 1 m_CommTimeouts WriteTotalTimeoutMultiplier 3 0 10 m_bPortReady SetCommTimeouts m_hCom amp m_CommTimeouts This function is used to read one character from the RS232 serial port bool CMainFrame readchr unsigned char c EEE516J4 Honours Project Page 61 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord unsigned char Buffer 128 unsigned long a 0 bReadRC ReadFile m_hCom amp Buffer 1 amp a NULL if a 0 return false No char received else kc Buffer 0 return true This function is used to transmit one character to the RS232 serial port void CMainFrame trans char c char buffer 2 buffer 0 c bWriteRC
57. _ms 5000 5 Sec delay printf TEST RAM CHIP RAM Test 1 write OxFF into all locations and check printf n nTest 1 Fill RAM with OxFF gt pass 0 Reset Pass counter fail 0 Reset Fail counter for i1 0 1 lt 8192 i Write OxFF to all locations WriteRAM i OxFF for i 0 i1 lt 8192 i if ReadRAM i OxFF pass else fail printf Passes Slu Fails lu pass fail RAM Test 2 write 0x00 into all locations and check printf n nTest 2 Fill RAM with 0x00 gt pass 0 Reset Pass counter fail 0 Reset Fail counter for i1 0 1 lt 8192 i Write 0x00 to all locations WriteRAM i 0x00 for i 0 i1 lt 8192 i if ReadRAM i 0x00 pass else fail printf Passes Slu Fails lu pass fail RAM Test 3 write LSB of address into all locations and check printf n nTest 3 Fill RAM with LSB of Address gt pass 0 Reset Pass counter fail 0 Reset Fail counter for i1 0 1 lt 8192 i Write LSB of address to all locations WriteRAM i char i for 1 0 1 lt 8192 i if ReadRAM i char i pass else fail printf Passes Slu Fails lu pass fail printf n nEnd of RAMTEST Hopefully work can now start on storage mode n n sleep EEE516J4 Honours Project Page 110 Chapter 10 PIC Software Development Friday 21 June 200
58. alphabetically u foe ACK ADC ASM BMP bps BRG C C C CCS CISC CPU CRC CRT DDB DIB DOS F fcuT_oFF FERR fstop GIF GND GUI Hz O IC JPEG k LCD MB Percentage Micro 1 x 10 Infinity Acknowledgement Analogue to Digital Converter Assembly level programming Bitmap Bits per second also known as the baud rate Baud Rate Generator Capacitor High level programming language Object originated programming language C compiler Complex Instruction Set Computer Central Processing Unit Cyclical Redundancy Check Cathode Ray Tube Device Dependent Bitmap Device Independent Bitmap Disk Operating System Farads High frequency cut off Framing Error Start of filter stop band Graphical Interchange Format Ground Graphical User Interface i e Microsoft Windows hertz Input Output Integrated Circuit Joint Photographic Experts Group Kilo 1 x 10 Liquid crystal Display Milli 1 x 10 Filter Order Mega 1 x 10 Megabytes EEE516J4 Honours Project Page Ill Colin K McCord Notation Friday 21 June 2002 Final Report MS Microsoft NAK Negative Acknowledgment OERR Overflow Error p Pico 1 x 10 PC IBM compatible personal computer PIC Peripheral Interface Controller R Resistor RAM Random Access Memory RCSTA Receive Status and Control Register RISC Reduced Instruction Set Computer ROM Read Only Memory RS232 Standard 9 pin PC serial port RX Receive
59. an extremely good clean connection will fail if one character has been corrupted 7 Change Baud Rate Baud Rate Current 009600 bps 115200 bps bi 57600 bps hi 38400 bps hi 19200 bps hi 14400 bps hi 9600 bps hi 4800 bps hi 2400 bps hi 1200 bps hi No Change DOWMAATNAURWNEH Pt te EE ED ee CE TE Ee OLEY hi User can change the baud rate by hitting the appropriate key 8 About Final Year Project EEE516J4 University of Ulster BEng hons Electronic Systems Date 22 02 2002 Revision 1 05 By Colin K McCord Information about the program and the author ct Page 92 EEE516J4 Honours Proje Chapter 9 Test Program Friday 21 June 2002 Final Report 9 2 How is RS232 Communications Achieved Setup UART constants and RS232 buffer Colin K McCord define COM 0x3f8 COM1 0x3 8 COM2 0x2f8 define RBR 0 Receive Buffer Register define THR 0 Transmit Holding Reg y define DLL 0 Divisor Latch LSB define DLM 1 Divisor Latch MSB ag define IER 1 Interrupt Enable Reg define IIR 2 Interrupt ID Register xj define FCR 2 define AFR 2 define LCR 3 Line Control Register xi define MCR 4 Modem Control Register define LSR 5 Line Status Register define MSR 6 Modem Status Register define SCR 7 The Scratch Register K def
60. apparent signal which does not actually exist usually caused by under sampling Many samples should be taken per cycle at least 10 for pulse interpolation to ensure an accurate representation of an analogue signal in a digital memory If only one sample is taken per cycle or one sample per several cycles then aliasing occurs For example say a waveform is being sampled every three cycles these samples may form together particularly when using pulse interpolation to look like a valid waveform S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 Figure 3 4a Demonstrating aliasing red is the real waveform while blue is an alias Figure 3 4a clearly demonstrates how false signals aliasing can be displayed on a digital scope The red waveform is the waveform being monitored notice that the waveform is under sampled see green arrows for sample points The black dots shows were the input waveform red has been sampled by joining the dots it is clear that a perfect sine wave is created blue which is an alias of the original signal Note that it is impossible to tell that the blue signal is an alias unless the scope has analogue and digital capabilities were a user can switch to analogue mode to check that the waveform is not an alias There is nothing that can be done after sampling to correct aliasing hence the solution is to filter out high frequencies by sending the input signal through a low pass filter Ideally all frequencies above half the sample
61. as this is used in the calculation of the time C Real Time Scroll base else the time base selected in the Disp tab will be incorrect G Real Time Buffered f i f Co SE AR E Note the input range is selected here it was expected that this information is sent to the PIC to adjust the gain of the op amps but this has not been implement yet Allow it is important that the correct Input 25t0 25V input range is selected as this changes the binary representation of voltage e g for a range of 2 5 to 2 5V OV 2 5 512 OV 1024 2 5V and for a range of 5 to 5V 5V 0 OV 512 5V 1024 Sampling mode is also selected here Real time scroll mode means Figure 7 0i Sample Tab of controls dialog that the waveform is sampled using the real time mode but stored onto the internal channel arrays in such away that the waveform appears to scroll across the screen low frequencies only e g useful for ECG monitor Real time buffered mode means that data is buffered before copying to the internal channels arrays and is triggered so that the waveform appears to be stable on the display e g useful for periodical waveforms Storage mode has not been implemented yet recall that the PIC samples to RAM and then transmits the data to the PC in one large block with added CRC The grid configuration dialog box is shown in figure 7 0j X specifies the number of horizontal squares 1 to 99 Y specifies the number of vertical squares 1
62. bit parallel latch to hold the selected range while the PIC is using these lines for use with the RAM chip The simplest way of producing different analogue ranges is to have a number of different inputs for example each analogue block has 3 inputs 1 to 1V 10 to 10V and 250 to 250V Another simple solution is to use a manual three to one way switch to select the appropriate range It is clear that a 8kByte RAM chip see figure 5 1a is used this RAM chip is used during storage mode operation A finite number of samples are stored into the RAM chip and transmitted to the PC in one large block hence removing the RS232 bottleneck faster sample rates possible Notice that there are 8 data lines which are connected to port B and 13 address lines connected which are connected to port C and port D Recall that 2 bytes are required per reading hence 4000 readings can be stored that s 1000 for each channel Notice that there is one control line this puts the RAM chip in read or write mode but if the data lines are shared with another component sometime in the future there is the need for another control line to disable the RAM chip It is possible to use four PICs one for each channel hence each channel can be sampled simultaneously using a master slave communication protocol For example each PIC has its own address say 1 to 4 all four wait until the master PC calls them before transmitting there data Note the current communication prot
63. c uses the ADCs internal oscillator not good and this could explain why the waveform was continuously changing slightly e g noise form PIC oscillator It was discovered that it is possible for the scope program to display perfect sine waves at false time based readings when the waveform is under sampled This is a common problem which all digital scopes have called aliasing frequency above half the sample frequency should be filter out Note it may be possible to use this as an advantage as it makes it possible to monitor waveforms much higher than the sampling rate improving the performance of the PC based scope program if the real frequency could be detected 11 2 Test Session 2 FG Wilson Lab 05 03 2002 The circuit diagram shown in figure 11 2a was constructed on prototype board with RS232 communication connected to laptop COM1 1GHz AMD processor 256MHz SDRAM 8MB 3D accelerator card running windows XP VCC morRvpPTHV RB7 PGD L f Thi e CH1 __ IRao ANo RB6 PGC cs c vec 3 IRat ant RBS aan RA2 JAN2 VREF RB4 5 36 i 1 vec 2 DIP SW R Fe ee RB3 PGM apur C1 ssvtostov V tk Jik fik RasTocKi RB25 Sot ouis m UURAS ANA SS rei m s IREO RD ANS RBO INT ape C2 ovo YHE m 9 RE1 WR AN6 vad I5 Hez ee iF i i 10 IRE2 CS AN7 vsi h 1 L ak va RD
64. calling the main program If a certain block of characters are received during bootstrap it moves into program mode using a bidirectional communications protocol RTS ACK NAG EEE516J4 Honours Project Page 152 Chapter 13 Recommendations For Further Work Friday 21 June 2002 Final Report Colin K McCord etc a new program can be download from the PC directly into program memory when download is complete the new program is called This offers greater product flexible as software updates bug fixes new features can be downloaded free of charge and download directly into the product using the same serial interface and software used to display the waveforms i e the scope program Microchip application note J6 will fully describe how to implement this including full source code 13 6 Virtual Channels It is recommended that the scope program should have up to four user configurable virtual channels that s a total of 8 channels Each virtual channel can be configured as follows CH1 CH2 or CH1 x CH2 or CH1 CH2 or CH1 CH2 etc This makes the scope program more versatile increasing its usefulness for example monitoring of RS485 RS422 serial communication is now possible RS485 RS422 works on the principal of differential voltages between two cables twisted together good noise immunity hence two oscilloscope channels four for RS422 could be used and the scope program will automatically add the traces together creat
65. case 8 baud 0x30 break case 9 baud 0x60 break default clrscr return set speed outportb COM LCR inportb COM LCR 0x80 outporthb COM DLM baud gt gt 8 outportb COM DLL baud amp 0xff outportb COM LCR inportb COM LCR amp Ox7f rate 115200 baud if baud 1 printf n nBaud Rate Changed to u bps rate else printf n nBaud Rate Changed to 115200 bps rate clrscr Colin K McCord The source code is reasonable readably lots of comments and partitioned into many functions hence if the reader of this report wises to find out how any other aspect of the program works see appendix for the complete source code EEE516J4 Honours Project Page 95 Chapter 9 Test Program Friday 21 June 2002 Final Report Colin K McCord 10 0 PIC SOFTWARE DEVELOPMENT The philosophy used during the development of the PIC code was to keep it simple straightforward comprehensible and to a minimum There are many small programs designed for testing the hardware and ideas each program is labelled mark 1 2 3 etc The end result is that the PIC code is gradually built up step by step instead of writing the entire program at once This ensures that operational results are obtained as testing producers are carried out at each stage while if the program was written all at once there is little chance it will work and could prove difficult to debug The high level prog
66. case 1 set_uart_speed 9600 break case 2 set_uart_speed 14400 break case 3 set_uart_speed 19200 break case 4 set_uart_speed 32768 break case 5 set_uart_speed 38400 break case 6 set_uart_speed 57600 break case 7 set_uart_speed 115200 break 10 6 Mark 6 c Real Time Mode 1 Channel Fixed Delay Adjustable Baud Rate Same as mark3 c with the addition of function SetBaudRate this function sets the UART baud rate based on the positions of the DIP switches that are connected to port E This program is used to test the real time communications protocol and scope program at different baud rates EEE516J4 Honours Project Page 100 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord Mark 6 c source code Je ease Sessa esata as eas Sass ass SSeS sees see esas eee FILE mark 6 c PROJECT Low Cost PC Based Oscilloscope DESC Read CH1 ADC transmit result through RS232 using the real time frame format Baud rate set by dip switches SSS SS DATE 01 03 2002 BY Colin K McCord VERSION Ld include lt 16F877 h gt device PIC16F877 16 ADC 10 use device adc 10 to implement a 10 bit conversion otherwise the default is 8 bits fuses HS NOWDT NOPROTECT NOLVP byte PORTE 0x09 PortE lives in File 9 a Note 20MHz clock must be used for 115 000 bps use delay clock 20000000 use rs232 baud 9600 xmit the err
67. chl_b2 EEE516J4 Honours Project Page 89 Chapter 8 The Simulator Program Friday 21 June 2002 Final Report Colin K McCord 9 0 TEST PROGRAM Test exe is a MS DOS based application designed to test the digital hardware using RS232 it has many features and has a user friendly interface allow some of the test procedures are low level designed for use by an engineer and not the average person Full source code is found in appendix 2 Note allow this is a DOS program it will run under Windows even though Windows NT 2000 XP do not allow direct access to the hardware e g RS232 it will simulate the operation of the RS232 UART allowing DOS based programs to access the serial port as long as another program is not already using the required port 9 1 User Manual Main menu user has 9 options just hit the key corresponding to the required function PC Based Oscilloscope Test Program RX Terminal e Ape TX Terminal chat 2 Manual RTU frame with CRC hit 3 Manual RTU frame no CRC hast lt 4 Simulated Random Noise ALC cS Loop back test st shit 6 Change Baud Rate hit 7 About hit 8 Quit hat Q 1 RX Terminal RX Terminal Waiting for message press a key to stop Simple RX Terminal basically every character that is received from COM 1 is printed on the screen using the ASICII format Note some non alphanumerical characters have special functions e g Back
68. converter in Hertz 500 Hz Portions of the input signal that reside in the frequency domain above fs 2 will fold back into the bandwidth of interest with it s amplitude preserved causing aliasing e g 20000 ANTI ALIASING Wizard 4 MicrocHe FilterLab The calculated IDEAL Signal to Noise ratio for this A D converter is shown You 62 dB may decrease this value if desired or click NEXT to continue Decreasing this A value will lessen the order required idesi SNR 6 02 n 1 78 c 1899 Microchip Technology linc es eama ANTI ALIASING Wizard Colin K McCord b microchip FilterLab Whatis the bandwidth of interest for this low pass filter The closed loop bandwidth of your amplifier must be at least 10x higher than the filter cutoft frequency Enter the cutoff frequency in Hertz 2500 Hz c 1999 Microchip Technology Inc Next gt gt Cancel Figure 3 4 3b Step 2 Enter 3dB Cut off frequency 4 Microchip FilterLab Enter the number of bits of your A D converter n c 1833 Microchip Technology inc Next gt gt Cancel Figure 3 4 3d Step 4 Enter ADC resolution ANTI ALIASING Wizard microchip FilterLab This is the MINIMUM order required to antelias for these specifications The attenuation atthe stop band is also shown Ifyou are satisfied with one of these filters select one and FilterLab
69. f EEEH se ee a Chapter 3 Fundamentals 25 samples cycle 10 samples cycle Page 7 5 samples cycle Figure 3 3a Comparison of Dot Pulse Interpolator and Sine Interpolator displays at different sample rates s samples cycle EEE516J4 Honours Project Friday 21 June 2002 Final Report Colin K McCord Nyquist theorem states that to define a sine wave a sampling system must take more than two samples per cycle Notice that the sine interpolator display type 2 5 samples cycle approaches the limits that the sampling theory suggests Exactly two samples per cycle known as the Nyquist rate suffice if it is guaranteed that they coincide with the peaks of the waveform Otherwise there would be no knowledge of amplitude and if samples happened at zero crossings the waveform wouldn t even be detected However more than two samples per cycle would be fine as the position of the samples relative to the sine wave will gradually drift through all possible phases so that the peak amplitude will be accurately defined For none sinusoidal waveforms a sine interpolator is inappropriate except in the case of certain instruments which can suitably pre process the waveform before passing it to the sine interpolator 3 4 Aliasing Aliasing is an undesirable effect that can occur in digital sampling oscilloscopes which is not found in traditional analogue oscilloscopes This is the display of an
70. inserting serial cards why not use both serial ports to receive the data Obviously the PIC only has one hardware UART hence the solution is to use the hardware UART plus a software UART CSS C compiler automatically generates the code when non hardware PINs are selected which is reconfigurable throughout the program Two bytes are sent 10 bit ADC for each channel hence put the first byte on COM1 and the second on COM2 this will double the maximum sampling rate Note the MAX232CPE chip is a dual RS232 line driver chip hence no extra hardware is required allow the additional software UART will push the PIC to the limits should be OK at 20MHz N x Baud Rate 20 Serial Links Sample Rate Multipliable Serial Links No of Channels Number of Max Sample Rate Max Sample rate Max Sample Rate at Channels at 230 Kbps 2 serial at 115 Kbps 2 serial 67 2 Kbps 2 serial links at 115 Kbps links at 56 6 Kbps links at 33 6 Kbps 1 11 5 KHz 5 75 KHz 3 36 KHz 2 5 75 KHz 2 87 KHz 1 68 KHz 3 3 83 KHz 1 91 KHz 1 12 KHz 4 2 88 KHz 1 43 KHz 840 Hz Figure 6 5c Table showing the theoretical real time sample rates chop 10 bit ADC dual RS232 cable For faster sample rates storage mode must be used for example the PIC samples a waveform at 20 KHz storing each reading into an array e g external RAM chip Then once a certain number of samples have been taken say 200 the PIC stops sampling and sends
71. interrupt or PIC must check UART buffer regularly must be setup in the PIC to let it know that there is a control message waiting to be read 6 1 Real Time Mode Reads one sample at a time sending each reading directly to the PC using RS232 note there is a delay real time clock between readings which is specified by the PC using the control protocol Read Transmit Delay Channel1 Reading ADC RS232 Figure 6 1a Illustration of real time mode with one channel From figure 6 1b it is clear that timing is a big problem as there are time delays for reading each analogue channel and transmitting the data This problem is worse at high sample frequencies and one solution is to work around the problem and try to software offset the waveforms to compensate for these time delays Another option is to use four PICs hence sampling can occur simultaneously and use a master slave communication protocol with some why of synchronising all the PICs PIC microcontrollers are so cheap that this is a real option and was considered multiple PICs in designs are widely used unlike microprocessor design were it is usually expected that one microprocessor will control everything e g PC although there are lots of MPUs in a modern PC besides the Pentium Read Transmit CH1 Read Transmit CH2 Delay m Channel1 _ Reading Channel2 Reading
72. mode Baud rate set by dip switches EEE516J4 Honours Project Page 106 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord DATE 20 03 2002 BY Colin K McCord VERSION 1 5 include lt 16F877 h gt device PIC16F877 16 ADC 10 use device adc 10 to implement a 10 bit conversion otherwise the default is 8 bits fuses HS NOWDT NOPROTECT NOLVP NOBROWNOUT byte PORTE 0x09 PortE lives in File 9 Note 20MHz clock must be used for 115 000 bps the error is to large at slower speeds use delay clock 20000000 use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 use fast_io E Fast access to PortE don t fiddle with TRISE long int TimeBase long int TimeBaseMUX char bSample Forward declaration of functions void SetBaudRate void Sample RealTime TimeBase Interrupt called every 20uS that s 50KHz MAX INT_TIMER2 Timer2 ISR Sample Frequency TimeBaseMUX 20uS e g 100Hz 1mS 20uS 500 if TimeBase 0 TimeBase TimeBaseMUX bSample TRUE main bSample FALSE set_tris_e 0x17 TRISE 00010111 RE2 RE1 and REO TTL Inputs SetBaudRate setup_adc_ports A_ANALOG RAO RA4 Analog REO RE2 digital setup adc ADC CLOCK DIV 32 set_adc_channel 0 delay_us 20 Delay for sampling cap to charge Setup Time Base timer2 1 20 000 0
73. on a large projector display Because of the low cost of the PC based oscilloscope it is economical for a school technical college to have large quantities available for students Unlike traditional analogue scopes which are expensive and students are forced to share equipment because it is not economical to purchase enough scopes for every student EEE516J4 Honours Project Page 3 Chapter 1 Project Background Friday 21 June 2002 Final Report Colin K McCord 2 0 DESIGN SPECIFICATIONS 2 1 Core Objectives 1 Design and construct the hardware required for data acquisition including analogue circuit design for insuring input voltage falls between 0 and 5V ADC min and max range Pick a transport medium for relaying data to the PC USB RS232 parallel or PCI and discuss the advantages disadvantages and the reasons why it was picked Design and construct the hardware required e g MAX232 etc to interface the PIC microcontroller with the chosen medium Design a communication protocol for relaying data from the PIC to the PC in real time perhaps including a check sum or CRC Discuss the advantages and disadvantages of using a check sum or CRC in this real time mode Design a Windows based C application capable of displaying low frequency waveforms up to 4 channels simultaneously lt 5 KHz in real time i e the graphic subsystem This application should directly communicate with the PIC using the chosen transport me
74. penCHl new CPen penCH1l gt CreatePen PS SOLID 2 LIGHTRED penCH2 new CPen penCH2 gt CreatePen PS SOLID 2 LIGHTGREEN penCH3 new CPen penCH3 gt CreatePen PS SOLID 2 LIGHTBLUE penCH4 new CPen penCH4 gt CreatePen PS SOLID 2 YELLOW m_ColorGridBackGround BLACK OnDrawGrid This function is called when a channel voltage scale combo box is changed void CControlsP2 OnChange CString temp Setup Channel 1 Volts per Dev GetDlgItemText IDC_CH1 VOLT temp if temp _T 10mV DIV pDoc gt m_nCH1 VOLTS 1 if temp _T 20mV DIV pDoc gt m_nCH1_ VOLTS 2 if temp _T 50mV DIV pDoc gt m_nCH1l VOLTS 5 if temp _T 1V DIV pDoc gt m_nCH1_VOLTS 10 if temp _T 2V DIV pDoc gt m_nCH1_VOLTS 20 if temp _T 5V DIV pDoc gt m_nCH1_ VOLTS 50 if temp _T 1V DIV pDoc gt m_nCH1_ VOLTS 100 if temp _T 2V DIV pDoc gt m_nCH1_ VOLTS 200 if temp _T 5V DIV pDoc gt m_nCH1 VOLTS 500 if temp _T 10V DIV pDoc gt m_nCH1 VOLTS 1000 if temp _T 20V DIV pDoc gt m_nCH1_VOLTS 2000 EEE516J4 Honours Project Page 55 Chapter 7 The Scope Program Friday 21 June 2002 Final Report if temp _T 50V DIV pDoc gt m_nCH1 VOLTS 5000 Channel 2 4 done in exactly the same way as channel 1 Colin K McCord This function prepares the traces
75. rate should be filtered out but circuit design can become difficult if the sampling rate is adjustable because the high frequency cut off must also be adjustable One solution is to used digital potentiometers resistance controlled by microcontroller to change the high frequency cut off of the filter EEE516J4 Honours Project Page 8 Chapter 3 Fundamentals Friday 21 June 2002 Final Report Colin K McCord 3 4 1 Typical Low Pass Filter Design Parameters There are four key parameters that specify an low pass filter as shown in figure 3 4 1a fcut orr fstop AMAx and M The cut off frequency fcut orr of a CUT OFF low pass filter is normally defined as the 3dB point e g Butterworth and Bessel filter or the frequency at which the filter response leaves the error band e g Chebyshev M Filter Order e i Apass Butterworth or Bessel filters do not create ripple in the pass band i e flat unlike the Chebyshev filter The Chebyshev filter has a ripple up to the cut off frequency defined as Gain dB A STOP By definition a low pass filter ES el P passes lower frequencies up to the rer Bang 2top pang cut off frequency and attenuates the higher frequencies that are above the cut off frequency J4 a Transition Band Frequency Hz Figure 3 4 1a The key low pass filter design parameters The filter order is determined by the number of poles in the transfer function e
76. the CRC register 2 Exclusive OR the first 8 bit bytes of the message with the low order byte of the 16 bit CRC register putting the result in the CRC register 3 Shift the CRC register one bit to the right Zero filling the MSB Extract and examine the LSB 4 Ifthe LSB was0 Do nothing proceed to step 5 If the LSB was 1 EXOR the CRC register with the polynomial value 0xA001 5 Repeat steps 3 and 4 until 8 shifts have been performed When this is done a complete 8 bit byte will have been processed 6 Repeat steps 2 through 5 for the next 8 bit byte of the message Continue doing this until all the bytes have been processed 7 The final content of the CRC register is the CRC value 8 Swap low amp high bytes of CRC Return CRC C code for producing CRC pure calculation no lookup table PC Code unsigned short CRC16 unsigned char message unsigned short data_length unsigned short CRC OxFFFF CRC initialised with all l s i Loop Control temp Temp for swap while data_length Loop until all bytes calculated CRC CRC messaget t for i 0 i lt 8 Shift all 8 bits if CRC amp 0x0001 CRC CRC gt gt 1 0xA001 else CRC gt gt 1 temp CRC amp OxFF Temp storage for swap CRC CRC gt gt 8 amp 0xFF temp lt lt 8 Swap high and low byte return CRC Return calculated 16 bit CRC C code for producing CRC using lookup table
77. the heater is activated by applying a voltage across it the cathode temperature rises and it then emits a stream of electrons B2 2000V 1500V 100V 100V 100V 10kV Correction electrodes ASTIG Cathode etc PDA connector u 19S payeoo soydsoud Heater Focus electrodes Figure 1 0c Diagram of a typical Cathode ray tube CRT construction This project attempts to achieve the same functionality as a traditional oscilloscope using a PIC microcontroller for data acquisition including appropriate analogue circuitry which transfers the data to the PC possibly via RS232 USB or Parallel A Microsoft Windows based software application will then display the waveform as it would appear on a traditional CRT oscilloscope This software application will have additional features not present on a traditional oscilloscope e g printing saving waveforms with greater flexibly as additional features can be added as their developed without the need for new hardware EEE516J4 Honours Project Page 1 Chapter 1 Project Background Friday 21 June 2002 Final Report Colin K McCord The digital based oscilloscope should display very low frequency waveforms in real time but for higher frequency waveforms it is necessary to read a finite number of samples storing them into RAM Once the memory is full or the preset number of samples has been reached the PIC will stop sampling and transfer the data to the PC when
78. to 99 Note each square has 10 points hence a maximum resolution of 999 by 999 is possible assuming Window s desktop resolution is larger than this The default grid resolution is 10 x 8 100 x 80 but 20 x 16 200 x 160 is probably better suited for quad channel operation Note the higher the grid resolution the more processor hungry the scope program becomes hence extremely high resolutions are only recommend for high speed modern computers e g 500MHz or above EEE516J4 Honours Project Page 46 Chapter 7 The Scope Program Friday 21 June 2002 Grid Configuration x Grid Area Refresh Rate x 20 200 mSec Vf 16 Buffer Size 801 Reduce for slow sample rates and increase for high V Auto sample rates Restore Defaults BK Color Save Defaults Figure 7 0j Grid configuration dialog box Final Report Colin K McCord The refresh rate specifies the time in milliseconds between screen refreshes For example 200 milliseconds is the default that s a refresh rate of 1 0 2 5 Hz Some traditional analogue engineers who are use working with CRT displays will think that this refresh rate is too low and will result in the screen flickering This is not the case unlike CRT displays the screen holds the current display contains between refreshes and only redraws the changes made to the waveform when the screen is refreshed perhaps this should have been called the update rate rather than the refresh rate The actual r
79. void CScopeView OnDrawGrid a a EY ee a S A E a E E a a a Fuction void CScopeView OnDrawGrid Description Draws grid in memory then updates display Return Void Date 09 12 2001 Verison 1 4 By Colin McCord ee ee ne ee ed int nL CClientDC dc this CBitmap m bitmapGrid m_bitmapOldGrid NULL if we don t have one yet set up a memory dc for the grid if m dcGrid GetSafeHdc NULL m_dcGrid CreateCompatibleDC amp dc m_bitmapGrid CreateCompatibleBitmap amp dc m_nClientWidth m_nClientHeight m_bitmapOldGrid m_dcGrid SelectObject amp m_bitmapGrid m_bitmapOldGrid gt DeleteObject Make sure there is not a memory leak If the pen is not setup do not continue if penGrid NULL return Select the grid pen for use with the DC CPen pOldPen m_dcGrid SelectObject penGrid CBrush Brush Brush CreateSolidBrush m_ColorGridBackGround Grid Back Colour EEE516J4 Honours Project Page 51 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord m_dcGrid FillRect amp m_ClientRect amp Brush Draw Border m_dcGrid MoveTo m_ nGridx 0 m_nGridy 0 m_dcGrid LineTo m_nGridX x m_nGridy 0 m_dcGrid LineTo m_nGridX x m_nGridY y m_dcGrid LineTo m_nGridx 0 m_nGridY y m_dcGrid LineTo m_nGridx 0 m_nGridy 0 Draw V Gray Lines for n 10 n lt x n n 10 for i m_nGridY 0 i lt m_n
80. was not the original plan as a slower clock speed would reduce power consumption critical if using battery power supply and less noise would have been generate hence ADC readings would be more accurate allow it is possible to put the PIC to sleep while taking the ADC reading the ADC will send an interrupt waking the PIC once the acquisition is complete This is not an option for this application because it takes a long time for the PICs oscillator to return to full speed after a sleep operation hence this would severely affect the maximum sampling rate EEE516J4 Honours Project Page 21 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord The main reason for using a 20MHz clock was because at slower clock speeds it was not possible to obtain a good 115kbps baud rate Officially the maximum allowable baud rate error is 3 allow most PC UARTs are specified to operate correctly with a baud rate variation of 5 before many errors start to occur The C compiler CCS V2 7 used to write the PIC program generates an error if the specified baud rate cannot be achieved within 3 of the desired value using the current clock rate The reason why 115kbps is important is because the RS232 serial communication is the bottleneck when operating in real time mode hence it makes sense to use the maximum baud rate possible Note the PIC is capable at 20MHz of generating baud rates higher than 115kbps but most PCs have a maximum ba
81. will now build it for you Results le Order Amax Build Sampling Freq 5000 Ppp a He Buterworh n a ae 4 30 aB e 8 Chebyshev 3 a 4 0 aB c Edge Freq 2500 He Finished Cancel c 883 Microchip Technology inc Figure 3 4 3e Step 5 IDEAL signal to noise ratio is calculated Figure 3 4 3f Step 6 Click build Butterworth then Finish Notice that the anti aliasing wizard gives the user the choice to generate a Butterworth or Chebyshev solution Note that the Chebyshev solution figure 3 4 3f has a 3dB base band ripple while the Butterworth has no base band ripple The anti aliasing wizard generates the circuit diagram required to filter out the high frequencies that will cause aliasing based on the user configurable parameters see figure 3 4 39 EEE516J4 Honours Project Page 11 Chapter 3 Fundamentals Friday 21 June 2002 Final Report Colin K McCord 7 FilterLab a shel xi Fle Options Hep aj aama Ferr Ae Oe fw o Order Cut off Frequency Ripple Gain Circuit Options To edit the component values click on a capacitor value in Capacitor List Hel the circuit above You may then select a new value from the This circuit was designed using the antialiasing wizard list or enter an exact value Resistor values are calculated based on the capacitors that are chosen FilterLab will wam you if a value is not within an allowable range All calculations are based on the approximation method filter order and
82. wires data and clock Master Slave There are lots of cheap I C chips available typically lt 100kbps UART Universal Asynchronous Receiver Transmitter with baud rates of 300bps to 115kbps 8 or 9 bits parity start and stop bits etc Outputs 5V hence an RS232 level converter e g MAX232 is required Timers both 8 and 16 bits many have prescalers and some have postscalers In 14 bit cores they generate interrupts External pins clock in clock out can be used for counting events Ports have two control registers TRIS sets whether each pin is an input or an output and PORT sets their output bit levels Note Other peripherals may steal pins so in this respect peripheral registers control ports as well Most pints have 25mA source sink LED enabled but not all pins it is important to look up the datasheet Floating input pints must be tied off or set to outputs ADCs Analogue to Digital Converter are currently slow less than 54 KHz sampling rate 8 10 or 12 bits theoretically higher accuracy when PIC is in sleep mode less digital noise once the sample is complete the ADC sends an interrupt waking the PIC Note that the PIC must wait until the sampling capacitor is charged see datasheets 3 6 RS232 Serial Interface RS232 is simple universal well understood and supported but it has some serious shortcomings as a data interface Its origins predate modern computers and it contains many features that are not relevant
83. 00 4 1 100 1 20uS setup timer 2 T2 DIV BY 1 100 1 interrupt every 20us that s 50Khz max set_timer2 0 enable interrupts INT _TIMER2 TimeBaseMUX 50 1000 Hz TimeBase TimeBaseMUX e g 50000 100 for 100 Hz thats 500 20us 10mS enable interrupts GLOBAL while TRUE if bSample TRUE bSample FALSE Sample RealTime EEE516J4 Honours Project Page 107 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord void Sample RealTime 20 03 2002 verision 1 0 sample chl to ch4 Chop Mode NOTE by default in CCS all var s are unsigned long int adcValue 16 bit storage for ADC reading char adcHI adcLO 8 bit storage for real time frames Channel 1 adcValue read_adc Get ADC reading Convert 16 bit adcValue to Real time frame structure CH1 adcHI char adcValue gt gt 5 amp Oxlf 01 01 01d9 d81da7 d6 da5 adcLO char adcValue amp 0x1f 0x80 110 0 d4 d3 d2 d11 d0 putc adcHI Transmit Byte 1 d9 d5 putc adcLO Transmit Byte 2 d4 d0 Channel 2 set_adc_channel 1 delay_us 20 Delay for sampling cap to charge adcValue read_adc Get ADC reading Convert 16 bit adcValue to Real time frame structure CH2 adcHI char adcValue gt gt 5 amp Ox1lf 0x20 01 0111a9 d81da7 d6 d5 adcLO char adcValue amp 0x1f
84. 002 Final Report Colin K McCord Channel 1 connected to 10Hz sine wave 5Vpp channel 2 connected to 100Hz sine wave 4Vpp see figure 11 3 2 1h Channel 1 unaffected Channel 2 2 divisions per cycle hence the calculated frequency is 1 1 0 01 100 Hz Channel 1 connected to 10Hz sine wave 5Vpp channel 2 connected to 550Hz sine wave 4Vpp see figure 11 3 2 1i Channel 1 unaffected Channel 2 Under sampled aliasing has occurred gt Scope Scopel E 5 x File Edt View _Toos Window Hep B Pegoulet Ese Sample Disp Trig Time Base M CHI jivioVv v IV oHa svioV w CH3 p Figure 11 3 2 1i Screen dump of scope program sample rate 1 kHz CH1 10Hz sinewave CH2 550Hz sinewave Scope Scopel E 6 x Fie Edt View Toos Window Help Mi CGO s amp ihe asf eae Sample Disp Trg Time Base CHT iviolv a M CH2 sv DY f CH3 HHHH oo AU Ready Figure 11 3 2 1j Screen dump of scope program sample rate 1 kHz CH1 square wave CH2 trianglewave EEE516J4 Honours Project Page 139 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Note all of the experiments in this section were carried using independent triggering mode because it was difficult to get two stable traces when triggering off one channel e g if triggering on CH1 CH2 is unstable and if triggering on CH2 CH1 was unstable This problem should be software fixable
85. 00Hz sinewave 0 5V 400Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3e 1 3 divisions per cycle hence the calculated frequency is 1 1 3 0 002 384 6Hz Scope Scopel _ 10 x File Edit View Tools Window Help CAE EI A RU4G4 3 8 amp IV CHI liv DIV CH2 I CH3 fiviov v Co ow 2 Figure 11 3 2 3e Screen dump of scope program sample rate 5000Hz input wave 400Hz sinewave 0 5V 500Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3f 1 divisions per cycle hence the calculated frequency is 1 1 0 002 500HzZ Cre fi ha CH3 Vov v Ready Figure 11 3 2 3f Screen dump of scope program sample rate 5000Hz input wave 500Hz sinewave 0 5V EEE516J4 Honours Project Page 143 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 750Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3g 0 7 divisions per cycle hence the calculated frequency is 1 0 7 0 002 714 2Hz 0 x Fle Edt Vew Toos Window Hep Peou BEE Sample Disp Trg ss Bees z M ei f1v DIv v cre fivjov x CH3 7 Ooo moa Figure 11 3 2 3g Screen dump of scope program sample rate 5000Hz input wave 750Hz sinewave 0 5V 1000Hz sinewave 0 5V connected to CH1 ANO see figure 11 3 2 3h 0 5 divisions per cycle hence the calculated frequency is 1 0 5 0 002 1000Hz but distorted due to under sampling Sample Disp Trig
86. 0xA0 1 0111d4 d3 d2 d1 d0 putc adcHI Transmit Byte 1 d9 d5 putc adcLO Transmit Byte 2 d4 d0 Channel 3 set_adc_channel 2 delay_us 20 Delay for sampling cap to charge adcValue read_adc Get ADC reading Convert 16 bit adcValue to Real time frame structure CH3 adcHI char adcValue gt gt 5 amp Oxlf 0x40 011101d9 d81da7 d6 d5 adcLO char adcValue amp 0x1f 0xC0 11110 d4 d3 d2 d1 d0 putc adcHI Transmit Byte 1 d9 d5 putc adcLO Transmit Byte 2 d4 d0 Channel 4 set_adc_channel 3 delay_us 20 Delay for sampling cap to charge adcValue read_adc Get ADC reading Convert 16 bit adcValue to Real time frame structure CH4 adcHI char adcValue gt gt 5 amp Oxlf 0x60 O11111d9 d81da7 d6 d5 adcLO char adcValue amp Oxl1f 0xEO 11111 d4 d3 d2 d1 do putc adcHI Transmit Byte 1 d9 d5 putc adcLO Transmit Byte 2 d4 d0 Back to Channel 1 set_adc_channel 0 delay_us 20 Delay for sampling cap to charge void SetBaudRate switch PORTE amp 0x07 Read dip switches and setup baud rate case 0 set_uart_ speed 4800 break case 1 set_uart_ speed 9600 break case 2 set_uart_speed 14400 break case 3 set_uart_speed 19200 break case 4 set_uart_speed 32768 break EEE516J4 Honours Project Page 108 Chapter 10 PIC Software Deve
87. 1 10 0 01 10Hz 0 x 218 x Sample jisp Trig Time Base t F F r f f f 3 f f f Ready Figure 11 2 3c Screen dump of scope program sample rate 1 000Hz input wave 10Hz sinewave 0 5V 20Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3d resolution 200 x 160 that s 20 x 16 divisions 5 division per cycle hence the calculated frequency of the waveform is 1 5 0 01 20Hz EEE516J4 Honours Project Page 122 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord i Sample Disp Trig i rea AEN Ba is Time Base V CHI 5v iDV cue fiv m ch Figure 11 2 3d Screen dump of scope program sample rate 1 000Hz input wave 20Hz sinewave 0 5V 50Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3e resolution 200 x 160 that s 20 x 16 divisions 2 division per cycle hence the calculated frequency of the waveform is 1 2 0 01 50Hz 10 x _ sll tego Jagi ha a sfea Sample Disp Trig Time Base Ready Figure 11 2 3e Screen dump of scope program sample rate 1 000Hz input wave 50Hz sinewave 0 5V 100Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3f resolution 100 x 80 that s 10 x 8 divisions 1 division per cycle hence the calculated frequency of the waveform is 1 1 0 01 100Hz EEE516J4 Honours Project Page 123
88. 1 Control Protocol Obviously the first thing that needs to be finished is the control protocol allowing for the scope program to directly control the sample rate enable disable channels real time storage mode chop or alternate etc Sufficient details have been included in this report on how this might be achieved 13 2 Storage Mode Sample a finite number of samples storing them into RAM Once the memory is full or the preset number of samples has been reached the PIC will stop sampling and transfer the data to the PC when ACK acknowledgement is received from the PC the PIC will start sampling again There is enough information contained in this report to implement this feature clearly the scope program and PIC software needs modification 13 3 Multiple Serial Ports The PIC only has one hardware UART hence one solution is to use the hardware UART plus a software UART CCS C complier makes this easy Two bytes are sent for per ADC reading hence put the first byte on COM1 and the second on COM2 this will double the maximum real time sampling rate 11 5 kHz max Note the MAX232CPE chip is a dual RS232 line driver chip hence no extra hardware is required allow the additional software UART will push the PIC to the limit should be OK at 20MHz If it turns out it is not practical to use a software UART an additional hardware UART chip could be used these chips are readily available and are reasonably priced 13 4 USB Transp
89. 2 BV DIV v Coo mo Figure 11 3 2 1b Screen dump of scope program sample rate 1 kHz CH1 25Hz sinewave CH2 30Hz sinewave EEE516J4 Honours Project Page 135 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Channel 1 connected to 25Hz sine wave 5Vpp channel 2 connected to 30Hz sine wave 4Vpp see figure 11 3 2 1b Channel 1 4 divisions per cycle hence the calculated frequency is 1 4 0 01 25Hz Channel 2 unaffected Channel 1 connected to 50Hz sine wave 5Vpp channel 2 connected to 30Hz sine wave 4Vpp see figure 11 3 2 1c Channel 1 2 divisions per cycle hence the calculated frequency is 1 2 0 01 50Hz Channel 2 unaffected Sample Disp Trg Time x Base Men fiviov Mone svov eH fiviov F va z Time Men fiviov Mone sviov gt Men fiviov F E a Figure 11 3 2 1d Screen dump of scope program sample rate 1 kHz CH1 100Hz sinewave CH2 30Hz sinewave EEE516J4 Honours Project Page 136 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Channel 1 connected to 100Hz sine wave 5Vpp channel 2 connected to 30Hz sine wave 4Vpp see figure 11 3 2 1d Channel 1 1 divisions per cycle hence the calculated frequency is 1 1 0 01 100Hz Channel 2 unaffected Channel 1 connected to 500Hz sine wave 5Vpp channel 2 connected to 30Hz sine wave 4Vpp see figure 11 3 2 1e Channel 1 Under sampled aliasing ha
90. 2 Final Report Colin K McCord void SetBaudRate Verison 1 1 22 3 2002 by CKM set_tris_e 0x17 TRISE 00010111 RE2 RE1 and REO Inputs Parallel slave mode is ON e g TTL Inputs on Port E and D switch PORTE amp 0x07 Read dip switches and setup baud rate case 0 set_uart_speed 4800 break case 1 set_uart_speed 9600 break case 2 set_uart_speed 14400 break case 3 set_uart_speed 19200 break case 4 set_uart_speed 32768 break case 5 set_uart_speed 38400 break case 6 set_uart_speed 57600 break case 7 set_uart_speed 115200 break set_tris_e 0x07 Turn OFF Parallel Slave Mode as this affects port D Address Bus void WriteRAM long int address char data 20 03 2002 version 1 0 by Colin McCord set_tris_b 0x00 TRISE 00000000 RBO to RB7 TTL Outputs data bus Set Address Don t Write until address and data bus is setup PORTD char address Set A7 A0 PORTC PORTB data delay cycles 1 delay cycles 1 RW 1 PORTC amp OxEO address gt gt 8 Set A12 A8 Put data on the data bus j 200nS delay same as NOP 1 20 000 000 4 1 200nS make sure address amp data is valid before write Write data to specified address 200nS delay same as NOP make sure write is finished Back to Read Mode char ReadRAM long int address 20 03 2002 version 1 0 by Colin McCord set_tris b O
91. 3 Pages 83 to 84 Pages 84 to 85 Pages 86 to 89 Pages 78 to 89 Pages 90 to 95 Pages 90 to 92 Pages 93 to 95 Pages 96 to 113 Pages 96 to 97 Page 97 Pages 97 to 98 Pages 99 Page 100 Pages 100 to 101 Pages 102 to 103 Pages 104 to 105 Pages 105 to 109 Pages 109 to 111 Pages 112 to 113 Pages 114 to 147 Pages 114 to 120 Pages 114 to 115 Pages 115 Pages 115 to 119 Page 120 Pages 120 to 131 Page 120 Page 121 Pages 121 to 136 Pages 125 to 129 Pages 129 to 130 Page 130 to 131 Page 131 Pages 131 to 147 Page 131 Pages 132 to 145 Pages 135 to 140 Pages 140 to 141 Pages 141 to 145 Pages 145 to 147 Page 147 Page 147 Page 147 Pages 148 to 151 Pages 152 to 155 Page 152 Page 152 Page 152 Page 152 Page 152 to 153 Table of Contents Friday 21 June 2002 Final Report 13 6 Virtual Channels 13 7 Data Logging 13 8 TCP IP Internet Communications 13 9 Direct Modem to Modem Communication 13 10 Printing of Scope Display 13 11 An Alternative Method for Dealing with Aliasing 13 12 Taking Advantage of Aliasing 14 0 Bibliography References A CD ROM containing source code datasheets etc NOTE Full set of appendixes in separate booklet EEE516J4 Honours Project Page VII Colin K McCord Page 153 Page 153 Page 153 Pages 153 to 154 Page 154 Pages 154 to 155 Page 155 Pages 156 to 158 Page 159 Table of Contents Friday 21 June 2002 Final Report Colin K McCord TABLE
92. 500n 5 l kA E Z Min l m gt Vpop 1k 2 7k Sample Q f T AN4 RA4m l ji D4 Switch 50p Q ADRESL 5p n ST l Vee 2 ON ork ae AN5 RE Omm Yo lk ae 4 9 amp 5 2500n l Vet gt p gt Voo 1k AN6 RE 1m be al 1D l A 5p 500n 2 Va l p gt Von 1k 5 AN7 RE2m i D7 5 A 5p 500n P i Var g fo 3 A A A citi File 9Eh Internal data bus to MCU File 1Fh Analogue channel F 2 address F8 y AD F 32 _J cCR Figure 4 2a Simplified block diagram of the PIC16F877 ADC module The input analogue channels AN4 0 are shared with port A and channels AN7 5 are shard with port E If less than eight analogue channels are required then some of the pins can be assigned as digital I O port lines using PCFG3 0 bits see datasheet For example if PCFG3 0 0010 then AN4 0 are configured as analogue inputs while AN7 5 are digital port E free with Vpp used as the reference On reset all pins are set to accept analogue signals Pins that are reconfigured as digital I O should never be connected to an analogue signal Such voltage may bias the digital input buffer into its linear range and the resulting large current could cause irreversible damage B3 EEE516J4 Honours Project Page 18 Chapter 4 The PIC16F877 Microcontroller Friday 21 June 2002 Final Report Colin K McCord The 10 bit ADC uses a technique know as successive approximation the following mechanical analogy will help exp
93. 68 0X78 OXB8 OXB9 0X79 OXBB OX7B OX7A OXBA OXBE OX7E OX7F OXBF OX7D OXBD OXBC OX7C OXB4 0X74 OX75 OXB5 OX77 OXB7 OXB6 OX76 0X72 OXB2 OXB3 OX73 OXB1 OX71 OX70 OXBO OX50 0X90 OX91 OX51 0X93 OX53 OX52 0X92 0X96 0X56 OX57 OX97 0X55 0X95 0X94 0X54 OX9C OX5C OX5D OX9D OX5F OX9F OX9E OX5E OX5A OX9A OX9B OX5B 0X99 0X59 0X58 0X98 0X88 0X48 0X49 0X89 OX4B OX8B OX8A OX4A OX4E OX8E OX8F OX4F OX8D OX4D OX4C OX8C 0x44 0X84 0X85 0X45 0X87 0X47 0X46 0X86 OX82 0X42 0X43 0X83 0X41 OX81 0X80 o m F oO 0X40 unsigned char CRC Hi OxFF High byte of CRC initialised unsigned char CRC_Lo OxFF Low byte of CRC initialised unsigned index 0 Will index into CRC lookup table while data_length index CRC_Hi message Calculate the CRC CRC Hi CRC Lo Table CRC Hi index CRC_Lo Table CRC_Lo index return CRC Hi lt lt 8 CRC Lo Example CRC calculation Message Length 1 Message 0 0000 0010 Initialised CRC with all 1 s CRC TITT ITITI 1 I Exclusive OR the first 8 bytes of the message with the low order byte of the 16 bit CRC register putting result into the CRC CRE 1 Message 0000 0000 0000 0010 NEW CRC 01 LSB is 1 gt gt 1 no 1 amp EOR with A001 gt gt 1 0 0 A001 010 0000 0000 0001 NEW CRC 0 1 LSB is 1 gt gt 1 no
94. 7 PSP7 1 i iH Vs RD6 PSP6 gt 1 OSC1 CLKIN RDS PSP5 x 1 7 RR 14 losc2 CLKOUT RD4 PSP4 2 si pi 15 26 12 13 8 nA IRCO T10SO T1CKI RC7 RX DT SIrcwt1iosivccr2 RCB TX ICK E 17 ee 24 9 8 w a ry Il Ireziccr1 RCS5 SD g L AO ROMHE RC3 SCK SCL RC4 SDI SDA da RDo PSPO RD3 PSP3 2 MAX232CPE L S ae RD1 PSP1 RD2 PSP2 aan P1IC16F877 20 P 16 Figure 11 2a Test Circuit Diagram 2 11 2 1 Test 4 Test RS232 Communications Baud Rate set by DIP Switches Program mark4 c was compiled and loaded into the PIC using Microchip MPLAB This program is extremely simple basically the same as mark1 c expect baud rate is set by the DIP switches basically it reads the DIP switches and sets the baud rate then it transmits Testing continuously with a 1 second delay between each Testing The DOS based test program test exe version 1 05 was used in the RX terminal mode to receive incoming characters All baud rates were tested and there were no problems EEE516J4 Honours Project Page 120 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 11 2 2 Text 5 Fully Test RS232 Communications Baud Rate set by DIP Switches Program mark5 c was compiled and loaded into PIC using Microchip MPLAB This program is extremely simple basically it reads the DIP switches and sets the baud rate then it waits for an incom
95. 8 40 pin 8 bit CMOS flash microcontrollers 1999 microchip technology EEE516J4 Honours Project Page 158 Chapter 14 Bibliography References Friday 21 June 2002 Final Report Colin K McCord A CD ROM This CD ROM contains complete source code include compiled exe files for all PIC embedded software the test program the simulator program and the scope program all 42 versions present Also contained on this CD ROM are datasheets and over 200MB of raw research data CD ROM EEE516J4 Honours Project Page 159 Appendix CDROM
96. ACK acknowledgment is received from the PC the PIC will start sampling again This is known as a Storage Oscilloscope but there are disadvantages e g it s impossible to continuously monitor a waveform in real time for more than the amount of samples that can be stored into the buffer as there would be gaps in the data Digital storage oscilloscopes have two main advantages over traditional analogue scopes 1 The ability to observe slow and very slow signals as a solid presentation on the screen Slow moving signals in the 10 100 Hz range are difficult to see and measure on a normal analogue oscilloscope due to the flicker of the trace and the short persistence of the spot on the screen Very slow moving signals less than 10 Hz are impossible to view on an analogue scope As fast as the spot traces out the waveform the image fades and disappears before a complete picture can be formed B2 2 The ability to hold or retain a signal in memory for long periods The PIC microcontroller has a built in ADC 8 10 or 12 bits which has a voltage range of 0 to 5V This voltage range is not ideal as most oscilloscopes have a much wider voltage range including negative voltages e g 100 to 100V hence an analogue circuit is required to reduce the voltage positive signals so they fall between 2 5 and 5V and voltage negative signals between 0 and 2 5V i e bipolar The built in ADC on the PIC is slow and will limit the maximum samplin
97. ADC RS232 ADC RS232 Transmit CH4 Read Transmit CH3 Read Reading j Channel4 Reading j Channel3 RS232 ADC RS232 ADC Figure 6 1b Illustration of real time mode with four channels chop mode Figure 6 1c illustrates sampling four channels in the real time mode using alternate sampling Channel 1 is sampled 1000 times then channel 2 is sampled 1000 times then channel 3 is sampled 1000 times then channel 4 is sampled 1000 times and the process repeats forever Let 1 4 Yes 1 gt 1000 gt 1 gt 2000 D 1 gt 4000 p a di Ns A gt No T No Read CH1 and Read CH2 and Read CH3 and Read CH4 and I lt transmit I lt transmit I lt transmit I lt transmit reading reading reading reading Figure 6 1c Illustration of real time mode with four channels alternate mode The advantage of using alternate sampling is that all channels can be sampled at the maximum sample rate while in chop mode each channel must share the RS232 throughput RS232 bottleneck for example say the maximum sample rate was 4KHz set by the maximum RS232 frame structure throughput one channel enabled would have a max sample rate of 4KHz two channels enabled would have a max sample rate of 2KHz each four channels enabled would have a max sample rate of 1KHz each EEE516J4 H
98. B HANDLE handle HDC hDC EEE516J4 Honours Project Page 73 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord HPALETTE hPal ASSERT bitmap GetSafeHandle The function has no arg for bitfields if dwCompression BI _BITFIELDS return NULL If a palette has not been supplied use defaul palette hPal HPALETTE pPal gt GetSafeHandle if hPal NULL hPal HPALETTE GetStockObject DEFAULT PALETTE Get bitmap information bitmap GetObject sizeof bm LPSTR amp bm Initialize the bitmapinfoheader bi biSize sizeof BITMAPINFOHEADER bi biWidth bm bmWidth bi biHeight bm bmHeight bi biPlanes 1 bi biBitCount bm bmPlanes bm bmBitsPixel bi biCompression dwCompression bi biSizeImage bi bixPelsPerMeter bi biYPelsPerMeter bi biClrUsed bi biClrImportant r ni r r ar A o E ar A o P Es r Compute the size of the infoheader and the color table int nColors 1 lt lt bi biBitCount dwLen bi biSize nColors sizeof RGBQUAD We need a device context to get the DIB from hDC GetDC NULL hPal SelectPalette hDC hPal FALSE RealizePalette hDC Allocate enough memory to hold bitmapinfoheader and color table hDIB GlobalAlloc GMEM_FIXED dwLen if hDIB SelectPalette hDC hPal FALSE ReleaseDC NULL hDC return NULL lpbi LPBITMAPINFOHEADER hDIB l
99. BACKGROUND Oscilloscopes traditionally are hardware based using a CRT Cathode Ray Tube designed to display voltage variations periodic or otherwise they are bulky expensive and have difficultly displaying low frequency waveforms Figure 1 0a 20MHz Analogue a Trace CRT about 400 Figure 1 0b 150MHz Analogue Digital CRT about 1 600 W1 The word Oscilloscope is an etymological hybrid The first part derives from the Latin oscillare to swing backwards and forwards this in turn is from oscillum a little mask of Bacchus hung from the trees especially in vineyards and thus easily moved by the wind The second part comes from the Classical Greek skopein to observe aim at examine from which developed the Latin ending scopium which has been used to form names for instruments that enable the eye or ear to make observations B1 The heart of the traditionally CRT oscilloscope is the display screen itself the CRT The CRT is a glass bulb which has had the air removed and then been sealed with a vacuum inside At the front is a flat glass screen which is coated inside with a phosphor material This phosphor will glow when struck by the fast moving electronics and produce light emitted from the front and forming the spot and hence the trace The rear of the CRT contains the electron gun assembly A small heater element is contained within a cylinder of metal called the cathode When
100. C based oscilloscope If more time was available it would be nice to investigate this theory further EEE516J4 Honours Project Page 155 Chapter 13 Recommendations For Further Work Friday 21 June 2002 Final Report Colin K McCord 14 0 BIBLIOGRAPHY REFERENCES NOTE References are in blue text referred to them explicitly in this report the rest are bibliography Text Books fan Hickman 4 B1 Oscilloscop HOW THEY WORK B3 B5 AUDIO VIDEO AND DATA TELECOMMUNICATIONS Journals J1 J2 Oscilloscopes How to use them How they Work B2 Honds On Guide to OSCILLOSCOPES Barry Ress By lan Hickman Publisher Newnes ISBN 0 7506 2282 2 UUJLIB 621 3815483HIC 1995 The Quintessential PIC Microcontroller B4 By Dr Sid Katzen Published by Springer ISBN 1 85233 309 X 2001 Audio Video And Data Telecommunication B6 COMMUNICATION FOR ENGINEERS By David Petersen Published by McGraw Hill ISBN 0 07 707427 0 1992 Computer Networks Third Edition amem Mhe B8 Complete Reference By Andrew S Tanenbaum Publisher Prentice Hall ISBN 0 13 394248 1 1996 Number 1 Page 13 20 Publisher Emerald J3 Data Systems Vol 94 No 1 1994 pp 3 8 EEE516J4 Honours Project Page 156 Hands On Guide to Oscilloscopes By Barry Ross Publisher McGraw Hill ISBN 0 07 707818 7 UUJLIB 621 3815483ROS 1994 Mi
101. Cord 3 0 FUNDAMENTALS 3 1 The Basic CRT Oscilloscope An oscilloscope draws its trace with a spot of light produced by a deflectable beam of electrons moving across the screen of its CRT see Figure 1 0c Basically an oscilloscope consists of the CRT a time base circuit to move the spot steadily from left to right across the screen at the appropriate time and speed and some means usually a Y deflection amplifier of enabling the signal to deflect the spot in the vertical or Y direction z i CRT Frequency compensated Y Amplifier Y Deflection attenuator Stage Y Input AC o 8 Dmi gt CRT Y J D Deflection DC plates Tri CRT X Y Shift r gger Deflection pickoff amp plates X Deflection Stage int Trigger TE Sweep gate Selector logic O ext Trigger Input Trigger Level Trigger To CRT Polarit Auto o Grid 1 Brightline 4 Circuit Blanking Amplifier X Input Sweep Speed Setting Figure 3 1a Block diagram of a basic CRT oscilloscope This type of oscilloscope is known as a real time oscilloscope This means that the vertical deflection of the spot on the screen at any instant is determined by the Y input voltage at that instant Not all CRT oscilloscope are real time instruments figure 3 1b categorises the various types available Cathode ray x oscilloscopes Real time scopes Caan sc
102. EEE ANNT al Ti Hi i Visiole on all desktops tik l Colapse to this desktop f D Individua settings Menu options l About nView CPU Mboard ITN F ii 40 C Figure 7 14a Demonstrating the transparent window feature added to the windows system menu by the video card drivers Figure 7 14a demonstrates the transparent window feature that was added to the windows system menu by video card drivers Clearly this feature requires hardware acceleration hence it is plausible that all windows based drawing is being acceleration by hardware EEE516J4 Honours Project Page 84 Chapter 7 The Scope Program Friday 21 June 2002 Final Report nView Menu Extension Options x MV Maximize to desktop MV Send window to monitor n IV Send application to monitor n M Send window to desktop n graphics M Send application to desktop n Transparent MV Always ontop Add all Add all DTM Remove all DTM Cancel Figure 7 14b nView Menu Extension Options M Position memory WM Visible on all desktops Collapse to this desktop M Individual settings Colin K McCord nview Desktop Manager E 21x Profiles Windows Effects Hot keys Desktops Effects Provides 3D features for windows and dynamic zoom functionality on the desktop m Window Drawing Enhancements I Make windows transparent when dragged Transparency level of 125 percent Zoom Settings F U
103. Eoy Hp file scope bmp E E ee E A diaii Browse i Zoom out Zoomin Edt Print Move to Saving the scope display to a BMP file would have been fairly simple if a handle to a device independent bitmap existed Simply write BITMAPINFOHEADER information followed by the contents of the bitmap The three fields that have to be set in the BPTMAPINFOHEADER are the bfType which should always be BM the bfSize which is the size of the bitmap including the infoheader and the bfOffBits which is the offset to the bitmap bits from the start of the file But unfortunately the scope display is a device dependent bitmap Therefore a DIB Device Independent Bitmap must first be created from it Figure 7 10c Screen dump of exported file scope bmp The following function converts a DDB Device Dependent Bitmap to a DIB Device Independent Bitmap HANDLE CScopeView DDBToDIB CBitmap amp bitmap DWORD dwCompression CPalette pPal Fuction HANDLE CScopeView DDBToDIB Description Convert Device Dependent Bitmap DDB to Device independent Bitmap DIB Return Void Date 16 02 2002 Verison 1 3 By Colin K McCord PEAN EN ts AE ENE ET EET E EEEE E DDBToODIB Creates a DIB from a DDB bitmap Device dependent bitmap awCompression Type of compression see BITMAPINFOHEADER pPal Logical palette BITMAP bm BITMAPINFOHEADER Ip LPBITMAPINFOHEADER lpbi DWORD dwLen HANDLE hDI
104. Figure 3 6b 9 pin RS232 D connector pin signal description Typical line drivers receivers chips for RS232 are the Maxim MAX232 or MAX233 chips see http www maxim ic com the original specification states that RS232 should drive 50 feet but modern line driver receivers can manage much better than this Baud Rate Max Distance Shielded Cable Max Distance Unshielded Cable 110 bps 5000 feet 3000 feet 300 bps 5000 feet 3000 feet 1200 bps 3000 feet 3000 feet 2400 bps 1000 feet 500 feet 4800 bps 1000 feet 250 feet 9600 bps 250 feet 250 feet Figure 3 6c Typical maximum distance modern line driver receivers can manage before errors occur EEE516J4 Honours Project Page 15 Chapter 3 Fundamentals Friday 21 June 2002 Final Report Colin K McCord 4 0 THE PIC16F877 MICROCONTROLLER PIC16F874 7 EEPROM dma memory Instruction Gecoder amp control rs P 2 z 2 7 z S s 3 4 ued On a ued on Figure 4 0a Architecture of the PIC16F877 microcontroller W9 EEE516J4 Honours Project Page 16 Chapter 4 The PIC16F877 Microcontroller Friday 21 June 2002 Final Report Colin K McCord The PIC16F877 is a high performance FLASH microcontroller that provides engineers with the highest design flexibility possible In addition to 8192x14 words of FLASH program memory 256 data memory bytes and 368 bytes of user RAM PIC16F877 also features an integrated 8 channel 10 bit Analog
105. Final Year Project Low cost PC based quad channel real time storage oscilloscope Final Report Supervisors First Dr S Katzen Second Dr C Tuner s Scope Untitled 5 x File Edit View Tools Window Help 5 x iM eo mey lE BD amp EFA C a a Disp Trig IZINT TAN TT ry tT PT YR TT YAN TER YiTRI T T AT TA IAT S Time ooms OV LT AT PT IAT VT ENT T7t TY Tt th Base INT TNA TERA TT AY TON Hele deeds deal ahaa Une Uh da fd Ui LAT cre FR V AAA NAE PA T MAMIR o vov M CH3 joviDV Vo fovDpy U ULSTER P UNIVERSITY of school of electrical and DSA N H ii mechanical engineering COURSE BEng HONS Electronic Systems MODULE EEE516J4 Honours Project BY Colin K McCord DATE Friday 21 June 2002 Friday 21 June 2002 Final Report Colin K McCord ACKNOWLEGEMENTS Dr S Katzen For everything that he has done in helping the project along and for offering support and encouraging an interest in the field of microprocessor microcontroller engineering Dr C Turner For everything that he has done in helping the project along and for offering support and encouraging an interest in the field of object originated programming Dr Ning Li For the use of FG Wilson s electronic laboratory EEE516J4 Honours Project Page Acknowledgements Friday 21 June 2002 Final Report Colin K McCord EXECUTIVE SUMMARY The following report details the development and implementation o
106. Grid SView gt PrepareTraces SView gt OnDrawGrid SView gt OnDrawCHl1 SView gt OnDrawCH2 SView gt OnDrawCH3 SView gt OnDrawCH4 Je r r SetTitle m Filename A standard Windows CFileDialog is used to allow the user to select the file to open then a pointer to the file is setup Once again the old ASIC C method of accessing files is used this time using the function fscanf to read the file line by line The data is retrieved from the data file in exactly the same order as it was saved once all fields have been acquired the scope display is refreshed EEE516J4 Honours Project Page 68 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord Sample Disp Trig Time fioms ov Base Ce von Mon Voy y McH3 fivioVv Figure 7 8c Example File1 sdf has been opened then CH1 CH2 was disabled with voltage time base scales modified Figure 7 8c demonstrates the potential of this feature File1 sdf has been loaded Channel 1 and Channel 2 has been disabled Hidden voltage and time base scales have been modified Zero point of channels 3 and 4 has been moved and a large offset has been applied to channel 3 Op F I Pi SC i 5 x File Edit View Tools Window Help 18 x i OO DSHP DAAC SS le z Sample Disp Trig Time D5S DIV Nes EA Cei von Mene faviov v McH3 fiviov Kevo E Figure 7 8d Demonstr
107. Gridy y it m_dcGrid SetPixel m_nGridxX n i GRAY Draw H grey line for n 10 n lt y n n 10 for i m_nGridX 0 i lt m_nGridX x i m_dcGrid SetPixel i m_nGridY n GRAY Draw Centre Axis m_dcGrid MoveTo m_nGridX x 2 m_nGridY 0 m_dcGrid LineTo m_nGridX x 2 m_nGridY y m_dcGrid MoveTo m_nGridX 0 m_nGridY y 2 m_dcGrid LineTo m_nGridX x m_nGridY y 2 Draw V Ticks on H Centre for n 2 n lt x n n 2 m_dcGrid MoveTo m_nGridX n m_nGridY y 2 1 m_dcGrid LineTo m_nGridX n m_nGridY y 2 Draw H Ticks on V Center for n 2 n lt y n nt2 m_dcGrid MoveTo m_nGridX x 2 m_nGridY n m_dcGrid LineTo m_nGridX x 2 1 m_nGridy n m_dcGrid SelectObject pOldPen Update Display Invalidate TRUE 7 3 The Traces The drawing of the traces looks extremely complex when looking at the big picture as channel offsets zero positions time base sample rate triggering method channel disabled enabled and voltage scales all affect how the scope traces are drawn Allow the basic principles behind the drawing of the waveforms are simple so let s try and describe how the waveform traces are drawn step by step There are four large arrays one for each channel in class CScopeApp int m_nCH1Vol1t 10000 Voltage 1000 int m_nCH2Volt 10000 Voltage 1000 int m_nCH3Volt 10000 Voltage 1000 int m_nCH4Volt 10000 Voltage 1000
108. Hardware Development 5 1 5 2 5 3 5 4 5 5 5 6 Simplified Block Diagram Digital Circuit Diagram Analogue Circuit Diagram Mark 1 Analogue Circuit Diagram Mark 2 System Powering Circuit Cost of Components 6 0 Communication Protocol Development 6 1 6 2 6 3 6 4 6 5 6 6 6 7 6 8 6 9 Real Time Mode Storage Mode Control Protocol Frame Structure Real Time Mode Sample Rate Real Time Mode Frame Structure Storage Mode Sample Rate Storage Mode CRC16 Cyclical Redundancy Check used in Storage Mode 6 8 1 Comparison of Raw Calculation CRC amp Lookup Table CRC Frame Structure Control Protocol 7 0 The Scope Program 7 1 Data Flow Diagram 7 1 1 Data Flow Paths 7 2 7 3 7 4 7 5 7 6 7 7 7 8 7 9 The Grid The Traces Storing and Restoring the Previous Position of the Main Frame Setting Up RS232 Communications Solving the Flickering Problem Creating the Split Window View Saving Opening Scope Data Copying the Scope Display to the Windows Clipboard 7 10 Exporting the Scope Display as a Bitmap BMP File EEE516J4 Honours Project Page V Colin K McCord Pages 1 to 3 Page 4 Page 4 Page 4 Pages 5 to 15 Page 5 Page 6 Pages 6 to 8 Pages 8 to 12 Page 9 Pages 9 to 10 Pages 10 to 12 Pages 12 to 13 Pages 13 to 15 Pages 16 to 20 Page 17 Pages 18 to 19 Page 20 Page 20 Pages 21 to 29 Pages 21 to 23 Pages 23 to 24 Pages 24 to 26 Pages
109. Included in this report were design details of the real time communication protocol this included the frame structure and some maximum sample rate calculations at different baud rates There are two real time sampling modes the first is chop mode where channel 1 is sampled then channel 2 then channel 3 then channel 4 Clearly this causes a number of problems the first is that RS232 throughput must be shared between all channels hence this reduces the maximum sampling rate the second is that because it takes time for the ADCs sampling capacitor to charge 20us there is a time delay between sampling each channel e g channel 1 will lead channel 2 by 20us Obviously this waveform offset can be software corrected for EEE516J4 Honours Project Page 148 Chapter 12 Conclusions Friday 21 June 2002 Final Report Colin K McCord example a future version of the scope program could have a calibration dialog which allows the user to software offset channel timings to compensate for this 20us delay between waveforms The second real time mode is alternate basically this samples channel 1 1000 times then channel 2 1000 times then channel 3 1000 times then channel 4 1000 times Clearly this has the advantage of maximising the real time sample rate channels don t share RS232 throughput no matter how many channels are enabled but continuous monitoring of a waveform is impossible as there are gap in the data and channel phases are lost e g
110. L inputs parallel slave mode is turn ON It is clear from the PIC data sheet that this parallel slave mode also effects port D which is connected to the address bus Switching off parallel slave mode solved the problem but created a new one DIP switches cannot be read The solution to this new problem was simple before reading the DIP switches turn ON parallel slave mode and after reading the DIP switches turn OFF parallel slave mode Screen dump of the result for the corrected mark10 c program is shown below RX Terminal Waiting for message press a key to stop TEST RAM CHIP Test 1 Fill RAM with OxFF gt Passes 8192 Fails 0 Test 2 Fill RAM with 0x00 gt Passes 8192 Fails 0 Test 3 Fill RAM with LSB of Address gt Passes 8192 Fails 0 End of RAMTEST Hopefully work can now start on storage mode Clearly the RAM test was a success and work can now start on the storage mode embedded program 11 3 4 Test 11 5V Regulator The system powering circuit figure 5 5a was constructed on prototype board The input voltage was varied from 8 to 20 VDC while the output voltage was measured using a digital CRT storage oscilloscope Output voltage was 5 VDC throughout the test 11 3 5 Test 12 Test 12 Analogue Circuitry The analogue circuitry figure 5 4a circuit was constructed on proto type board and tested Signal generator was used to generate the input and a digital CR
111. OE PIE Read ADC aha justified Read Dip Select channel Select channel 10ms delay ee set ANO AN1 E 20us delay 100Hz Figure 10 8a Mark 8 flowchart Mark 8 c source code JR aeoso SoA a a os FILE mark 8 c PROJECT Low Cost PC Based Oscilloscope DESC Read CH1 amp CH2 transmit result through RS232 using the real time frame format Baud rate set by dip switches DATE 05 03 2002 BY Colin K McCord VERSION 1 4 include lt 16F877 h gt device PIC16F877 16 ADC 10 use device adc 10 to implement a 10 bit conversion otherwise the default is 8 bits fuses HS NOWDT NOPROTECT NOLVP byte PORTE 0x09 PortE lives in File 9 Note 20MHz clock must be used for 115 000 bps the error is to large at slower speeds use delay clock 20000000 use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 use fast_io E Fast access to PortE don t fiddle with TRISE Forward declaration of functions void SetBaudRate main EEE516J4 Honours Project Page 104 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord NOTE by default in CCS all var s are unsigned long int adcValue 16 bit storage for ADC reading char adcHI adcLO 8 bit storage for real time frames set_tris_e 0x17 TRISE 00010111 RE2 RE1 and REO TTL Inputs SetBaudRate
112. OnTImer function void CSimDlg ComProtocolTop int i UpdateData TRUE RealTime if IsDlgButtonChecked IDC_REALTIME for i 1 i lt 10 i if m EnableCH1 TRUE SimCH1 if m_EnableCH2 TRUE SimCH2 if m_EnableCH3 TRUE SimCH3 if m_EnableCH4 TRUE SimCH4 This function simulates CH1 all four channels are done the same way void CSimDlg SimCH1 15 03 2002 by CKM Version 1 6 unsigned short temp unsigned char chl_bl chl_b2 double value double freq 50 0 double amp amp double GetDlgItemInt IDC_AMP_CH1 NULL TRUE freq double GetDlgItemInt IDC_FREQ CH1 200 if m_nCHlWaveType SINE value amp sin 2 3 14159 freq t1l temp unsigned short 512 0 102 4 value tl tl 1 if tl gt freq tl 1 0 if m_nCHlWaveType SQUARE value 10 sin 2 3 14159 freq t1l if value gt 0 value amp EEE516J4 Honours Project Page 88 Chapter 8 The Simulator Program Friday 21 June 2002 Final Report Colin K McCord else value amp 1 0 temp unsigned short 512 0 102 39 value Glo St se a if tl gt freq tl 1 0 if m_nCH1lWaveType RANDOM temp rand 1024 chl_bl temp gt gt 5 chl_bl chl_bl amp Ox1F amp 00011111 chl_b2 unsigned char temp chl_b2 chl_b2 0x80 1000 0000 trans chl_bl trans
113. Pen penCH1 CDC m_dcCH1 CDC m _dcCH2 CPen penCH2 CDC m dcCH3 Pen penCH3 Q CDC m_dcCH4 Pen penCH4 Q Variables are initialised in the CScopeView constructor CScopeView CScopeView m_bitmapCH1 NULL m_bitmapCH2 NULL m_bitmapCH3 NULL m_bitmapCH4 NULL m_nClientHeight 0 m_nClientWidth 0 x 100 y 80 Zero Point Positions EEE516J4 Honours Project Page 54 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord m_nCH1POS 40 m_nCH2POS 20 m_nCH3POS 50 m_ nCH4POS 60 m_nCH1_ Offset 0 m_nCH2 Offset 0 m_nCH3 Offset 0 m_nCH4 Offset 0 m nTriggerCHl 0 m nVPD CH 100 1 voltage per division m_nVPD_CH2 100 m_nVPD_CH3 100 m_nVPD_CH4 100 penGrid NULL penCH1 NULL penCH2 NULL penCH3 NULL penCH4 NULL m_bChangeZeroCHl false m_bChangeZeroCH2 false m_bChangeZeroCH3 false m_bChangeZeroCH4 false m bChangeOffsetCHl false m_nRefreshRate 200 Default refresh rate 200ms Refresh timer trace colours grid colour and the grid background colour are setup here void CScopeView OnInitialUpdate CView OnInitialUpdate pDoc CScopeDoc m pDocument pApp CScopeApp AfxGetApp SetTimer nTimerRefresh m nRefreshRate NULL penGrid new CPen penGrid gt CreatePen PS_ SOLID 1 WHITE
114. RR KR RRR ARR ARR ARR ARR k kkk kkk k k kk kkk k k k k kk k A KK k k BCMenu h header file Version 3 0 Date January 2002 Author Brent Corkum Email corkum rocscience com Latest Version http www rocscience com corkum BCMenu html Bug Fixes and portions of code supplied by Ben Ashley Girish Bharadwaj Jean Edouard Lachand Robert Robert Edward Caldecott Kenny Goers Leonardo Zide Stefan Kuhr Reiner Jung Martin Vladic Kim Yoo Chul Oz Solomonovich Tongzhe Cui Stephane Clog Warren Stevens Damir Valiulin You are free to use modify this code but leave this header intact This class is public domain so you are free to use it any of your applications Freeware Shareware Commercial All I ask is that you let me know so that if you have a real winner I can brag to my buddies that some of my code is in your app I also wouldn t mind if you sent me a copy of your application since I like to play with new stuff J KR RK RR KR I RRR ARR ARR kkk kkk k kkk kkk k kkk kkk k k k k k k k k A A kK k k 7 11 1 Integrating Brent Corkum s BCMenu Class with the Scope Program Step 1 Add include BCMenu cpp to stdafx cpp stdafx cpp source file that includes just the standard includes Scope pch will be the pre compiled header stdafx obj will contain the pre compiled type information include stdafx h include UsefulSplitterWnd cp
115. T storage oscilloscope was used to check the output before connecting to the PIC ADC The test was not perfect as the scale was incorrect For example a 2 5 to 2 5 volt sine wave was connected to the 2 5 to 2 5 input the output was 1 to 5 volts and not O to 5 volts as expected Allow this could be software corrected it makes since to play around with the resistor values to try and improve this Perhaps variable resistors may have to be used for calibration purposes Note a switch mode DC to DC converter was used to converter 5 Vdc to 15 and 15V Hence the entire circuit was power from one supply Note the diodes successfully stopped the output voltage getting too low or too high 11 3 6 Conclusion Evidently the scope program can view up to four channels at a sample rate of 1kKHz and one channel at a sample rat of 5kHz in real time Clearly there is a triggering problem as it was difficult to obtain a stable trace when triggering off another channel for example when triggering off channel 1 all other channels were constantly scrolling across the screen When the same signal is inputted into all four channels it is now possible to get a stable trigger e g waveforms related but waveforms of different frequencies was a problem Clearly storage mode operation is now possible as the RAM chip was successfully tested The first step might be to use the real time frame structure storing up to 4000 reading into RAM and then cycling through the
116. Type cx cy m_nClientWidth cx m_ nClientHeight cy m_ClientRect bottom m_ClientRect left 0 m_ClientRect right m_nClientWidth m_ClientRect top m_nClientHeight 0 PrepareGrid PrepareTraces OnDrawGrid OnDrawCH1 OnDrawCH2 OnDrawCH3 OnDrawCH4 r r r Function OnSize first retrieves the new size of the scope display from the system and updates the m_nClientRect variable Then it calls function PrepareGrid to recalculate and fill the grid coordinate arrays Then prepares the traces redraws the grid and all of the traces 7 4 Storing and Restoring the Previous Position of the Main Frame Basically the window size and position is saved to the windows registry before the application closes and restored when the program starts up Two functions used for saving and restoring windows position 11111111111 111 11 111 11 11 1 11111 11 111 1 1 1111 1 1111 1 111 1 11 111 11111 11 1111111111111 saving restoring window state static TCHAR BASED CODE szSection _T Settings static TCHAR BASED CODE szWindowPos _T WindowPos static TCHAR szFormat _T u u d 3d d Sd sd sd sd sd static BOOL PASCAL NEAR ReadWindowPlacement LPWINDOWPLACEMENT pwp CString strBuffer AfxGetApp gt GetProfileString szSection szWindowPos if strBuffer IsEmpty return FALSE WINDOWPLACEMENT wp int nRead _stscanf strBuffer szFormat amp wp f
117. Vew Toos Window Hep 8 x Mi alraiRi a srea Sample Disp Trig F Bass aa M CHI fv CH2 a E B JA HAO 0 OVINI N ULTA E TTD ATT EA A MITE WA M Figure 11 2 3h Screen dump of scope program sample rate 1 000Hz input wave 500Hz sinewave 0 5V Ready 11 2 3 1 Sample Rate Changed to 2000Hz mark6b c Scope time base is 0 005 seconds per division that s 200Hz 10Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 1a resolution 200 x 160 that s 20 x 16 divisions 19 5 division per cycle hence the calculated frequency of the waveform is 1 19 5 0 005 10 25Hz Scope Scopel E 5 x B Fie Edt View Toos Window Help 15 x eom la a Esa Sample Disp Trig Base z v CHI j ha cue fivjov HE HEHE gee Sane SAREE EEE EEE REH EEE EEE EEE eee ECE EEE eee cere Ready CAP Figure 11 2 3 1a Screen dump of scope program sample rate 2 000Hz input wave 10Hz sinewave 0 5V EEE516J4 Honours Project Page 125 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 20Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 1b resolution 200 x 160 that s 20 x 16 divisions 9 7 division per cycle hence the calculated frequency of the waveform is 1 9 7 0 005 20 6Hz 0 x 218 x ie c Ba E Ea Sample Disp Trig Time 5 Base fa ASAA i vee oe E eia fiviov x oo
118. Window Hep l Pi OlG Ans sgsrere Sample Disp Trig Time Base CHI f1v Dv MeH liv DIV F Figure 11 3 2a Screen dump of scope program sample rate 1 kHz CH1 25Hz sinewave CH2 5V CH3 5V CH4 5V 25Hz sinewave 0 5V connected to CH2 AN1 and all other channels connected to 5V see figure 11 3 2b 4 divisions per cycle hence the calculated channel 2 frequency is 1 4 0 01 25Hz Channels 1 3 amp 4 are at 5V DC W O More fiviov Mon fivov x Ready Figure 11 3 2b Screen dump of scope program sample rate 1 kHz CH2 25Hz sinewave CH1 5V CH3 5V CH4 5V EEE516J4 Honours Project Page 133 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 25Hz sinewave 0 5V connected to CH3 AN2 and all other channels connected to 5V see figure 11 3 2c 4 divisions per cycle hence the calculated channel 3 frequency is 1 4 0 01 25Hz Channels 1 2 amp 4 are at 5V DC 7 Sco le Edt Sample Disp Trig Time Base Men fiviov M cHe hiv oVv Men fiviov x Figure 11 3 2c Screen dump of scope program sample rate 1 kHz CH3 25Hz sinewave CH1 5V CH2 5V CH4 5V 25Hz sinewave 0 5V connected to CH4 AN3 and all other channels connected to 5V see figure 11 3 2d 4 divisions per cycle hence the calculated channel 4 frequency is 1 4 0 01 25Hz Channels 1 2 amp 3 are at 5V DC 2 Sco Scope Scopeh
119. a Mark 2 flowchart Page 97 10 3a Mark 3 flowchart Page 98 10 7a Mark 7 flowchart Page 102 10 8a Mark 8 flowchart Page 104 10 9a Mark 9 flowchart Page 106 11 0 Test Results Pages 114 to 147 11 1a Test circuit diagram 1 Page 114 11 1 3a Screen dump of scope program sample rate 100HZz input wave 1Hz Page 116 11 1 3b Screen dump of scope program sample rate 100HZz input wave 2Hz Page 116 11 1 3c Screen dump of scope program sample rate 100Hz input wave 5Hz Page 117 11 1 3d Screen dump of scope program sample rate 100Hz input wave 10Hz Page 117 11 1 3e Screen dump of scope program sample rate 100Hz input wave 20Hz Page 118 11 1 3f Screen dump of scope program sample rate 100Hz input wave 50Hz Page 118 EEE516J4 Honours Project Page IX Table of Figures Friday 21 June 2002 Final Report Colin K McCord 11 1 3g Screen dump of scope program sample rate 100Hz input wave 100Hz Page 119 11 1 3h Screen dump of scope program sample rate 100Hz input wave 200Hz Page 119 11 2a Test circuit diagram 2 Page 120 11 2 3a Screen dump of scope program sample rate 1 000Hz input wave 2 5Hz Page 121 11 2 3b Screen dump of scope program sample rate 1 000Hz input wave 5Hz Page 122 11 2 3c Screen dump of scope program sample rate 1 000HZz input wave 10Hz Page 122 11 2 3d Screen dump of scope program sample rate 1 000Hz input wave 20Hz Page 123 11 2 3e Screen dump of scop
120. additional time delay oe la x Ele Edt Vew Toos Window Hep ala xJ Ei Qln AA Zla ere Sample Disp Tria Time Base V CHI Sv DNV M CH2 fi Ready Figure 11 2 3 2a Screen dump of scope program sample rate 5 000Hz input wave 50Hz squarewave 0 5V This program reads the ADC and transmits two characters with a 200uS delay before the process repeats over and over again But if the transmits buffer is full note that for 115kbps it takes 8 7us 1 115 000 to transmit each character that s 86 9uS per byte Using the PICs built in timers should fix this problem But the main reason for the distorted waveform was because the PC serial buffer was overflowing The incoming characters were coming in faster than the scope program was processing them hence the buffer was overflowing causing gaps to appear in the data The solution is to increase the scope programs communication protocol real time timer e g from 100ms to 25ms and increase the buffer size from 1k to 10k 11 2 4 Test 7 Test Timer Interrupts Program mark7 c was compiled and loaded into the PIC using Microchip MPLAB This program is simple basically it setups all of the PIC onboard timers to interrupt the main program at preset timer intervals then Main is transmitted once every second forever Timer 0 interrupt is used to transmit Interrupt_TO twice a second timer 1 interrupt is used to transmit Interrupt_T1
121. ame was thought that it may not be suitable with the PIC Although it is possible to generate the CRC using a lookup table this reduces processor load but this lookup table uses a lot of COUNT No of data bytes RAM DATAN The plan is to use a 16 bit CRC for error detection as this practically guarantees that all errors are detected But if it I turns out that it is impractical to implement on the PIC a l simple checksum will be used instead but the disadvantage of this is that not all errors will be detected burst errors will be DATA n a problem Note all fields in the frame are included in the CRC or maybe checksum calculation e g SOF COUNT and DATA i DATA n CRC low byte The data field uses the same frames as specified for the CRC high byte real time frame structure The big advantages of this is that the code reusable e g subroutines functions can be written Figure 6 6a Frame Structure Storage Mode and used in the real time and storage modes There are two options for checking if the frame is correct 1 Calculated the CRC for the received frame and compare with the received CRC 2 Send the entire frame to the CRC function including received CRC and if the calculated CRC is zero then the frame is correct 6 7 Sample Rate Storage Mode Since operating in storage mode the maximum sampling rate is only limited by the maximum sampling rate of the PIC ADCs and not the RS232 lin
122. an Transmit the Hardware UART incoming E a received baud rate 9600 character character Figure 10 2a Mark 2 flowchart Mark 2 c source code ea a pe ep a a a es a a a a a ae eee ne ace FILE mark 2 c PROJECT Low Cost PC Based Oscilloscope DESC Test Serial Communications waits for an incoming char and transmits the char DATE 19 02 2002 BY Colin K McCord VERSION 1 0 include lt 16F877 h gt device PIC16F877 16 ADC 10 fuses HS NOWDT NOPROTECT NOLVP use delay clock 4000000 use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 main Note kbhit can be used to check for incoming char before calling getc while TRUE putc getc Wait for incoming char and transmit 10 3 Mark 3 c Real Time Mode 1 Channel Fixed Sampling Delay This program reads ADC channel ANO and transmits the reading through RS232 using the real time frame structure with a fixed sampling delay of 10mS that s a sample rate of 100Hz before repeating see figure 10 3a This program is extremely useful as it tests the ADC the scope program and the real time frame structure The sample rate is fixed allow the sample delay can be manually modified e g 1ms 1000Hz and the program recompiled and load into the PIC hence testing of different sample rates is possible EEE516J4 Honours Project Page 97 Chapter 10 PIC S
123. and Windows 2000 Note Windows XP running on laptop AMD 1GHz 8MB 3D video card 256MB of PC133 RAM and Windows 2000 98 dual boot running on desktop AMD 800MHz 64MB 3D video card 256MB of PC133 RAM The colours settings in the display control panel Win XP was changed from 24 bit to 16 bit this reduced CPU load But in Windows 2000 the colours are set to 32 bit and the CPU load is less than 2 and in Windows 98 the colours are also set to 32 bit and the CPU load is less than 10 Clearly Windows XP is trying to display the scope graphics at full colour specified in the display control panel The program creates a new bitmap in XP same number of colours as the system every time the screen is refreshed and deletes the old bitmap to make sure there is not a memory leak Clearly this is bad programming practice as it is not necessary to create a new bitmap every time but only when the screen is resized The code will be modified in the near future so that this is the case this will reduce CPU load but the problem remains when the window is being resized It makes sense to try and also modify the code so that only a 256 colour bitmap is created and not one with same number of colours as the system in reality the scope display will use less than 16 colours no need for 16 bit 24 bit 32 bit colour The big question is why this problem is not present in Windows 2000 there are two possible reasons 1 Windows 2000 may limit the number of colo
124. angle shows the zero point of the displayed waveform The user using the mouse can click on the triangle and drag it to a new position hence changing the zero point see figure 7 0e Notice if the waveform is too high or too low for the display the top bottom of the waveform will be cut off lgi xj Scope ntited Ci fle Edt Wew Toos Window Hep jal xi Poons y DS OATS SKC Figure 7 0e Three screen dumps of scope exe demonstrating the change of zero point Notice the small red triangle at the top of the graphical display this triangle shows the offset position of the displayed waveform middle of the screen represents zero offset The user using the mouse can click on the triangle and drag it to a new position hence changing the waveform offset see figure 7 0f Notice that if the waveform is offset to the right it is possible to see data before the waveform triggered This feature is mainly useful for helping in the measurement of waveform period time use in calculation of frequency where the waveform can be scrolled so that a peak is directly in line with a division line making actuate measurement easy Scope untitled 0 Be Ede yew Took Window Help Figure 7 0f Three screen dumps of scope exe demonstrating the change of waveform offset EEE516J4 Honours Project Page 44 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord Also notice that the waveform triggers on a low to hig
125. ar Communication Le CControlsP1 7 le 8 Sample Tab CControlsP2 4 4 CGridConfigDig i Disp Tab Grid Configuration CScopeView Graphical Display CControlsP3 i Trig Tab VV F Y gt CScopeApp CScopeDoc a 10 5 CAboutDig About Dialog Output Input P 4 n A Windows r Windows l sdf file bmp file Clipboard Printer RS232 Registery 7 1 1 Data Flow Paths The Data Flow Diagram shows how data flows between classes but it does not give any details on the type of data being transferred The following is detailed information about data flow in all numbered paths shown on the Data Flow Diagram Path 1 CControlsP2 gt CScopeDoc int m TimeBaseSelection int int m nCH3_VOLTS int Path 2 CControlsP3 gt CScopeDoc int m_nTrigger int int m nTriggerFormat Path 3 CMainFrame gt CScopeApp int m_nSampleMode int int m nCH1Volt 10004 int int m nCH4Volt 10004 int m_nCH1_ VOLTS m nCH4 VOLTS m_nTriggerOffsetLevel m_nBufferSize m_nCH2Volt 10004 m_ nInputRange Path 4 CScopeView gt CGridConfigDlg int x COLORREF m_ColorGridBackGround EEE516J4 Honours Project int y m_nRefreshRate Page 49 int m_nCH2_ VOLTS int m_nTriggerType int m_nPOS int m_nCH3Volt 10004 int m_SampleRateSelection Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord Path 5 Chi
126. ating aliasing by selecting a out of range time base EEE516J4 Honours Project Page 69 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord It is important to remember that the saved waveforms are with respect to the original sample rate The scope program increases the time base by skipping readings and decreases the time base by duplicating readings As shown in figure 7 8d it is possible for aliasing to occur if the selected time base requires for less than 2 samples per cycle to be displayed hence it is important to make sure the sample rate is optimal for the waveform being monitored before saving File1 sdf 235kB 0 298 589 867 126 360 563 T32 861 861 732 563 360 126 867 589 298 298 589 867 126 360 563 732 861 949 994 994 949 861 732 563 360 126 The file format is simple the data is listed in one large column The data shown above is part of the data for channel 1 clearly it is a sine wave The values are actual voltage readings that have been multiplied by 1000 to improve accuracy dividing by 1000 will convert back to the voltage for example 298 is 0 298 V 589 is 5 89V and the peak 1994 is 1 994 Volts EEE516J4 Honours Project Page 70 Chapter 7 The Scope Program Friday 21 June 2002 Final Report 7 9 Copying the Scope Display to the Windows Clipboard Colin K McCord The scope program has the ability to copy the scope displ
127. ave mode relays real time data through the internet using the TCP IP internet protocol the scope program on the other end master program receives the data and draws the waveforms as normal The scope program operating in slave mode has its controls disabled hence only the master scope program controls the PIC via the internet and via the slave scope program Problem the internet unless using broadband technology e g ASDL fibre optic is slow and commonly suffers from net congestion hence this feature is only useful for slow sampling rates unless storage mode is used For example an ECG signal only requires a sample rate of 120 Hz clearly the internet is capable of transferring this data in real time without any problems hence a doctor can remotely diagnosis an ECG signal in real time 13 9 Direct Modem to Modem Communication The master scope program dials the slave scope program and a direct communication link is established Once at direct modem link is established the communication protocol between the remote scope programs are exactly the same as with a direct like to the PIC hence the only operation of the slave program during this time is to relay the data from the PIC to the master scope program and visa versa EEE516J4 Honours Project Page 153 Chapter 13 Recommendations For Further Work Friday 21 June 2002 Final Report Colin K McCord This feature is easy to implement basically two additional functions is required on
128. aves which are difficult to monitor on a traditional oscilloscope due to the low frequencies involved Monitoring of an ECG signal again because this is such a low frequency traditional oscilloscopes would have difficultly monitoring such a signal ECG data could be logged and emailed directly to the doctor for diagnosis or perhaps real time TCP IP internet communication so that the doctor could remotely monitor the ECG signal in real time Monitoring of serial communications for example RS485 works on the principal of differential voltages between two cables twisted together hence the PC based oscilloscope could be used to view serial communications Two oscilloscope channels would be used and the PC software will automatically add the two channels together producing a virtual trace A B Note this PC based oscilloscope is also suitable for RS422 communication where there are separate transmit and receive lines 2 sets of differential twisted par cables hence all four scope channels can be used producing two virtual traces VC1 CH1 CH2 VC2 CH3 CH4 This monitoring of serial communication is extremely useful for educational usage e g learning how serial data is transmitted The PC based oscilloscope is ideal for demonstration purposes for example using data projector a class of student could be introduced to the oscilloscope with real waveforms being monitored signal generator or even a microphone for sound waves and displayed
129. ay 21 June 2002 Final Report Colin K McCord distorted recall that the pulse interpolator display type scope exe uses this required at least 10 sample cycle before a recognisable sinewave can be plotted J Scope Scopel E 0 x B Fie Edt y Toos Window je la x Vegoje BRES MTEFA Sample Disp Trig Time a Base v CHI fivolv v Figure 11 1 3e Screen dump of scope program sample rate 100Hz input wave 20Hz sinewave 0 5V 50Hz sinewave 0 5V connected to CH1 ANO see figure 11 1 3f Something real strange has happened here clearly the result of under sampling E lojx la x C He Edt y Toos Window Help Pi az a Rh sais re Sample Disp Trig Time Base V CHI hvolv woo ell oO Seer i wii ATT TONIT N E Figure 11 1 3f Screen dump of scope program sample rate 100Hz input wave 50Hz sinewave 0 5V Ready 100Hz sine wave 0 5V connected to CH1 ANO see figure 11 1 3g 10 divisions per cycle hence the calculated frequency of this waveform is 1 10 0 1 1Hz Clearly not correct the reason for this is that the EEE516J4 Honours Project Page 118 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord sample rate is not high enough and because sine waves are periodical it is possible to get false time base readings e g aliasing This will be a mayor concern at a later stage in the project and will be investigated
130. ay to the windows clipboard in the form of a bitmap the paste command in many Windows applications e g Word will import the scope image The user can use the right click menu as shown in figure 7 9a the edit menu the shortcut key Ctrl C or the copy toolbar icon f Scope Scopel B File Edit View Tools Window Help aR T COCE Grid Configuration Sidebar Debug LA Print Preview Print Setup nee AA aA INTE oA A FEET ft tT tT iA dt Se Se Pela Toda Tak ak ag MENEN AE ack atl ch hath ac NI T S Pee ae S H E E E A titer Figure 7 9b Scope display was pasted into this document from the clipboard This function copies the scope display to the clipboard EEE516J4 Honours Project Page 71 l0 x Sample Disp Trig Time 20ms DIV Base M CHI jiv Dv M CH2 2viDIv M CH3 fiv ov Vv sv DIV v Figure 7 9b is an image of the scope display that was copied into the Windows clipboard and pasted into Microsoft Word This document Only the scope waveforms are copied and not the entire scope display as was the case for the screen dump shown in figure 7 9a It maybe useful for other information like time base and channel voltage scales to be included This change is recommended and should be adopted sometime in the future because the scope waveforms are useless without knowledge of the time base and voltages scales us
131. count0 0 printf Interrupt _TO int_count0 INT_TIMER1 timerl interrupt Timerl ISR if int_count1 0 printf Interrupt _T1l int_countl INT_TIMER2 Timer2 ISR timer2 interrupt if int_count2 0 printf Interrupt _T2 int_count2 100 Forward declaration of functions void SetBaudRate main set_tris_e 0x17 TRISE SetBaudRate Setup timer0 RTCC int_count0 TO_INTS PER _SEC 2 set_rtcc 0 00010111 Every 0 5 seconds TO_INTS PER_SEC 2 called every time timerl overflows Every 0 25 seconds T1_INTS_PER_SEC 4 Every 0 1 seconds RE2 RE1 and REO TTL Inputs 0 5 seconds setup_counters RTCC_INTERNAL RTCC_DIV_256 enable interrupts RTCC_ZERO xe INTS PER_SEC 4 DIV_BY 1 Setup timer int counti TI setup timer 1 T set_timer1 0 enable interrupts INT_TIMER1 Setup timer2 int_count2 100 setup timer 2 T2 DIV BY 4 125 9 set_timer2 0 enable interrupts INT _TIMER2 enable interrupts GLOBAL while TRUE printf Main delay ms 1000 void SetBaudRate switch PORTE amp 0x07 Read 4800 9600 case case case case case case case case set_uart_s set_uart_speed set_uart_speed set_uart_ speed 0 peed 1 2 3 4 set_uart_speed 5 6 32768 38400 57600 11520 set_uart_spe
132. croelectronic Circuits Fourth Edition By S Sedra and Kenneth C Smith Publisher Oxford University Press ISBN 0 19 51 1690 9 1998 Data Communications for Engineers By Michael Duck Peter Bishop and Richard Read Publisher Addison Wesley Longman limited ISBN 0 201 42788 5 1997 The Complete C Reference By Herbert Schildt Published by McGraw Hill ISBN 0 07 882476 1 1998 PC based virtual test and measurement speed bench testing by Ivor Matanle AA Vol 15 No 4 1995 page 12 Digital signal processing by Andy McFarlane Journal Sensor Review Year 1997 Volume 17 Computer integrated documentation by Robert M Parkin and B S Dalay Industrial Management amp Chapter 14 Bibliography References Friday 21 June 2002 Final Report Colin K McCord J4 Anti aliasing analogue filters for data acquisition systems by Bonnie C Baker Microchip application note AN699 1999 J5 Using digital potentiometers to design low pass adjustable filters by Bonnie C Baker Microchip application note AN737 2001 J6 Implementing a bootloader for the PIC16F87X by Mike Garbutt Microchip application note AN732 2000 Web Sites W1 http www farnell com Farnell Online catalogue W2 Welcome to RS Online http rswww com RS Online Catalogue http www microchip com Microchip Website w3 MICROCHIP PIC datasheets and application notes http w
133. cuit 5 3 Analogue Circuit Diagram Mark 1 Figure 5 3a shows the circuit diagram for ensuring that the input voltage falls between zero and five volts The first op amp is designed to change the input voltage so that it does not go over 0 volts for example changes 1 to 1V to 0 to 2V The second op amp is configured in a negative amplifier mode to increase and EEE516J4 Honours Project Page 24 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord change 0 to 2V to 0 to 5V Note the third part with the two zener diodes is for protection the PIC ADCs may be damaged if input voltage is larger than 5 volts or smaller than 0 volts 5V O r 5V O R3 R4 R4 6k 1 2k 25k D1 12V 12V Asay 1 to 1v s gt input Ri K J R5 e ToADC 1 2k 10k z R6 R7 150 150 10 to 10V p 2V 12V sa D2 input ji 51v R1 R2 IC 741 IC 741 4k 8 2k 50 to 50V l a L input R2 R3 3 53k 56k Figure 5 3a Analogue circuit diagram Mark 1 14 12 2001 The variable resistors are for calibration 1 Ground 1 to 1V input calibrate using VR3 until 1 5V is outputted from the first op amp 2 Change VR4 until 2 5 volts is outputted from the output after the two zener diodes and the 2 150R resistors 3 Un ground 1 to 1v input and put in a voltage into input 10 to 10v an
134. cut off frequency Click here to visit Microchip s website for the MCP60x single supply op emp date sheet http www microchip com Circuit Topology Resistor Selection 4 7 pF xj A Sallen Key Standard 1 Resistors F l Ite rLab Reset Low pass B N b cerca Cerone MICROCHIP 613 Microchip zien te Butterworth Low Pass 1940 26 03 2002 Figure 3 4 3g Anti aliasing filter designed by the anti aliasing wizard 3 5 The PIC Microcontroller A PIC Peripheral Interface Controller microcontroller is an IC manufactured by Microchip S MICROCHIP These ICs are complete computers in a single package The only external components necessary are whatever is required by the I O devices that are connected to the PIC The traditional Von Neumann Architecture Used in 80X86 8051 6800 68000 etc is illustrated in Figure 3 5a Data and program memory share the same memory and must be the same width All the elements of the von Neumann computer are wired together with the one common data highway or bus With the CPU acting as the master controller all information flow is back and forward along these shared wires Although this is efficient it does mean that only one thing can happen at any time This phenomenon is sometimes known as the von Neumann bottleneck B3 amp Data Figure 3 5a Simplified illustration of the von Neumann architecture EEE516J4 Honours Project Page 12 Chapter 3 Fundamen
135. d calibrate using VR1 Disconnect that voltage 4 Puta voltage in to 50 to 50V and calibrate using VR2 Disadvantages of this circuit 1 Use of variable resisters much more expensive than fixed value resistors 2 No op amp protection if wrong input line is used e g 100V input on the 1 to 1V input 3 Ifan input line is used say 10 to 10V line and a device is connected to another line e g say 1 to 1V line there is nothing to stop current flow to the other device A diode could be used but there is a 0 7 voltage drop across the diode resistor values could be changed to compensate for this voltage drop 4 Range not microcontroller controlled 5 3 1 Simulation of the Circuit using Electronic Workbench From figure 5 3 1a using 1 to 1V input it is clear that a 1 to 1V sine wave input has been applied and the output is 0 to 5V Figure 5 3 1b clearly shows an input of 0 5v to 0 5v and an output of to 1 25V to 3 75V Notice the input and output waveforms are the same phase and polarity Oscilloscope aj 444 6605 ne 999 0396 nv at 4 9939 Y Figure 5 3 1a Screen dump of oscilloscope CH A Input CH B Figure 5 3 1b Screen dump of oscilloscope CH A Input CH B Output Output EEE516J4 Honours Project Page 25 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord From figure 5 3 1c using 10 to 10V input it is clear that a 10 to 10V sine wa
136. d to filter out frequencies above half the sample rate Instead of filtering out aliased signals a hardware circuit can be used to detect the actual frequency of the waveform being monitored The PIC can then transmit the actual frequency of the waveform to the scope program The scope program can then software calculate the frequency of the sampled waveform and if the two frequencies do not match the scope program knows that the sampled waveform is an alias f f 256 OV OV OV Divide CH1 m T by mmPC 256 Figure 13 11a Frequency detection circuit Figure 13 11a shows how a simple detection circuit could be made A Schmitt Triggered inverter is used to generate squarewaves at the same frequency of the original signal which is then passed through a frequency divider circuit which decreases the frequency by 256 The output of the detection circuit is connected directly to a Schmitt triggered input on the PIC which is configured to interrupt the PIC Using a real time timer the frequency of the signal can be calculated and transmitted to the scope program vcc vcc vcc vcc vec vec vec vec vec SET SET SET ET SET ET ET SET ejJ Qm eJ Qm J3 Qm eg Qm eJd OAM eg OAM Igi QO ed AM HNI QA ar Q ar a Ka H KA 12 14 18 116 132 132 164 1128 1256 F
137. day 21 June 2002 Final Report Colin K McCord The system can be powered from a battery source e g PP3 9V or a DC power supply e g 12V It has been decided not to design a complete power supply unit from scratch but to use commercially available units It is important to remember that voltage regulators are not efficient and as the input voltage increases the least efficient they become energy is lost in the form of heat A heat sink is normally required to keep the chip within its maximum operational temperature 5 6 Cost of Components All order numbers refer to Farnell catalogue Digital Circuit Order Cost Number Item Qty Each Cost 325 5573 PIC16F877 20 P Microcontroller 1 7 09 7 09 407 150 MAX232CPE RS232 Line Buffer 1 2 40 2 40 115 873 HT6264 70 8k x 8 CMOS SRAM 70ns acc 1 1 65 1 65 170 234 20MHz Crystal A147C 1 0 75 0 75 747 014 33pF Ceramic Capacitor 2 0 13 0 26 664 315 1uF 25V Electrolytic Capacitor 5 0 27 1 35 543 380 1kQ Metal Oxide Film 1 Resistor 3 0 02 0 06 134 3040 40 way dip docket 1 0 33 0 33 134 3038 28 way dip socket 1 0 22 0 22 134 2988 16 way dip socket 1 0 12 0 12 780 091 4 way dip switch 1 0 40 0 40 150 812 9 way D type Socket 1 0 55 0 55 Total 15 18 Analogue Circuit Mark 2 Order Cost Number Item
138. dium The application must be user friendly and should be Windows 95 98 NT ME 2000 XP compatible Design PIC embedded software for reading the ADC at a certain sample rate and transferring the data to the PC in real time A basic simulation program for simulating the PIC microcontroller allowing the communication protocol to be tested before the hardware has been constructed This simulation program should be able to simulate a waveform at an adjustable frequency hence making it possible to easily test the graphic display and triggering methods in the windows based oscilloscope program Demonstrate the entire system working together as a basic real time low frequency oscilloscope lt 5 KHz 2 2 Further Development 1 3 Add storage oscilloscope functionally to the low frequency lt 5 kHz PC based real time oscilloscope specified in the core objectives increasing it s sampling frequency to at least 20 kHz hence making it possible to monitor sound waves using this oscilloscope Using external ADC with direct memory access explain how it would be possible to monitor high frequency waveforms storage oscilloscope gt 3MHz even if the transport medium between the PIC microcontroller and the PC is much slower than the sample rate Investigate how far this storage technique can be pushed what are the limits EEE516J4 Honours Project Page 4 Chapter 2 Design Specifications Friday 21 June 2002 Final Report Colin K Mc
139. ducts for example it is a quad channel oscilloscope and commercial quad channel oscilloscopes are extremely expensive including commercial PC based scopes It is foreseen that the oscilloscope could be available in kit form were customers would buy the PCB components PCB board case leads and build the scope themselves this is a real option as the hardware circuitry is extremely simple and this would reduce product costs making the product more economical Core objective design and construct the hardware required for data acquisition clearly this objective has been successfully achieved The PIC16F877 is use this microcontroller is extremely powerful running at a 20MHz it has a built in 10 bit ADC which can be connected to anyone of 8 input pins and a hardware UART suitable for RS232 communications Evidently the analogue circuit was proven to work as it was simulated in electronic workbench and then in the laboratory using real components Obviously the analogue circuit needs to be redesigned so that the PIC microcontroller can control the input voltage range as stated in this report there are a couple of different ways of achieving this The first analogue switches could be used to switch in different resistor values to the op amps hence changing the gain e g MAX4066 or MM74HC4066 The second and more likely option is the use of digital potentiometers resistance controlled by microcontroller to change the gain of the op amps
140. e Sd n amp SView gt x infile Sd n amp SView gt y infile d n amp SView gt m_nCH1POS r fscanf infile d n amp SView gt m_nCH2POS fscanf infile d n amp SView gt m_nCH3POS fscanf infile d n amp SView gt m_nCH4POS fscanf infile d n amp SView gt m_nCH1 Offset fscanf infile d n amp SView gt m_nCH2_Offset fscanf infile d n amp SView gt m_nCH3_Offset fscanf infile d n amp SView gt m_nCH4_Offset fscanf infile d n amp pApp gt m_nInputRange fscanf infile d n amp pApp gt m_nSampleMode fscanf infile d n amp m_bCH1 ENABLE fscanf infile d n amp m_bCH2 ENABLE fscanf infile d n amp m_bCH3 ENABLE fscanf infile d n amp m_bCH4 ENABLE fscanf infile d n amp m_TimeBaseSelection fscanf infile d n amp m_nCH1l_VOLTS fscanf infile d n amp m_nCH2_VOLTS fscanf infile d n amp m_nCH3_VOLTS fscanf infile d n amp m_nCH4 VOLTS o infile d n amp m_nTrigger infile d n amp m nTriggerType infile d n amp SView gt m_ColorGridBackGround infile d n amp SView gt m_nRefreshRate fscanf fscanft fscanf fscanf infile d n amp pApp gt m_SampleRateSelection fscanf fclose infile UpdateAllViews NULL HINT OPEN NULL SView gt Prepare
141. e screen Before hand it was not known how to achieve this hence new knowledge has been acquired Clearly the graphical display works well and is extremely flexible e g auto resizable user adjustable grid resolution and colour The graphical display is designed to display the waveforms as it would appear on a traditional oscilloscope The standard resolution allow this can be modified up to 99 by 99 is 10 by 8 squares that s 100 by 80 dots and has a user configurable trigger software trigger This triggering operation took some time to implement there were many problems at first but eventually most of the problems were ironed out a view still remain e g unstable CH2 trace when triggering off CH1 if waveforms are unrelated The user can select from a range of different triggering methods e g low to high high to low level or edged etc and which channel they which to trigger on e g 1 2 3 4 including impendent triggering where each channel is trigger independently of each other this feature is not possible on traditional analogue oscilloscopes it is not sure how useful this feature is buts its another one of those features Bells and Whistles that gives this project an edge over existing similar products Notice the split screen feature were the graphical display is on the left hand side and the controls are on the right just as they would appear on a traditional oscilloscope It is clear that the scope program can dis
142. e g 01 df Calculated CRC Hex 81E1 Total Frame Length Dec 4 Sending RTU Frame HEX 12 81 El Finished Sending RTU Frame User manually enters a frame of data in hexadecimal once OxDF is entered the program assumes that the frame is complete and calculates the 16 bit CRC which is added to the end of the frame The whole frame is then transmitted through RS232 This function can be used to generate test storage mode frames when testing the scope program and test control protocol frames for manually controlling the PIC 4 Manual RTU frame no CRC Manual RTU frame no CRC Enter RTU frame in byte s enter DF when finished RTU frame 0 e g 01 1 RTU frame 1 e g 01 2 RTU frame 2 e g 01 df Total Frame Length Dec 2 Sending RTU Frame HEX de Finished Sending RTU Frame User manually enters a frame of data in hexadecimal once OxDF is entered the program assumes that the frame is complete and transmits the frame This function can be used to generate test real time frames 5 Simulated Random Noise Simulated Random Noise No delay between bytes Aart uh Random delay 0 to 100ms between bytes hit 2 User sets delay in milliseconds SENTE S Cancel Return to Main Menu hit 4 This function simulates random noise there are three formats to choose from The first transmits random bytes through RS232 continuously with no delay bet
143. e hardware UART is being used hence the PIC can sample the next reading while the UART is transmitting the last reading Note if alternating sampling not chop is used the sample rate will not decrease with the number of channels for example figure 6 5a states that the maximum sample rate for one channel at 115 kbps is 5 75 KHz if alternate mode is used this maximum sampling rate still applies even if 4 channels are enabled Recall that alternate mode is only useful for periodical waveforms EEE516J4 Honours Project Page 33 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord The PIC16F877 has an 10 bit ADC if speed is important the resolution could be reduced to 8 bits when sampling four channels For example channels 1 2 3 4 are always transmitted along with sync frame 5 bytes for 4 channels 80 efficient hence the following sample rates are now possible Sample Rate 8 bit ADC Four Channels ers Number of Max Sample Rate Max Sample rate Max Sample Rate at Channels at 115 Kbps at 56 6 Kbps 33 6 Kbps 1 2 3 KHz 1 132KHz 672 Hz 2 2 3 KHz 1 132KHz 672 Hz 3 2 3 KHz 1 132KHz 672 Hz 4 2 3 KHz 1 132KHz 672 Hz Figure 6 5b Table showing the theoretical real time sample rates chop 8 bit ADC Another possible method for increasing real time sampling rates is to use two or more serial links For example most PCs have two RS232 ports more can be added by
144. e program sample rate 1 000Hz input wave 50Hz Page 123 11 2 3f Screen dump of scope program sample rate 1 000Hz input wave 100Hz Page 124 11 2 3g Screen dump of scope program sample rate 1 000Hz input wave 200Hz Page 124 11 2 3h Screen dump of scope program sample rate 1 000Hz input wave 500Hz Page 125 11 2 3 1a Screen dump of scope program sample rate 2 000HZz input wave 10Hz Page 125 11 2 3 1b Screen dump of scope program sample rate 2 000HZz input wave 20Hz Page 126 11 2 3 1c Screen dump of scope program sample rate 2 000Hz input wave 50Hz Page 126 11 2 3 1d Screen dump of scope program sample rate 2 000Hz input wave 100Hz Page 127 11 2 3 1f Screen dump of scope program sample rate 2 000Hz input wave 200Hz Page 127 11 2 3 1g Screen dump of scope program sample rate 2 000HZz input wave 500Hz Page 128 11 2 3 1h Screen dump of scope program sample rate 2 000Hz input wave 1 000Hz Page 128 11 2 3 1i Screen dump of scope program sample rate 2 000Hz trianglewave Page 129 11 2 3 1j Screen dump of scope program sample rate 2 000Hz squarewave Page 129 11 2 3 2a Screen dump of scope program sample rate 5 000HZz input wave 50Hz Page 130 11 3 1a Screen dump of scope program Dual Channel Test Page 132 11 3 3a Test Circuit Diagram 3 Page 146 EEE516J4 Honours Project Page X Table of Figures Friday 21 June 2002 Final Report Colin K McCord 1 0 PROJECT
145. e program is limited to 256 colours this works Figure 7 13b shows the display properties in Window XP note when running in 16 bit colour mode the scope program runs smoothly 7 14 Additional Video Card Features That May Explain Low CPU Usage The scope program when running on the desktop system running Windows 2000 800MHz AMD processor 256MB PC133 RAM and Creative Labs 3D Blaster GeForce 3 Titanium 200 64MB 3D accelerator video card uses less than 2 of the CPU load But when tested on a UUJ computer lab 6C49 computer Intel P4 1 5GHz 256MB RAM Windows 2000 it was shocking to note that the scope program was using 10 of the CPU that s 5 times more than that of the 800Mhz desktop system even though its clock speed is almost half the speed OK AMD processors are faster than Intel s e g 8300MHz AMD is equal to 1GHz Intel P4 but not by this amount so something else much be making up the difference Clearly the video card must be accelerating windows graphics as well as direct X and open GL and may be the reason for the low CPU usage on the desktop when compared to the laptop and university machines It was noticed that Geforce 3 video card drivers have added new features to windows that makes it probable that the video card is hardware accelerating standard windows operations Minimize O Maximize X Close Alt F4 Maximize to desktop Send window to Send application to af seam xil EAE Wor artti Aways on top
146. e to setup the scope program as a master dial user configurable number real time storage and control protocols unchanged and the other to setup the scope program as slave wait for connection and once connection is established rely data from the PIC to the master visa versa 13 10 Printing of Scope Display The scope program should be able to print the scope display directly to the system printer Some work has already been done in this area for example configuration of the printer is currently possible and code for printing exists along with a header and footer The only thing that remains to be completed is the drawing of the scope display clearly the simplest way of achieving this is by copying the bitmap directly to the printer output CDC but this is not ideal as this would not contain any information about the selected time base voltage scales this is essential and the screen resolution source of bitmap could be much lower this is likely than that of the printer hence producing a poor quality printout Obviously the grid and traces need to be redrawn on the printer output CDC this is simple as the code is exactly the same as that which draws the grid and traces to the screen hence put cut amp paste to good use allow the size of the page is different to that of the screen hence don t forget to detect the resolution of the printer 13 11 An Alternative Method for Dealing with Aliasin Generally a low pass filter is use
147. e waveform display and selecting Sidebar or by using the View menu see Figure 7 0c Gid Config ration Sure At present four channels has been implemented Data can be received in the Z Sidebar cres real time mode using the RS232 serial port The real time mode B Copy Ctrl C communications were first tested using the PIC simulator program where Enable Communicatons Ctrl E sinewaves squarewaves and random waves at variable frequencies and Boreas ore amplitudes were successfully sent to the scope program which correctly i displayed the waveforms Desktop PC running scope exe linked to Laptop eae a running sim exe via RS232 Null mode cable Once the program was working Print Setup Ctrl4R on the simulator it was tested using a PIC sampling real waveforms the scope Fe Exit cix program successfully displayed these waveform correctly see chapter 11 Figure 7 0b Right click menu testing for test results at various stages of development EEE516J4 Honours Project Page 43 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord Scope Untitled x CT 5 x Fle Edit View Took Window Help Fle Edt View Toos window Help iF OoNsAeesARalhagte Pr Ce MsaeY BOATS SHE Ready NUM 7 Ready NUM Figure 7 0c Screen dump of scope exe with slide bar hidden Figure 7 0d Screen dump demonstrating auto resize Notice the small red triangle at the left of the graphical display this tri
148. eal time frame structure is as efficient as possible Unmistakably that s the reason why the real time structure does not have a check sum or CRC Clearly this causes a problem however the frame structure is designed in such as a way that some errors can be detected but the cable between the MAX232 buffer and the PC will be high quality shielded cable short length and errors should not occur that frequently anyway If one or two readings are lost corrupted it is clear the appearance of the waveform will not be affect too much as there are at least 10 readings per cycle and because it is real time the screen is continuously refreshed hence the error will probably not stay on the screen for very long until it is replaced by new readings Clearly a Windows based C application capable of displaying low frequency waveforms from four channels simultaneously in real time has been successfully designed implemented and proven The scope program graphically displays waveforms without flicker it has a good user interface that is easy to use and directly communicates with the PIC There were many problems during development some of which have been described in detail in this report e g Windows 95 98 ME compliably problem These problems are all part of the learning curve for example one of the early problems was drawing the traces without flicker and this problem was solved by drawing the trace to a memory DC bitmap and then quickly coping this to th
149. ed Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord void CScopeView OnEditCopy aii i i ail i ee el ee ia a a See oS Sao el Fuction void CScopeView OnEditCopy Description Copies the scope display to the Windows clipboard Return Void Date 15 02 2002 Verison 1 0 By Colin McCord seeetceceaecesteocete ect se soso Sc sc esc ScG cee Se See oe Se eee CRect rect CClientDC dc this CDC memDC CBitmap bitmap GetClientRect amp rect Create memDC memDC CreateCompatibleDC amp dc bitmap CreateCompatibleBitmap amp dc rect Width rect Height CBitmap pOldBitmap memDC SelectObject amp bitmap Fill in memDC memDC FillSolidRect rect dc GetBkColor Redraw grid to memory DC if memDC GetSafeHdc NULL first drop the grid on the memory dc memDC BitB1lt 0 0 m_nClientWidth m_nClientHeight amp m_dcGrid 0 0 SRCCOPY now add the plot on top as a pattern via SRCPAINT works well with dark background and a light plot memDC BitBlt 0 0 m_nClientWidth m_nClientHeight amp m dcCH1 0 0 SRCPAINT SRCPAINT memDC BitBlt 0 0 m nClientWidth m nClientHeight amp m_dcCH2 0 0 SRCPAINT SRCPAINT memDC BitBlt 0 0 m nClientWidth m nClientHeight amp m_dcCH3 0 0 SRCPAINT SRCPAINT memDC BitBlt 0 0 m nClientWidth m nClientHeight
150. ed set_uart_speed set_uart_speed dip switc 0 0 25 second T1 INTERNAL 0 1 second interrupt every Ims 1 second delay hes and setup baud rate break break 14400 19200 break break break break break break 65536 gt 0 EEE516J4 Honours Project Page 103 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord 10 8 Mark 8 c Real Time Mode Dual Channel Fixed Delay Adjustable Baud Rate Same as mark6 c expect that instead of just sampling channel 1 the program chops between channel 1 and channel 2 see figure 10 8a This program is used to test the scope program in dual trace mode triggering methods and stability of a trace when the other is being used as the trigger Note the configuration of the ADC has been modified so that 32Tosc is used and not the internal RC oscillator The reason for this change is that the PIC16F877 datasheet states When the device frequencies are greater than 1MHz the RC A D conversion clock source is only recommended for sleep operation Setup RS232 Convert reading Convert reading Transmit Hardware UART gt Read ADC m into real time into real time real time frame baud rate 9600 frame structure frame structure Setup ADC 10 bits right 20ps delay S
151. ed into PIC using Microchip MPLAB This program is a little more complex than the first two basically it reads ADC CH1 ANO and transmits the result through RS232 using the real time frame format every 10ms sample rate of 100Hz The scope exe version 1 023a program was used to display the real time frames graphically and a calibrated digital signal generator was use to generate a 0 to 5V e g 5V peak to peak with a DC offset of 2 5V sinewave at a variable frequency e g 2Hz 5Hz 10Hz etc Portable commercial digital storage oscilloscope was used to make sure that the signal generator output was 0 to 5V as values outside this range would damage the PICs ADC analogue circuit not constructed at this stage EEE516J4 Honours Project Page 115 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Note Sample rate 100Hz 100 horizontal samples are displayed on the scope display 10 samples per division Hence scope time base is 0 1 seconds per division that s 10Hz Note time base is fixed on this version of the scope program 1Hz sinewave 0 5V connected to CH1 ANO see figure 11 1 3a 10 division per cycle hence the calculated frequency of the waveform is 1 10 0 1 1Hz Scope Scopel 5 x J Fie Edit View Tools Window Help la x EH GOormeioiai rte Sample Disp Trig Ti Base Ready Figure 11 1 3a Screen dump of scope program sample rate 100Hz input wave 1Hz s
152. een dump of the screen using the windows clipboard and exporting the scope display to a bitmap are useful for importing an image of the scope display into applications like Microsoft Word but these images cannot be manipulated e g channel time base The saving and opening of the scope data is far more useful for keeping a record of an event for analysis at a later time because the scope controls are fully functional for example time base center points of waveforms channel offset grid resolution and enable disable channels are adjustable loj x Bile Edit View Tools Window Help laj x i Ge Nsw t nRa EEE Sample Disp Trig Time f20mS DV Base M CHI sv DIV CH2 2v0 V CH3 lev DIVv Vv sv DIV E Figure 7 8a Scope data saved to File1 sdf Scope V1 040a 07 04 2002 sdf is the file extension used it is short for Scope Data File If the user clicks on menu item File Save the following function is called void CScopeDoc OnFileSave 07 04 2002 by CKM if _access m_ Filename 0 1 OnFileSaveAs else Save Basically the OnFileSave function calls the OnFileSaveAs function if there is no current file untitled or the Save function to save changes to the current file EEE516J4 Honours Project Page 65 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord If user clicks on menu item File Save As
153. een dumps of scope exe demonstrating different display settings Page 46 7 0i Sample tab of controls dialog Page 46 7 0j Grid configuration dialog box Page 47 7 0k Screen dump of scop exe demonstrating multiple scope views Page 47 7 01 Screen dump of about dialog Page 48 7 0m Screen dump of configuration dialog Page 48 7 0n Screen dump of debug menu Page 48 7 00 Screen dump of advanced sampling control panel Page 48 7 2a Grid layout Page 50 7 5a Screen dump of the configuration dialog box Page 60 7 56 Screen dump of windows registry Page 60 7 8a Scope data saved to File1 sdf Scope V1 040a 07 04 2002 Page 65 7 8b Windows standard CFileDialog Box Page 66 7 8c Example File1 sdf has been opened Page 69 7 8d Demonstrating aliasing by selecting a out of range time base Page 69 7 9a Screen dump demonstrating how to copy the scope display to the clipboard Page 71 7 9b Scope display was pasted into this document from the clipboard Page 71 7 10a User clicks Export Page 73 7 10b Save dialogue box appears Page 73 7 10c Screen dump of exported file scope bmp Page 73 7 11a Microsoft Word XP file menu Page 77 7 11 Scope Ver1 046a file menu Page 77 8 0 The simulator Program Pages 86 to 89 8 0a Screen dump of sim exe V1 007a 29 03 2002 Page 86 8 0b Screen dump of options dialog in sim exe Page 87 8 0c Screen dump of about dialog in sim exe Page 87 10 0 PIC Software Development Pages 96 to 113 10 1a Mark 1 flowchart Page 96 10 2
154. efresh rate is that specified by Windows which for a modern PC is above 100Hz for a CRT display and 50 60Hz for a TFT display Note the lower this refresh rate update rate the more processor hungry the scope program becomes A 200 milliseconds update rate will require a PC running at a minimum of 200MHz and at 50 milliseconds update rate will probably require a PC running at least 800MHz to run smoothly depending on the selected grid resolution and type of video card in the system hardware acceleration The scope program was designed so that multiple scope windows can be displayed each one with its own selected channels enabled impendent triggering time bases and scales But it was not sure how useful this feature might be and it may have caused problems during the development process hence it was considered this feature may be dropped on the finished application Fortunately this did not cause as many problems as first expected and it was decided to keep this feature as it may have some use for specialist applications and it s another one of those features Bells and Whistles that sets this project apart from other similar products on the market Be Edt yew Toot pow Hap Sampie Time o Baro Fon Pr EEE516J4 Honours Project Figure 7 0k Screen dump scope exe demonstrating multiple scope views Window s screen resolution was 1600 x 1200dpi alaj x Page 47 Chapter 7 The Scope Program
155. emory 7 of total and the raw calculation CRC only used 116 words 1 of total hence the CRC lookup table uses 6 times more program memory than the raw calculation version Obviously the reason for this is because the lookup table CRC uses 512 words of program memory for its lookup table Evidently if speed is important and there is plenty of program memory available the lookup table CRC is the one to use But if program memory is at a premium and speed is not important the raw calculation CRC is the one to use EEE516J4 Honours Project Page 41 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord 6 9 Frame Structure Control Protocol SOF Start of Frame SETUP_REG1 SETUP_REG2 RATE CRC low byte CRC high byte Figure 6 9a Frame structure control protocol b7 b6 b5 b4 b3 b2 b1 bO Du ei ro 1 os es eaTer SETUP_REG1 M 0 Real time Mode M 1 Storage Mode R1 RO RATE Multiplier o 0 xXteg1t25Hz O 1 X10 e g 10 to 2550 Hz 1 0 X100 e g 100 to 25 500 Hz 1 1 X1000 e g 1 kHz to 255 kHz 0 Sample when PIC is awake 1 Sample when PIC is sleeping Figure 6 9a shows the frame structure for the control protocol each field is 1 byte in size Since this control protocol is used to directly control the PIC it is important that the PIC is able to check the frame before processing the information
156. er nIDEvent The first thing to note is that the timer is stopped while executing the OnTimer function and started again once the redraw is finished The reason for this is to reduce the chance of the program locking up because of accumulating delays caused by the refresh rate selected by the user being shorter than the time required to redraw the display In reality the true refresh rate is not the rate specified by the user but the time taken to redraw the display plus the rate specified by the user this insures that the program does not lockup especially when running on slow PCs lt 200 MHz Function trigger is called to find the trigger point for all channels then the channel voltages scales are set to that selected by the combo box then the channel traces are drawn This function calculates the trigger point void CScopeView Trigger int a pDoc gt m_nTriggerOffsetLevel CHL Tigger for int i 1 i lt 1000 i if pDoc gt m_nTriggerType 0 if pDoc gt m_nTriggerFormat 1 a pApp gt m_nCH1Volt i 1 Edge Triggered trigger POS to NEG if pApp gt m_nCH1Volt i gt a amp amp pApp gt m_nCH1Volt i 1 lt a m_nTriggerCH1 i Disable trigger for scroll mode if pApp gt m_nSampleMode 0 m nTriggerCH1 0 disbale trigger i 1001 break else if pDoc gt m_nTriggerFormat 1 a pApp gt m_nCH1Volt i 1 Edge Triggered trigg
157. er NEG to POS if pApp gt m_nCH1Volt i lt a amp amp pApp gt m_nCH1Volt i 1 gt a EEE516J4 Honours Project Page 53 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord m_nTriggerCH1 i Disable trigger for scroll mode if pApp gt m_nSampleMode 0 m nTriggerCH1 0 disbale trigger i 1001 break NOTE channel 2 4 trigger point calculated the same way as channel 1 switch pDoc gt m_nTrigger case 0 trig on CH1 m_ nTriggerCH2 m _nTriggerCH1 m nTriggerCH3 m _nTriggerCH1l m_ nTriggerCH4 m_nTriggerCH1 break case 1 trig on CH2 m nTriggerCH1l m nTriggerCH2 m_ nTriggerCH3 m_nTriggerCH2 m_ nTriggerCH4 m nTriggerCH2 break case 2 trig on CH3 m_ nTriggerCH1l m _nTriggerCH3 m nTriggerCH2 m _nTriggerCH3 m_ nTriggerCH4 m nTriggerCH3 break case 3 trig on CH4 m_ nTriggerCH1l m nTriggerCH4 m_nTriggerCH2 m nTriggerCH4 m_nTriggerCH3 m_nTriggerCH4 break Detection of the trigger point is simple basically the program scans the array and looks for a high to low or a low to high edge The location of which is stored m_nTriggerCH1 4 this producer is carried out for all four channels If a specific channel is selected as the trigger the trigger points of the other channels are made equal to the trigger point of the selected channel A memory DCs and pen is required for each trace C
158. errupt_T2 Interrupt_Tl In terrupt_T2 Interrupt_T2 Interrupt_T2 Interrupt_TO Interrupt_Tl Interru pt_T2 Interrupt_T2 Main Interrupt_T2 Interrupt_Tl Interrupt_T2 Inter rupt_T2 Interrupt_TO Interrupt_Tl Interrupt_T2 Interrupt_T2 Interrupt_ T2 Interrupt_Tl Interrupt_T2 Interrupt_T2 Interrupt_T2 Interrupt_TO Interrupt _Tl Interrupt_T2 Interrupt_T2 Main Interrupt_Tl Interrupt T2 Interrupt_T2 Interrupt_T2 Interrupt_T0O Interrupt_Tl Interrupt_T2 Int errupt_T2 Interrupt_T2 Interrupt_Tl Interrupt_T2 Interrupt_T2 Interrup t_T2 Interrupt_TO Interrupt_Tl Interrupt_T2 Interrupt_T2 Interrupt Tl Main Interrupt_T2 Interrupt_T2 Interrupt_T2 Interrupt_TO Interrupt_T 1 Interrupt_T2 Interrupt_T2 Interrupt_T2 Interrupt_Tl Interrupt_T2 1 nterrupt T2 Interrupt TO Interrupt Tl Interrupt T2 Interrupt T2 Interr UPET A se Clearly the timer interrupts are working note that there were 11 Interrupt_T2 between Main hence timing is slightly out should be 10 Timer 1 and Timer 0 timing were correct allow it is important to realise that the main program uses a loop delay this delay does not take into account the delay taken to process the interrupt hence this may explain way timer 2 appear to be slightly out 11 2 5 Conclusion Clearly the four tests that were carried out were successful Allow problems occurred when sampling at
159. es from frequencies of 0 1 Hz to 10 MHz Users can select a flat passband or sharp transition from passband to stopband Options such as minimum ripple factor sharp transition and linear phase delay are available Once the filter response has been identified FilterLab generates the frequency response and the circuit For maximum design flexibility changes in capacitor values can be implemented to fit the demands of the application FilterLab will recalculate all values to meet the desired response allowing real world values to be substituted or changed as part of the design process Further consideration is given to designs used in conjunction with an analogue to digital converter A suggested filter can be generated by simply input ting the bit resolution and sample rate via the Anti Aliasing Wizard This eliminates erroneous signals folded back into the digital data due to the aliasing effect W3 For example design a Butterworth anti aliasing filter using the FilterLab anti aliasing wizard Figures 3 4 3a to figures 3 4 3f show step by step how to configure the anti aliasing wizard EEE516J4 Honours Project Page 10 Chapter 3 Fundamentals Friday 21 June 2002 Final Report ES gt microchip FilterLab Welcome to the Antr aliasing wizard This wizerd will assist you in determing the filter required to meet your ant ealaising needs 4 Microchip FilterLab Emer the Sampling frequency of your A D
160. es per cycle before a recognisable sine wave can be plotted Pulse interpolation provides a good general purpose display where the waveform under investigation is known to be smooth and generally of a sinusoidal shape Sine interpolation provides a good representation with as few as 2 5 samples per cycle However it should not in general be used for pulse waveforms as here it can introduce ringing on the display which is not present on the actual waveform EEE516J4 Honours Project Page 6 Chapter 3 Fundamentals Colin K McCord Final Report Friday 21 June 2002 7 TE TTT Poi 7 REN TT iS rps pap porat oe paser e e e f dig f it 2 Ca e EEES s oO aoe ee 0 o e ze ee Ee F E a i ries Sal CES Sg Ls CR Ty S ze em m en S aaa 8 3 oome e aTa poparen ans apai r posme ee ene ao aca eS pre Oma I J LETN Ta a ee TITTY Te ant Pon E j Wenenes PRERE TAEAE IED uE PEON ae T f f o gt CTs Torere f t f 3 F Tes meea a ii 2 meeer menmi ii 5 Cas aoai Tk Se es CCRC CBee ys CS Ca i FT CT Ce snene fangs g oa a iia Mie a e e CO 2 aL 1 5 s ENS ee SORE URERE TERE 2 t Etura ad OSes Cae Te Cees ee H E eersten HAE i w na ait 1 es 3 e FF wn i n T Sao in TT CE a RNG CE CE T oA 7 FEELT Ti ET en et e EE TEs me A tc os S 3 saa Ea z a porre ea g e a 5 AE i 3 ne lt erm zs ae
161. eturn to full speed after waking up Recall that sampling when the PIC is sleeping results in more accurate ADC readings less noise SETUP_REG2 is shown in figure 6 9c this register specifies the number of samples to be stored into RAM storage mode only chop or alternate mode Chop Mode Alternate Mode v1 VO Voltage Input Range 0 0 1 to 1V 1 2 5 to 2 5V 0 5 to 5V 1 10 to 10V 0 25 to 25V 1 50 to 50V 0 100 to 100V 1 250 to 250V Reserved for future use Figure 6 9c SETUP_REG2 and the voltage input range change gain of op amps Notice that b7 is marked as R this means that the bit is not used and is reserved for future use Field RATE in figure 6 9a specifies the required sample rate this figure is multiplied by the RATE multiplier that is specified in SETIP_REG1 figure 6 9b For example if RATE is 100 and RATE multiplier is 10 R1 0 RO 1 the specified sample rate is 100 x 10 1000 Hz EEE516J4 Honours Project Page 42 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord 7 0 THE SCOPE PROGRAM This Windows based program graphically displays waveforms without flicker it has a good user interface that is easy to use and directly communicates with the PIC RS232 transport medium has been selected this medium is easy to program reliable and every PC comes with at least one RS232 port But it is slow and will limit the maximum sampl
162. etwork maintenance feature phones and field upgradeable pointing devices PIC16F877 has 33 I O pins and is available in the following package options 40 PDIP P 44 PLCC L 44 PQFP PQ and 44 TQFP PT W3 Four of the PICs ADC pins are used for data acquisition a MAX232 buffer is used to convert the TTL serial logic of the PICs UART to the correct RS232 format Additionally an analogue circuit is required to make sure the input voltage to the PICs ADC falls between 0 to 5V Figure 5 0a illustrates an 10 to 10V sine wave where the 10V peak is reduced to 5V ADC Value is 1024 OV is represented by 2 5V ADC Value is 512 and 10V is represented by OV ADC value is 0 i e Bipolar This could be achieved using two 741 op amps and a couple of diodes could be used for protection as the ADC cannot handle voltages outside its range damage the PIC 10V 5V x Jm gt gt Circuitry 10V Figure 5 0a Illustrates the operation of the analogue circuitry A 5V voltage regulator 7805 is used to power the circuit hence there is a large DC input range of 7 to 20V This means that a standard DC power supply 7 to 20VDC or a battery source e g 9V PP3 can be used to power circuit 5 1 Simplified Block Diagram Figure 5 1a shows a simplified block diagram of the overall system It is clear the PIC is connected to a MAX232 buffer which is connected to the PCs RS232 port Notice that the clock is specified as 20MHz this
163. f a low cost PC based quad channel real time storage oscilloscope This project attempts to achieve the same functionality as a traditional oscilloscope using a PIC microcontroller for data acquisition including appropriate analogue circuitry which transfers the data to the PC via RS232 A Microsoft Windows based software application will then display the waveform as it would appear on a traditional CRT oscilloscope This software application will have additional features not present on a traditional oscilloscope e g printing saving waveforms with greater flexibly as additional features can be added as their developed without the need for new hardware The digital based oscilloscope should display very low frequency waveforms in real time but for higher frequency waveforms it is necessary to read a finite number of samples storing them into RAM Once the memory is full or the preset number of samples has been reached the PIC will stop sampling and transfer the data to the PC when ACK acknowledgment is received from the PC the PIC will start sampling again This is known as a Storage Oscilloscope but there are disadvantages e g it s impossible to continuously monitor a waveform in real time for more than the amount of samples that can be stored into the buffer as there would be gaps in the data Main Advantages of Digital over Analogue Scopes e The ability to observe slow and very slow signals as a solid presentation on the
164. g 3 poles hence 3 order Generally the greater number of poles a filter has the smaller the transition bandwidth Ideally a low pass anti aliasing filter should perform with a brick wall style or response where the transition band is designed to be as small as possible Practically speaking this may not be the best approach for an anti aliasing solution With active filter design every two poles require an operational amplifier For instance if a 32 order filter is designed 16 operational amplifiers 32 capacitors and up to 64 resistors would be required to implement the circuit Additionally each amplifier would contribute offset and noise errors into the pass band region of the response J4 3 4 2 Typical Low Pass Filters The Butterworth Bessel and Chebyshev are the three most popular filter designs other filter types include inverse Chebyshev Elliptic and Cauer designs See reference B4 for detailed information on designing various types of filters including Butterworth and Chebyshev Butterworth Filter The Butterworth filter is by far the most popular design used in circuits This filter exhibits a monotonically decreasing transmission with all the transmission zeros at w making it an all pole filter Therefore the transfer function of a Butterworth filter consists of all poles and no zeros and is equated to Vour _ eT eo 5 3 4 2 1 Vin amp amp s as a 8 a S 4 S 1 Note denom
165. g frequency hence an external Flash ADC with direct memory access will be required to produce a high performance digital storage oscilloscope e g AD9070 10Bit 1OOMSPS ADC There are commercial digital scopes but they are expensive and have small displays unless they have video outputs or are based on PC displays in Figure 1 0d 100MHz 4 channel digital storage oscilloscope about Figure 1 0e 100MHz handheld digital storage oscilloscope 1 800 W2 about 1 000 W2 20 au fy yrtin awe he pa wee Mi se oe 04 626406 08 10 l 1 416 1820 PAFAS toa S Us WwW WH 2h Z J9 Jb u as 26FebtsGe It Figure 1 0f 100kHz Dual Channel PC based storage oscilloscope Figure 1 0g 20kHz single channel PC based storage oscilloscope 50mV to 20V about 250 W2 5 to 5V about 95 W2 EEE516J4 Honours Project Page 2 Chapter 1 Project Background Friday 21 June 2002 Final Report Colin K McCord Advantages of the PC based oscilloscope Large screen using data projector for demonstration purposes All Windows GUI advantage such as cut amp paste into documents Data logging e g streaming real time data to disk Remote monitoring e g via the internet remotely control view the oscilloscope from any where in the world Low cost expected to be less than 50 Software upgradeable There are many possible applications for this PC based oscilloscope Monitoring of sound w
166. gs CMenu pMenu This handler ensures that keyboard shortcuts work LRESULT lresult if m_menu IsMenu pMenu m_default IsMenu pMenu lresult BCMenu FindKeyboardShortcut nChar nFlags pMenu else lresult CMDIFrameWnd OnMenuChar nChar nFlags pMenu return lresult Step 8 Add the message handler for the WM_INITMENUPOPUP message void CMainFrame OnInitMenuPopup CMenu pPopupMenu UINT nIndex BOOL bSysMenu This handler updates the menus from time to time CMDIFrameWnd OnInitMenuPopup pPopupMenu nIndex bSysMenu CMDIFrameWnd OnInitMenuPopup pPopupMenu nIndex bSysMenu if bSysMenu if m_menu IsMenu pPopupMenu m_default IsMenu pPopupMenu BCMenu UpdateMenu pPopupMenu Step 9 Specify XP menu style for all versions of Microsoft windows and not just XP Edit BCMenu cpp include stdafx h Standard windows header file include BCMenu h BCMenu class declaration include lt afxpriv h gt SK makes A2W and other spiffy AFX macros work static CPINFO CPInfo how the menu s are drawn in win9x NT 2000 BOOL BCMenu xp_ select _disabled FALSE how the menu s are drawn in winXP UINT BCMenu xp_drawmode BCMENU_DRAWMODE_ XP BOOL BCMenu original_select_disabled TRUE enum Win32Type Win32s Windoze95 WinNT3 WinNT4orHigher That s it the scope program now has professional looking owner drawn MS Office XP style bitmap menus Step
167. gt device PIC16F877 16 ADC 10 fuses HS NOWDT NOPROTECT NOLVP use delay clock 4000000 4MHz clock change this value if using different clock speed use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 main while TRUE Note printf could be used but this function is wasteful and will not be used putat Ty Transmit T putc e Transmit e putc s Transmit s putc t Transmit t putc i Transmit i putc n Transmit n putc g Transmit g EEE516J4 Honours Project Page 96 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord putc Transmit pute s Transmit pubet lt 3 Transmit delay ms 1000 Preset delay repeat every second 9 10 2 Mark 2 c Fully Test RS232 Communications This program is extremely simple basically it initialises RS232 communications and waits for an incoming character once a character is received the character is transmitted this process repeats forever see figure 10 2a This program is used to fully test RS232 communications using the test program in TX terminal mode to transmit a message and then in RX terminal mode to receive a message A more comprehensive test can be carried out using the test program in the loop back test mode if this test passes it is certain that RS232 communications are optimal T Setup RS232 Wait for
168. h edge software trigger this is user adjustable in the Trig tab of the controls dialog see figure 7 0g Notice the user has many options level triggering means that a trigger occurs when the waveform rises from below to above the user configurable offset level for positive edged triggering and the waveform falls from above to below the user configurable offset level for negative edged triggering Edge triggering means that the program detects the positive or negative edges of any waveform and at any voltage level this guarantees that the waveform triggers without the need for user intervention unlike level mode were the waveform must pass through the selected offset level loj xj loj x D Ele Edt yew Toos Window Help lajxi M fe Edt Wew Took Window Hep 18 x erie erie r e fecay r e feck y Semple Disp Trig Semple Disp Trig Trigger X Trigger CHI ITC NEG POS 16 NEG fC POS OffsetLevel 0 4 OffsetLevel 0 4 Level Edge Level Edge Ready NUM iojxj iojxj D Ble Edt yew Toos Window Hep e x D fle Edt yew Toos Window Heb 15 xj ae ee PER P oo esky t u P oo esky tg Semple Disp Trig Semple Disp Trig Trigger em x Trigger emn x TC NEG POS IC NEG POS Otset Level Outset Level a 4 Level Edge Level Edge a iojxi iojxi M Ble Edt View Tools Window Hep laixi Be Edt yew Tools Window Heb 18 x er ee YF Goa hscuases ta ef ee
169. has only poles and no zeros Where the Butterworth design is optimised for a maximally flat pass band response the transition bandwidth the Bessel filter produces a constant time delay with respect to frequency over a large range of frequency The transfer function for the Bessel filter is a 3 4 2 3 Vn aS a S a 8 S Note denominator coefficients for Bessel designs are also available in table form Table 3 in reference J4 lists all of coefficient up to a 5 order filter The Bessel filter has a flat magnitude response in the pass band and the rate of attenuation in the transition band is slower than the Chebyshev or Butterworth This filter has the best step response of all the filters mentioned with very little overshoot or ringing 3 4 3 Software Generation of an Anti Aliasing Filter Customised filters e g anti aliasing can be designed automatically using powerful software applications microchip have developed a program called FillerLab This program is freeware and can be downloaded free of charge from the microchip website W3 FilterLab is an innovative software tool that simplifies active filter design Available at no cost the FilterLab active filter software design tool provides full schematic diagrams of the filter circuit with component values and displays the frequency response FilterLab allows the design of low pass filters up to an 8th order filter with Chebyshev Bessel or Butterworth respons
170. he gap between the horizontal grid points convert back to data type int after multiplication has taken place The array m_nGridY n is filled by looping from n 1 to n 80 Y and multiplying n by the gap between the vertical grid points convert back to data type int after multiplication has taken place Note there is also a configurable boarder offset nBD that must be included in the calculation The two arrays can now be used as a coordinate system to access any part of the grid for example the bottom left edge of the grid is at coordinate m_nGridX 1 by m_nGridY 1 and the top right edge of the grid is at coordinate m_nGridX 100 by m_nGridY 80 Drawing of the grid and waveform traces is achieved using this coordinate system the main advantage of this is that it does not matter what size the scope display is the only thing that needs to change is the values contain within the coordinate arrays extremely flexible Function PerpareGrid fills the grid coordinate arrays void CScopeView PrepareGrid double fW fH int n int nBD 10 Border fW double m_nClientWidth nBD 2 double x fH double m_nClientHeight nBD 2 double y m_nGridX 0 nBD m_nGridy 0 nBD for n 1 n lt x n m_nGridX n int fW n nBD for n 1 n lt y n m_nGridy n int fH n nBD Function OnDrawGrid draws the grid using the grid coordinate system
171. he key variables are saved e g channel center point position m_nCH1POS channel offset m_nCH1_ Offset etc If user clicks on menu item File Open the following function is called void CScopeDoc OnFileOpen 07 04 2002 by CKM CView pView GetActiveView if pView NULL return CChildFrame pChild CChildFrame pView gt GetParentFrame CScopeView SView CScopeView pChild gt m_wndSplitter GetPane 0 0 CScopeApp pApp CScopeApp AfxGetApp FILE infile intiz int temp CFileDialog dlg TRUE _T sdf m Filename OFN_HIDEREADONLY _T Scope Data File sdf sdfl if IDOK dlg DoModal m Filename dlg GetPathName if infile fopen m_Filename rw NULL AfxMessageBox Unable to open file return EEE516J4 Honours Project Page 67 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord rewind infile Open Channel 1 for i 0 1 lt 10000 i fscanf infile d n amp temp pApp gt m_nCH1Volt i temp Open Channel 2 for i 0 1 lt 10000 i fscanf infile d n amp temp pApp gt m_nCH2Volt i temp Open Channel 3 for i 0 1 lt 10000 i fscanf infile d n amp temp pApp gt m_nCH3Volt i temp Open Channel 4 for i 0 1 lt 10000 i fscanf infile d n amp temp pApp gt m_nCH4Volt i temp fscanft fscanf fscanft infil
172. he other option is to have the PC request each and every reading Master Slave the problem with this is that there is a delay sending the request to the PIC and a processing delay hence this method would be much slower in reality EEE516J4 Honours Project Page 32 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord Byte 1 Byte 2 Olt 1 Afofojo y 4 1 1 4 0 1 o o Data d9 d5 Data d4 d0 Figure 6 4b Real time frame structure example channel 4 reads 564d 10 0011 0100b from ADC Notice there is no check sum or CRC the reason for this is to maximise the data throughput Clearly there is a problem however the frame structure is designed in such a way that some errors can be detected Note the cable between the MAX232 buffer connect to PIC and the PC will be high quality cable short length and errors should not occur that frequently anyway A few rules that must occur for the frame to be valid non valid frames are flushed 1 Byte 1 is always followed by byte 2 for a particular channel E g B1_CH1 B2_CH1 B1_CH3 B2_CH3 OK E g B1_CH1 B1_CH3 B2_CH3 Error no B2_CH2 flush this byte 2 Channel readings can occur in any order as long as byte 2 follows byte 1 E g B1_CH3 B2_CH3 B1_CH2 B2_CH2 If one or two readings are lost it should not affect the appearance of the waveform too much as there are at least 10 readings per c
173. he test array is then send to the CRC function which then calculates the 16 bit CRC for the test array Break point was inserted at the position of the Sleep command the stopwatch windows was opened and reset Program was then simulated stopwatch starts until the break point is reached stopwatch stops Note the stopwatch time is the total time taken to execute all instructions in the test program and not just the CRC16 function This is fine as the two test programs are identical except for the CRC16 function therefore a good comparison can be made The screen dump of MPLAB after simulation Raw Calculation MPLAB IDE C WORK COLIN MPLAB PROJECT CRC CRC PIT Fie Project Edt Debug PICSTARTPlus Options Toos Window Hep include lt 16F877 h gt long int CRC16 char xmessage int length main long int crcANS char test 5 test 0 test 1 test 2 test 3 test 4 ercANS CRC1G test 5 Sleep Stopwatch Zero ores ae Address Symbol Value Time 1 64 ms 21 MAIN CRCANS H 90D9 Processor Frequency 4 000000 MHz Clear On Reset Ki Close ln18Colt f 46 WR NoWrep INS PICI6F677 pc0x72 w090 zdec BK On Sim 4MHz Debug Astart 4 GS Scwo Herc Empa Wc wo Gcvwo Icawo Morc Figure 6 8 1a Result of raw calculation CRC test Help AIJE 2103 Total execution time for the raw calculation CRC test program was 1 64ms 4Mhz
174. his dual channel test is shown in figure 11 3 1a EEE516J4 Honours Project Page 131 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Scope Scopel loj xj File Edit View Tools Window Help KiOGlHibikhZiais ere Sample Disp Trig Time Base VCH fiviov McH2 fiviov Cea fiviov ro mo a Ready NUM Figure 11 3 1a Screen dump of scope program Dual Channel Test 11 3 2 Test 9 Interrupt Driven Time Base Real Time Sampling Four Channels Program mark9 c was compiled and loaded into the PIC This program uses timer 2 PIC built in timer as the time base the timer causes an interrupt every 20uUS The variable TimeBaseMU is the time base multiplier e g 100 Hz 10ms hence TimeBaseMUX 500 Note no sampling is done during the interrupt routine as all interrupts are disabled while an interrupt is being processed hence the interrupt routine needs to take less than 20uUS to execute or timing would inaccurate e g say the interrupt routine execute time was longer than 20uS during this time timer 2 cannot cause any more interrupts hence accurate timing is lost The main program loops continuously checking the bSample flag if the flag is true the fuctuion Sample_RealTime is called else it continues to loop The bSample flag is set in the Time base interrupt routine keeping the interrupt short Interrupt driven time base has one big advan
175. igure 13 11b Divide by 256 circuit K aa eK 0 K aa 6K aO e Kaa K aa e kK The reason why the divider circuit figure 13 11b is required is to reduce the processing load on the PIC For example if the divide by 256 was not there the PIC would be interrupted 5000 times a second instead of 19 5 for a 5 KHz signal If the PIC was interrupted 5000 times a second normal operation of the PIC would EEE516J4 Honours Project Page 154 Chapter 13 Recommendations For Further Work Friday 21 June 2002 Final Report Colin K McCord be severally affected If extremely large frequencies are possible gt 1MHz the frequency divider should be increased 13 12 Taking Advantage of Aliasing Using the frequency detection circuit shown in figure 13 12a it maybe possible to monitor periodical waveforms that have a frequency much higher than the sample rate The idea behind this theory is that at certain frequencies aliased waveforms are the same as the input waveform expect for the frequency as seen during testing Therefore with some software processing it is possible to redraw the waveform at the correct time base using the hardware frequency detection circuit as a guild This technique will not work for random waveforms for example sound waves only periodical waveforms which 9 times out of 10 is what an engineer uses an oscilloscope to monitor This technique could allow for waveforms up to 1 MHz or above to be monitored using this P
176. impossible to capture the screen Clearly there must be a big memory leak problem EEE516J4 Honours Project Page 81 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord tman A lt r T a vf TALNA Figure 7 12b Screen dump of Windows 98 running Scope Figure 7 12c Screen dump of indows 2000 running Scope V1 008a taken after 40 seconds V1 008a Figure 7 12c clearly shows that Windows 2000 does not have any problems running scope V1 008a the CPU load is less and 2 and the memory usage is stable At first it was not understood why it was working in Windows 2000 and not Windows 98 On the 24 December 2001 the problem was solved there was indeed a memory leak Every 100ms the screen is refreshed e g a new bitmap is created and the waveform is drawn to the bitmap this bitmap is then drawn to the screen but the existing screen bitmap was being lost in memory Therefore 10 times a second a bitmap the size of the graphical display was being lost in memory eating up memory resources The solution was to setup a pointer to this old bitmap and delete the object void CScopeView OnDrawCH1 if m_dcCH1 GetSafeHdc NULL if we don t have one yet set up a memory dc for chl m_dcCH1 CreateCompatibleDC amp dc m_ bitmapCH1 CreateDiscardableBitmap amp dc m nClientWidth m_nClientHeight else m bitmapCH1 CreateDiscardableBitmap amp dc m nClientWidth m nC
177. inator coefficients for Butterworth designs are available in table form Table 1 in reference J4 lists all of coefficient up to a 5 order filter The frequency behaviour has a maximally flat magnitude response in the pass band The rate of attenuation in the transition band is better than Bessel but not as good as the Chebyshev filter There is no ringing in the stop band but there is some overshoot and ringing in the time domain but less than the Chebyshev EEE516J4 Honours Project Page 9 Chapter 3 Fundamentals Friday 21 June 2002 Final Report Colin K McCord Chebyshev Filter The Chebyshev filter exhibits an equiripple response in the pass and and a monotonically decreasing transmission in the stop and While the odd order filter has T 0 1 the even order filter exhibits its maximum magnitude deviation at w 0 In both cases the total number of pass and maxima and minima equals the order of the filter N All transmission zeros of the Chebyshev filter are at w making it an all pole filter B4 Therefore the transfer function of the Chebyshev filter is similar to the Butterworth filter in that it has all poles and no zeros with a transfer function of a ae 3 4 2 2 Vn S aS a 8 S Note denominator coefficients for Chebyshev designs are also available in table form Table 2 in reference J4 lists all of coefficient up to a 5 order filter Bessel Filter The transfer function of the Bessel filter
178. ine I8259M 0x21 define 18259 0x20 The address of the 8259 define EOI 0x20 The end of int command define IRQ 4 define SIZE 512 Buffer size K char buffer SIZE Receiving buffer char i get i put Pointer to buffer unsigned int baud Baud Rate x Initialise UART set speed set data format set ISR address etc int line mask Comm parameters void interrupt old_ handler old_handler getvect IRQ 8 Old ISR address ny i_put i_get buffer Pointer initialisation memset buffer 0 SIZE Buffer initialisation baud 0x0c 0x01 115200 bps 0x02 57600 bps 0x03 38400 bps 0x06 19200 bps Ox0c 9600 bps line 0x03 8 bits non parity 1 stop initialisation outporthb COM IER 0 inportb COM LSR inportb COM MSR inportb COM IIR inportb COM RBR set speed outportb COM LCR inportb COM LCR 0x80 outportb COM DLM baud gt gt 8 outporthb COM DLL baud amp 0xff outportb COM LCR inportb COM LCR amp Ox7f set data format outportb COM LCR line outportb COM MCR 0x0Ob outportb COM IER 0x01 tata set ISR address disable setvect IRQ 8 com_handler enable mask inportb 18259M mask amp 1 lt lt IRQ outportb 18259M mask Interrupt routine for storing incoming characters on the buffer void interrupt com_handler
179. inewave 0 5V 2Hz sinewave 0 5V connected to CH1 ANO see figure 11 1 3b 5 divisions per cycle hence the calculated frequency of this waveform is 1 5 0 1 2Hz loj x l x Sample Disp Trig Time Base m eni fiviov Figure 11 1 3b Screen dump of scope program sample rate 100Hz input wave 2Hz sinewave 0 5V EEE516J4 Honours Project Page 116 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 5Hz sinewave 0 5V connected to CH1 ANO see figure 11 1 3c 2 divisions per cycle Hence the calculated frequency of this waveform is 1 2 0 1 5Hz Scope Scopel o x 2 Fie Edt View Toos Window Hep _ l8 x Semple Disp Trig Time tes Base Jv CHI HVN x Figure 11 1 3c Screen dump of scope program sample rate 100Hz input wave 5Hz sinewave 0 5V 10Hz sinewave 0 5V connected to CH1 ANO see figure 11 1 3d 1 divisions per cycle hence the calculated frequency of this waveform is 1 1 0 1 10Hz Sample Disp Trig Time Base M CHI fiv DIV Figure 11 1 3d Screen dump of scope program sample rate 100Hz input wave 10Hz sinewave 0 5V 20Hz sinewave 0 5V connected to CH1 ANO see figure 11 1 3e 0 5 divisions per cycle hence the calculated frequency of this waveform is 1 0 5 0 1 20Hz But waveform is under sampled and heavily EEE516J4 Honours Project Page 117 Chapter 11 Test Results Frid
180. ing a new trace say CH5 virtual channel 1 This is extremely easy to achieve it is only matter of creating four more traces the same as was done for channels 1 to 4 e g cut amp paste makes life easy Instead of filling the arrays for these traces using the communication protocol the program continuously scans though each real channel array multiply adding dividing or subtracting channels together e g whatever the user has specified for each virtual trace filling the virtual trace arrays 13 7 Data Logging The scope program already has dummy dialog controls for this feature basically real time data is streamed to disk allowing the user to play back the recorded data in real time manually scroll through the data and email the data to a colleague anywhere in world For example this feature would be useful for monitoring of an ECG signal where the raw data can be email to a doctor for diagnosis This feature is easy to implement basically every character that is received from the serial port is dumped into a file and when playing back the data the program runs through the recorded data at the same rate it was originally sampled at perhaps the sample rate combo box could still be operational allowing for a slowed or speeded up view of the data 13 8 TCP IP Internet Communications Remote monitoring control of oscilloscope from anywhere in world for example the machine actually connected to the scope hardware running in sl
181. ing character and transmits it This is a very simple method of fully testing the RS232 communication PIC software PIC MAX232 cable and wiring The DOS based test program test exe version 1 05 was used to carryout two separate tests The first used the TX terminal to transmit a message then the RX terminal is used to receive the message if the RX amp TX messages are identical the test is successful The second used the loop back test function of the test program this stresses the communications as a large amount of data is transmitted and compared with the received block of data The TX RX terminal tests were successful for all baud rates but the loop back tests failed at high baud rates There are two possible reasons for this the first is that because a large block of data is being transmitted through unshielded cable clearly there is a good chance of an error occurring at high baud rates The second possibility is that the PIC UART input buffer overflowed 11 2 3 Test 6 Test ADC Scope Program and Real time Communication Protocol Program mark6 c was compiled and loaded into PIC using Microchip MPLAB basically it reads the DIP switches and sets the baud rate then it reads the ADC CH1 ANO and transmits the result through RS232 using the real time frame format every 1ms sample rate of 1000Hz The scope exe version 1 027a program was used to display the real time frames graphically and a calibrated digital signal generator was
182. ing rate in the real time mode Therefore it is important that the application is design to be flexible as its probable that the program will be modified some time in the future for use with another medium e g Parallel USB etc The development of this program is not fully completed but has progressed sufficiently to display real time waveforms using various triggering methods selectable time base selectable voltage scales etc Storage mode operation and direct control of the PIC has not been implemented yet as well as some advantaged features like streaming real time data to disk automatic frequency calculation and the addition of user configurable virtual channels e g VC1 CH1 CH2 VC2 CH1 CH2 etc Please note that the full source code is contained on the attached CD ROM as a full printout would require hundreds of pages Allow important parts of the source code have been included in this chapter along with a brief English description on how the code works Ble Edit View Tools Window Help ioo Oca BRIS EER Untitled Sample Disp Trig Time 20mS OV Base MeH fiviov re fiviov gt Coa fiviov z coo Mo Ready Num A Figure 7 0a Screen dump of scope exe V1 041a 19 04 2002 Notice that the display is split into two see figure 7 0a the left half displays the waveform and the right half contain the controls The attached control dialog can be hidden by right clicking on th
183. ion line return the impedance over a long distance may support a significant difference in the two ground potentials which will degrade noise immunity Furthermore any noise induced from the outside will affect signal lines differently from the ground return due to their dissimilar electrical characteristics hence the name unbalanced B3 RS232 data is bi polar e g a 3 to 15 volt indicates an SPACE ON while a 3 to 15 volt indicates an MARK OFF Modern computer equipment ignores the negative level and accepts a zero voltage level as the MARK OFF state This means circuits powered by 5 VDC are capable of driving RS232 circuits directly however the overall range that the RS232 signal may be transmitted received is dramatically reduced LSB MSB 15V S JL o S oO Qa N 3V g oO EE ov 59 or me 3V D X Oo 8 Data Bits 15V q gt Start Bit Stop Bit Figure 3 6d Illustration of how data is transmitted over RS232 The output signal level usually swings between 15V and 15V The dead area between 3v and 3v is designed to give some noise immunity This dead area can vary for various RS232 like definitions for example the definition for V 10 has a noise margin from 0 3V to 0 3V Many receivers designed for RS232 are sensitive to differentials of 1v or less EEE516J4 Honours Project Page 14 Chapter 3 Fundamentals Friday 21 June 2002 Final Report Colin K McCord
184. is 8 bits fuses HS NOWDT NOPROTECT NOLVP NOBROWNOUT byte PORTB 0x06 PortB lives in File 6 byte PORTC 0x07 PortC lives in File 7 byte PORTD 0x08 PortD lives in File 8 byte PORTE 0x09 PortE lives in File 9 data bus address bus A12 to A8 RX TX amp R W address bus AO to A7 used for DIP switches bit RW PORTC 5 RW 0 for Write and 1 for read Note 20MHz clock must be used for 115 000 bps the error is to large at slower speeds use delay clock 20000000 use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 use fast_io B Fast access to PortB don t fiddle with TRISB use fast_io C Fast access to PortB don t fiddle with TRISB use fast_io D Fast access to PortD don t fiddle with TRISD use fast_io E Fast access to PortE don t fiddle with TRISE Forward declaration of functions void SetBaudRate void WriteRAM long int address char data char ReadRAM long int address main long int i long int pass fail set_tris_c 0xC0 TRISD 11000000 RCO to RC5 TTL Outputs bits 7 amp 6 must be set for UART to work set_tris_ d 0x00 TRISD 00000000 RDO to RD7 TTL Outputs port_b pullups FALSE Don t use internal pull up resistors EEE516J4 Honours Project Page 109 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord SetBaudRate while TRUE delay
185. k case 5 set_uart_speed 38400 break case 6 set_uart_speed 57600 break case 7 set_uart_speed 115200 break EEE516J4 Honours Project Page 101 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord 10 7 Mark 7 c Test Timer Interrupts This program uses all of the PICs built in timers basically timers 0 2 are setup to cause an interrupt An interrupt subroutine has been written for each timer at preset intervals 0 5s 0 25s amp 0 1s a message is transmitted to the PC The main program is stuck in a loop transmitting main every second TimerO_ISR transmits Interrupt_T0O every 0 5s Timer1_ISR transmits Interrupt_T1 every 0 25s and Timer2_ISR transmits Interrupt_T2 10 times a second These messages are received using a PC running the DOS based test program in RX terminal mode hence testing of the PIC timer interrupts including crude timing analysis is achieved for example there should be two Interrupt_TO messages between every Main See figure 10 7a for a simplified flowchart of the program Timer1_ISR Timer2_ISR l Timer0_ISR Has 0 5s Setup RS232 Hardware UART 1 Second delay baud rate 9600 Has 0 1s elapsed elapsed Read Dip F Switches and set Torem yes yes yes baud rate oe 7 Y v Transmit AG Transmit no Transmit Ao
186. k The datasheet for the PIC16F877 specifies acquisition time TACQ TACQ Amplifier Setting Time Hold Capacitor Charging Time Temperature Coefficient Tame To Toorr 2uS Tc Temperature 25 C 0 05uS C Tc Choro Ric Rss Rs In 1 2047 120pF 1kO 7kQ 10kQ In 0 0004885 16 47uS TACQ 2uS 16 47uS 50 C 25 C 0 05yuS C 19 72uS Therefore theoretically the PICs ADC can sample at 1 19 72uS 50 7 KHz But according to the datasheet after a conversion has completed a 2 0 Tap delay must be complete before acquisition can begin again During this time the holding capacitor is not connected to the selected A D input channel D1 Tap is defined as the A D conversion time per bit For correct A D conversions the A D conversion clock Tap must be selected to ensure a minimum Tap time of 1 6us Assuming a minimum A D conversion clock Tap time of 1 6 uS e g the PIC is running at 20 MHz with 32TOSC selected for Tap the maximum sample rate is 1 1 Smax 43 63KHZz Ksps MX TACQ 2T p 22 92us Msas For faster sample rates an external ADC with direct memory access is required EEE516J4 Honours Project Page 35 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord 6 8 CRC16 Cyclical Redundancy Check used in Storage Mode Procedure 1 Load a 16 bit register with FFFF hex all 1 s Call this
187. ks well with dark background and a light plot memDC BitB1lt 0 0 m_nClientWidth m_nClientHeight amp m_dcCHl 0 0 SRCPAINT SRCPAINT memDC BitBlt 0 0 m nClientWidth m nClientHeight amp m_dcCH2 0 0 SRCPAINT SRCPAINT memDC BitB1lt 0 0 m_nClientWidth m_nClientHeight amp m_dcCH3 0 0 SRCPAINT SRCPAINT memDC BitBlt 0 0 m nClientWidth m nClientHeight amp m dcCH4 0 0 SRCPAINT SRCPAINT Convert Device Dependent Bitmap DDB to Device independent Bitmap hDIB DDBTODIB bitmap BI RGB NULL CFileDialog dlg FALSE T bmp _T Scope OFN HIDEREADONLY T Bitmap bmp bmp dlg m_ofn lpstrTitle Export Scope Display if IDOK dlg DoModal Check for existence if _access dlg GetPathName 0 1 if MessageBox File dlg GetPathName Alread to replace the existing file Export Scope Display MB_ICONINFORMATION IDYES return WriteDIB dlg GetPathName hDIB Save as Bitmap DIB Windows or OS 2 y exists Do you want MB_YESNO Write bitmap to specified file BOOL CScopeView WriteDIB CString szFile HANDLE hDIB Je ea eo oe ee ee E eae ee ee ee ee Fuction BOOL CScopeView WriteDIB Description Writes bitmap to specified file Return Void Date 16 02 2002 Verison wA By Colin K McCord a aa a ar a
188. l DO 4uF 9 32 TF 4 L 5 10 31 1 B 9 30 6 x rn L 12 29 2 I i 13 28 7 A 14 27 3 O a A 15 26 8 C a 8 16 25 4 9 17 24 9 ve RW 4 10 20MHz 18 23 5 O 1 AT 19 22 0 A ce c 20 21 ate 33pF 33pF 7 A PIC16F877 20 P Figure 11 3 3a Test Circuit Diagram 3 Program mark10 c was compiled and loaded into the PIC This program carries out three tests 1 Fill all memory locations with OxFFh and check 2 Fill all memory locations with Ox00h and check 3 Fill all memory locations with the LSB of the address and check RS232 communication is used to relay the results to the PC the DOS based program test exe used in RX terminal mode was used to receive and display the results Screen dump of the result is shown below RX Terminal Waiting for message press a key to stop TEST RAM CHIP Test 1 Fill RAM with OxFF gt Passes 7806 Fails 386 Test 2 Fill RAM with 0x00 gt Passes 8114 Fails 78 Test 3 Fill RAM with LSB of Address gt Passes 31 Fails 8161 End of RAMTEST Hopefully work can now start on storage mode EEE516J4 Honours Project Page 146 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Clearly this test was a failure it was discovered that there was a bug in the PIC program code version 1 1 Recall that the DIP switches are connected to port E and in order to configure this port for TT
189. l function registers Some high use special function registers from one bank may be mirrored in another bank for code reduction and quicker access Also notice that there are 16 general purpose global registers shown in green these registers can be accessed from any bank EEE516J4 Honours Project Page 17 Chapter 4 The PIC16F877 Microcontroller Friday 21 June 2002 Final Report Colin K McCord 4 2 Overview of the 8 Channel 10 bit ADC At first it appears that the PIC16F877 has 8 built in ADCs but this is not the case Figure 4 2a shows a simplified block diagram of the analogue to digital converter module clearly there is only one 10 bit ADC which can be connected to only one of eight input pins at any one time 1 Right justified 0 left justified rc ACON1 File 9Fh 9 l ADFM 0 0 0 PCFG3 PCFG2 PCFG1 PCFGO ADRESH l oOC1 E l l l E p gt gt Voo 1k l ie ANO RAOmmm Do 14 l Vy A 5p 500n w42 I l l Voo 1k d a AN1 RA1 D1 SSS ALBEE S i zk 5p 500n SS am d l 9 Vet o V o l AN2 RA2m l be i b l A 5p 500n g Mire reft v x lt I a DD Q or AN3 RA3mmm f o bs 9 File 1Eh kK 5p
190. lags amp wp showCmd amp wp ptMinPosition x amp wp ptMinPosition y amp wp ptMaxPosition x amp wp ptMaxPosition y amp wp rcNormalPosition left amp wp rcNormalPosition top amp wp rcNormalPosition right amp wp rcNormalPosition bottom if nRead 10 return FALSE wp length sizeof wp pwp wp return TRU ti static void PASCAL NEAR WriteWindowPlacement LPWINDOWPLACEMENT pwp write a window placement to settings section of app s registry TCHAR szBuffer sizeof 32767 8 sizeof 65535 2 wsprintf szBuffer szFormat pwp gt flags pwp gt showCmd pwp gt ptMinPosition x pwp gt ptMinPosition y pwp gt ptMaxPosition x pwp gt ptMaxPosition y pwp gt rcNormalPosition left pwp gt rcNormalPosition top EEE516J4 Honours Project Page 58 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord pwp gt rcNormalPosition right pwp gt rcNormalPosition bottom AfxGetApp gt WriteProfileString szSection szWindowPos szBuffer ZITTTLTTLTTT LAAT TTT ATT ATTA ATTA TTT ATTA TATTLE T AAT ATTA A TTA AT ATAAAATTTT This function restores window position from windows registry Restore window position from registry by CKM 05 02 2002 WINDOWPLACEMENT wp if ReadWindowPlacement amp wp ShowWindow nCmdShow return if nCmdShow SW_SHOWNORMAL wp showCmd nCmdShow SetWindowPlacement amp wp Sho
191. lain how it works Suppose there is an unknown weight a balance scale and a set of precision known weights 1 2 4 and 8 grams A systemic technique can be used to calculate the unknown weight Place the 8g weight on the pan and remove if it is too heavy Next place the 4g weight on the pan and remove if it is too heavy Next place the 2g weight on the pan and remove if it is too heavy Next place the 1g weight on the pan and remove if it is too heavy The sum of the weights still on the pan yields the nearest lower value of the unknown weight This is illustrated in figures 4 2b to 4 2g Figure 4 2b Unknown weight placed on the scales Figure 4 2c 8g weight placed on the pan not too heavy keep Figure 4 2d 4g weight placed on the pan too heavy remove Figure 4 2e 2g weight placed on the pan not too heavy keep Figure 4 2f 1g weight placed on the pan too heavy remove Figure 4 2g Unknown weight is about 10g 1010 The electronic equivalent to this successive approximation technique uses a network of precision capacitors configured to allow consecutive halving of a fixed voltage Vrer to be switched in to an analogue comparator which acts as the balance scale Generally the network of capacitors are valued in powers of two to subdivide the analogue reference voltage e g 1 2 4 8 16 etc This sampling acquisition process takes a finite time due to the charging time constant and is specified in the data sheet as 19 72uS
192. ldFrame lt gt CScopeView m_bShowPanel Path 6 CGridConfigDig lt gt CScopeApp m_nBufferSize Path 7 CScopeView CScopeDoc int m_TimeBaseSelection int m_nCH3 VOLTS int m_nTrigger bool m_bCH1 ENABLE bool m_bCH4 ENABLE int m_nCH1_ VOLTS int m_nCH4 VOLTS int m_nTriggerOffsetLevel bool m_bCH2_ ENABLE Path 8 CScopeView CScopeApp int m_nCH1Volt 10004 int m_nCH4Volt 10004 Path 9 CScopeDoc gt sdf File pApp gt m_nCH1Volt 10004 pApp gt m_nCH4Vol1t 10004 SView gt m_nCH1POS SView gt m_nCH4P0S SView gt m_nCH3 Offset pApp gt m_nSampleMode bool m_bCH2_ ENABLE int m TimeBaseSelection int m_nCH3_ VOLTS int m_nTriggerType int m_nCH2Volt 10004 pApp gt m_nCH2Vol1t 10004 SView gt x SView gt m_nCH2POS SView gt m_nCHl Offset SView gt m_nCH4 Offset pApp gt m_SampleRateSelection bool m_bCH3 ENABLE int m nCH1_ VOLTS int m nCH4 VOLTS SView gt m_ColorGridBackGround int m_nCH2 VOLTS int m_nTriggerType int m_nTriggerFormat bool m_bCH3 ENABLE int m_nCH3Volt 10004 pApp gt m_nCH3Vol1t 10004 SView gt y SView gt m_nCH3POS SView gt m_nCH2 Offset pApp gt m_nInputRange bool m_bCH1 ENABLE bool m_bCH4 ENABLE int m_nCH2 VOLTS int m_nTrigger SView gt m_nRefreshRate Path 10 CScopeDoc gt CScopeApp int m_nCH1Volt 10004 int m_nCH4Volt 10004 int m_SampleRateSelection int m_nCH2Volt 10004 int m_niInputRange int m_nCH3Volt 10004 int m_nSampleMode
193. lientHeight milo es wits giz O24 Fe windows Taku a 1943 igure 7 12e Screen dump of Windows 2000 running Scope V1 010a creen dump of Windows 98 running Scope V1 010a EEE516J4 Honours Project Page 82 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord Screen dump figure 7 12d clearly shows that this solved the problem CPU load is now 12 and system resources including physical memory are stable Figure 7 12e clearly shows that the modifications did not affect the operation of the scope program in Windows 2000 CPU load is less than 2 and memory usage is stable The reason why Scope version 1 008a worked in Windows 2000 is because it is a far superior operating system that can deal with memory leaks while Windows 98 cannot deal with memory leaks one of the reasons why it s so unstable This experiment clearly demonstrates how much better Windows 2000 is than Windows 98 also notice that the CPU load is much lower in Windows 2000 lt 2 when compared with Windows 98 12 7 13 Windows XP Compatibility Problem scope v1 017a 05 02 2002 On the 3 of February 2002 it was discovered that there is a problem when running the scope program in Windows XP CPU load was high which increased when the scope display was enlarged AT first it was not understood why this could be happening as the program had no problems running in Windows 98
194. lopment Friday 21 June 2002 Final Report Colin K McCord case 5 set_uart_speed 38400 break case 6 set_uart_speed 57600 break case 7 set_uart_speed 115200 break 10 10 Mark 10 c Test External RAM Chip This program carries out three tests 1 Fill all memory locations with OxFFh and check 2 Fill all memory locations with Ox00h and check 3 Fill all memory locations with the LSB of the address and check RS232 communication is used to relay the results to the PC the DOS based program test exe used in RX terminal mode is used to receive and display the results This program is designed to test the functions used to access the RAM ReadRAM WriteRAM and every location on the RAM chip Notice that there are 1 cycle delays in the ReadRAM and WriteRAM functions these delays make sure that the address and data lines are value before a read or write operation is completed Note the RAM chip used has a reassembly fast access time hence the RAM may operate correctly with these delays removed This program is in preparation for storage mode operation a sh a ye a at NNN NN tm Na Nt a Ne aN oat FILE mark_cl0 c PROJECT Low Cost PC Based Oscilloscope DESC Test RAM Chip SS SS SS SS SS DATE 21 03 2002 BY Colin K McCord VERSION 1 2 include lt 16F877 h gt device PIC16F877 16 ADC 10 use device adc 10 to implement a 10 bit conversion otherwise the default
195. lustration of RS232 1 driver and 1 receiver Page 14 3 6b 9 pin RS232 D connector pin signal description Page 15 3 6c Typical maximum distance modern line drivers receivers can manage Page 15 3 6d Illustration of how data is transmitted over RS232 Page 14 4 0 The PIC16F877 Microcontroller Pages 16 to 20 4 0a Architecture of the PIC16F877 microcontroller W9 Page 16 4 1a PIC16F877 register file map Page 17 4 2a Simplified block diagram of the PIC16F877 ADC module Page 18 4 2b Unknown eight placed on the scales Page 19 4 2c 8g weight placed on the pan not too heavy keep Page 19 4 2d 4g weight placed on the pan too heavy remove Page 19 4 2e 2g weight placed on the pan not too heavy keep Page 19 4 2f 1g weight placed on the pan too heavy remove Page 19 4 2g Unknown weight is about 10g 1010 Page 19 5 0 Hardware Development Pages 21 to 29 5 0a illustrates the operation of the analogue circuitry Page 21 5 1a Simplified block diagram Page 22 5 2a Digital circuit diagram version 1 3 19 03 2002 Page 23 5 2b Dip switch configuration Page 24 5 3a Analogue circuit diagram Mark 1 14 12 2001 Page 25 5 4a Analogue circuit diagram Mark 2 19 03 2002 Page 27 5 5a System powering circuit Page 28 6 0 Communication Protocol Development Page 30 to 42 6 1a Illustration of real time mode with one channel Page 30 6 1b Illustration of real time mode with four channels chop mode Page 30 6 1c Illustration of real time m
196. m transmitting them to the PC in one large block This is a quick and easy test next step is actually writing the storage mode software and then the control protocol EEE516J4 Honours Project Page 147 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 12 0 CONCLUSIONS Clearly commercial oscilloscopes are over priced the main goal of this project was that the cost of the PC based oscilloscope should be as low as practically possible the total cost was expected to be less than 50 and this figure was used as guild when selecting hardware components Clearly this goal has been achieved as the total cost of PCB components was calculated to be 22 97 retail price obviously this does not include the cost of the PCB board about 7 case about 5 and manufacturing costs about 15 but the total product costs should be under 50 Note the software application should be freeware including full source code hence customers can modify code making improvements and adding additional features these customers could be encouraged to send their customised copy of the program to the author so that some of these changes could be included in new releases of the program Clearly this project is cheaper than any other similar product on the market as the nearest was a 20 kHz single channel PC based storage oscilloscope 5 to 5V at 95 It is also clear that this project has many technical advantages over existing pro
197. milar but not perfect to that of Word XP It is clear that Brent Corkum has done a good job developing this class and it was decided after testing on Windows 98 2000 XP for the scope program to make use of his class as it made the program more professional looking and more user friendly Icons in the menus Efe Edit View Insert Format Tools Table MathType Window Help Acrobat Scope Scope Al Fle Edt View Tools Window Hep New 1E Save Save As S Save as Web Page R Search Versions Web Page Preview Page Setup A Print Preview amp Print Send To Properties Ctrl N cn o col S Crl P 1C Work Coln 2C Work coin 3 C Work coln 7 0 Bb _ Ref doc Owner Drawn Menus doc Template doc eHow aia Ha 1 Ard Txt B z uE CyN Open Col o x Close E Save Save As Ctri S Export amp Print A Print Preview Print Setup Rt Exit SSeS ee Seeee Sears sees ee 4 C Work Deaing with Aliasing doc Exit Figure 7 11b Scope Ver1 036a file Menu Figure 7 11a Microsoft Word XP file menu This class BCMenu implements owner drawn menus derived from the CMenu class The purpose of which is to mimic the menu style used in Visual C 5 0 and MS Word can t take credit for all the code some portions of it were taken from code supplied by Ben Ashley and Girish Bharadwaj The difference between
198. n id m_menu LoadToolbars toolbars 2 return m_menu Detach Step 4 Add function NewDefaultMenu to class CMainFrame HMENU CMainFrame NewDefaultMenu m_ default LoadMenu IDR_MAINFRAME m_ default LoadToolbar IDR_MAINFRAMBE return m_default Detach Step 5 Edit InitInstance function in class CScopeApp BOOL CScopeApp InitInstance create main MDI Frame window CMainFrame pMainFrame new CMainFrame if pMainFrame gt LoadFrame IDR_MAINFRAME return FALSE m_ pMainWnd pMainFrame Step 6 Add the message handler for the WM_MEASUREITEM message void CMainFrame OnMeasureItem int nIDCtl LPMEASUREITEMSTRUCT lpMeasurelItemStruct This handler ensure that the popup menu items are drawn correctly BOOL setflag FALSE if lpMeasurelItemStruct gt CtlType ODT_ MENU if IsMenu HMENU lpMeasureItemStruct gt itemID CMenu cmenu CMenu FromHandle HMENU lpMeasureItemStruct gt itemID if m_menu IsMenu cmenu m_default IsMenu cmenu m_menu MeasureItem lpMeasurelItemStruct setflag TRUE EEE516J4 Honours Project Page 79 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord if setflag CMDIFrameWnd OnMeasureItem nIDCtl lpMeasureItemStruct Step 7 Add the message handler for the WM_MENUCHAR message LRESULT CMainFrame OnMenuChar UINT nChar UINT nFla
199. nclude lt 16F877 h gt long int CRC16 char message int length main long int crcANS char test 5 test 0 test 1 test 2 test 3 test 4 PNHWH WwW crcANS CRC16 test 5 Sleep long int CRC16 char message int length 16 bit var s long int CRC OxFFFF CRC initialised with all 1l s i Loop Control temp Temp for swap wi while length Loop until all bytes calculated CRC CRC messaget t for i 0 i lt 8 Shift all 8 bits a if CRC amp 0x0001 CRC CRC gt gt 1 0xA001 else CRC gt gt 1 temp CRC amp OxFF Temp storage for swap 7 CRC CRC gt gt 8 amp 0xFF temp lt lt 8 Swap high and low byte E return CRC Return calculated 16 bit CRC ky Notice data types have been changed from that used in the PC version e g char is 8 bit short is 16 bit int is 32 bit and long is 64 bit on a PC while char is 8 bit short is 1 bit int is 8 bit and long is 16 bit on a PIC EEE516J4 Honours Project Page 38 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord Abstract from crc st MPASM CCS PCM C Compiler Version 2 707 8851 Filename C WORK COLIN MPLAB PROJECT CRC CRC LST ROM used 116 13 Largest free fragment is 2048 RAM used 12 7 at main level 22 13 worst case Stack 1 locations Test array setup containing 5 elements t
200. nfo DWORD DIB_RGB_ COLORS Use RGB for colour table if bGotBits GlobalFree hDIB SelectPalette hDC hPal FALSE ReleaseDC NULL hDC return NULL SelectPalette hDC hPal FALSE ReleaseDC NULL hDC return hDIB Colin K McCord Convert the scope display to a bitmap DDB and ask the user for a filename void CScopeView OnFileExport Fuction void CScopeView OnFileExport Description User specifies filename using CFileDialog then the scope display is save to that filename using the standard bitmap graphic format Return Void Date 16 02 2002 Verison Led By Colin K McCord Sa Sl ANSARI AIR EE E E ht ATER IR AEA EA CR AAR E Ses HANDLE hDIB CRect rect CClientDC dc this CDC memDC CBitmap bitmap GetClientRect amp rect Create memDC memDC CreateCompatibleDC amp dc bitmap CreateCompatibleBitmap amp dc rect Width rect Height CBitmap pOldBitmap memDC SelectObject amp bitmap Fill in memDC memDC FillSolidRect rect dc GetBkColor Redraw grid to memory DC if memDC GetSafeHdc NULL first drop the grid on the memory dc memDC BitB1lt 0 0 m_nClientWidth m_nClientHeight m_dcGrid 0 O SRCCOPY EEE516J4 Honours Project Page 75 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord now add the plot on top as a pattern via SRCPAINT wor
201. ntrolPROT Yes Decode and Valid Implement No Sample CH1 in real time a chop Return Be s Figure 6 3a Illustration of the control protocol 6 4 Frame Structure Real Time Mode 10 bit ADC hence 2 bytes are sent per reading Byte 1 Byte 2 A Bjcj j j A B C Data d9 d5 Data d4 d0 Figure 6 4a Frame structure Real Time If A 0 byte 1 which contains data d9 d5 Upper 5 bits of ADC reading If A 1 byte 2 which contains data d4 d0 Lower 5 bits of ADC reading B amp C specify what channel the data is for Since the RS232 communications is the bottleneck it is important that the real time communication protocol is as efficient as possible At first it appears that the structure is 100 efficient as all bytes are used and each one extremely Channel 2 important Channel 3 Yes this is partly true however the only data of real value is the ADC readings C h 14 the reset are for identification purposes only Hence the real efficiency of this anne frame structure is 10 data bits 16 bits in total hence efficiency 10 16 x 100 62 5 It is theoretically possible to use a frame structure that is 100 efficient but this requires because there is no identification code extremely good synchronisation between the PC and the PIC The main problem with this is that if a byte is lost due to noise bad line buffer overflow etc it would be extremely difficult to recover T
202. ocol would not work because there is a high likelinood of a collision occurring two or more transmit at the same time hence the need for a master slave communication protocol or extremely good synchronisation where each PIC only transmits during specified time blocks Sampling simultaneously is not required the two modes chop and alt should be adequate hence only one PIC is required chop read CH1 gt read CH2 gt read CH3 read CH4 gt alt read CH1 1000 times gt read CH2 1000 times gt read CH3 1000 times gt read CH4 1000 times Simultaneous sampling using four PICs may be useful for specialist applications and this project is suitable as only mirror software modification is required 5 2 Digital Circuit Diagram Figure 5 2a shows the digital circuit diagram the design is simple with a low chip count 3 ICs S2 S1 SO Baud Rate The dip switches connected to port E are used to select RS232 baud 0 0 0 115 200 bps rate see figure 5 2b The MAX232CPE RS232 line buffer is connected 0 0 1 57 600 bps to pins RC7 and RC6 of the PIC these pins are for use with the PICs 0 1 0 38 400 bps hardware UART The use of the PICs hardware UART was the only 0 1 1 32 768 bps option because a software UART would severely affect system 1 0 0 19 200 bps performance 1 0 1 14 400 bps 1 1 0 9 600 bps The reason why the MAX232CPE RS232 line buffer was chosen was 1 1 1 4 800 bps because it can be powered from a
203. ode with four channels alternate mode Page 30 6 2a Illustration of storage mode with one channel Page 31 6 2b Illustration of storage mode with four channels chop mode Page 31 6 3a Illustration of the control protocol Page 32 EEE516J4 Honours Project Page VIII Table of Figures Friday 21 June 2002 Final Report Colin K McCord 6 4a Frame structure Real Time Page 32 6 4b Real time frame structure example Page 33 6 5a Table showing the theoretical real time sample rates chop 10 bit ADC Page 33 6 5b Table showing the theoretical real time sample rates chop 8 bit ADC Page 34 6 5c Table showing the theoretical real time sample rates chop 10 bit ADC dual RS232 Page 34 6 6a Frame Structure Storage Mode Page 35 6 8 1a Result of raw calculation CRC test Page 39 6 8 1b Result of lookup table CRC test Page 41 6 9a Frame structure control protocol Page 42 6 9b SETUP_REG1 Page 42 6 9c SETUP_REG2 Page 42 7 0 The Scope Program Pages 43 to 85 7 0a Screen dump of scope exe V1 041a 19 04 2002 Page 43 7 0b Right click menu Page 43 7 0c Screen dump of scope exe with side bar hidden Page 44 7 0d Screen dump of scope exe demonstrating auto resize Page 44 7 0e Three screen dumps of scope exe demonstrating the change of zero point Page 44 7 0f Three screen dumps of scope exe demonstrating the change of waveform offset Page 44 7 0g Six screen dumps of scope exe demonstrating different trigger settings Page 45 7 0h Two scr
204. odes is for protection e g say a 1 to 6V signal makes it through the op amps the diodes will cut off the peaks of the waveform making sure no damage is done to the PICs ADC Note for the 250 to 250V range it may be necessary for R3 to be made up of several resistors in series as standard resisters have a maximum operating voltage of about 200 volts All resistors should have a tolerance of at least 1 ideally instrumental resistors should be used Instead of three inputs it is recommend that a three to one line manual switch should be used to connect each line to a single input line Over voltage protection is still required in case of miss use e g the user has the 2 5 to 2 5V volt input selected and connects the 240V c mains to the input EEE516J4 Honours Project Page 26 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord 5V O 5V O R5 R4 R7 2k 1k 10k D1 15V 15V A 2 5 to 2 5v o 4 input R1 b R6 To ADC 1k 10k R8 o1 150 25 to 25V 15V 15V input i n2 R2 IC 741 IC 741 10k 250 t0250V p L a input R3 100k Figure 5 4a Analogue circuit diagram Mark 2 19 03 2002 Disadvantages of this circuit 1 No op amp protection if wrong input line is used e g 100V input on the 2 5 to 2 5V input 2 Range not microcontroller controlled
205. offset triangle for both channels are in exactly the same place this is clear due to the colour of the triangle This is not a problem e g offset of both channels does not change if user clicks on the offset triangle as channel 1 has absolute priority hence only channel 1 offset will change separating the channel offsets Note channel 2 has priority over channel 3 and channel 3 has priority over channel 4 A quick way of moving channel 4 offset for example if all four channel are enabled and the offset of each is in the same place is to temporarily disabled channels 1 to 3 move channel 4 offset and enable channels 1 to 3 again ipixi iojxi D fe Edt View Toos Window Heb 18 x E Ble Edt Vew Toos Window Hep 18 xj ooms y taok SEPRE fee say oH sis fle eee Sanie Dio Tio SERRE Semple Disp Trig Se eee eee BECCONC Ceo Base 10mS Dv Cano Base SO S ON Z Poi fvov LEATS VCH fivioV VM CH2 ivioVv x COCA VW CH2 spov COCCCCCCCCe ea a COO ro fivov Figure 7 0h Two screen dumps of scope exe demonstrating different display settings The Sample tab of the controls dialog sets the sample rate mode Sample Disp Trig and input range of the scope Note at present the control communication protocol has not been Sample 1 00kHz implemented hence the selected sample rate will not actually change Rate the rate that the PIC is sampling But it is important that the correct sample rate is selected
206. oftware Development Friday 21 June 2002 Final Report Colin K McCord Setup RS232 dome ckleN Hardware UART 20us delay O Read ADC 100Hz baud rate 9600 Setup ADC Convert reading y 10 bits right SELES C Memel into real time Be fl ae justified ANO frame structure Figure 10 3a Mark 3 flowchart Mark 3 c source code IR ecto Ba ae ae oo oo FILE mark 3 c PROJECT Low Cost PC Based Oscilloscope DESC Read CH1 ADC transmit result through RS232 using the real time frame format a S222222 DATE 19 02 2002 BY Colin K McCord VERSION 1 1 include lt 16F877 h gt device PIC16F877 16 ADC 10 use device adc 10 to implement a 10 bit conversion otherwise the default is 8 bits fuses HS NOWDT NOPROTECT NOLVP use delay clock 4000000 use rs232 baud 9600 xmit PIN C6 parity N bits 8 rcv PIN C7 main NOTE long int adcValue char adcHI adcLO by default in CCS all var s are unsigned 16 bit storage for ADC reading 8 bit storage for real time frames setup_adc_ports A ANALOG setup adc ADC CLOCK INTERNAL set_adc_channel 0 RAO RA4 Analogue REO RE2 digital Use internal ADC clock delay_us 20 Delay for sampling cap to charge while TRUE adcValue read_adc Get ADC reading Convert 16 bit adcValue
207. ogram samples all four channels chop mode For example channel 1 is sampled then channel 2 then channel 3 and then channel 4 See figure 10 9a for a simplified flowchart of the program Setup RS232 c it readi Hardware UART onyen reading Transmit 20us delay Read ADC into real time Ea baud rate set by frame structure Rigen Welt DIP switches Setup ADC P 10 bits right Select channel Se ere Read ADC Select channel justified select ANI frame structure ANO channel ANO Transmit Transmit 20us delay real time frame real time frame 20us delay 20us delay Setup Timer 2 Convert reading mene eT POr EE Select channel select channel 20us frame structure TimeBaseMUX Transmit 50 Read ADC 20us delay ti 1000Hz real time frame Convert reading ues npe Read ADC into real time frame structure OE coe DEC TimeBase TimeBase bSample l time TimeBase oe Y gt TimeBaseMUX gt TRUE Figure 10 9a Mark 9 flowchart Mark 9 c source code ee E E E N N E FILE mark_9 c PROJECT Low Cost PC Based Oscilloscope DESC real time sampling using Interrupt timebase time base is fixed All channels are sampled CH1 to CH4 chop
208. ol the input range but this has not implement shortage of time future development hence for the amplitude values on the simulator program to be accurate the correct range must be selected This program can still be used to test other voltage input ranges for example the simulator program 5V represents an ADC reading of 1024 and OV represents an ADC reading of 0 hence if 10 to 10 V range on the scope program is selected 5V will represent 10V 2 5V will represent OV and OV will represent 10V Simulation of all four channels is possible after the user has setup each channel communication with the scope program is enabled by clicking the Enable button The user can even specify a simulated sample rate basically specifying how many real time frames are transmitted per second EEE516J4 Honours Project Page 86 Chapter 8 The Simulator Program Friday 21 June 2002 Final Report Colin K McCord Figure 8 0b shows a screen dump of the Options dialog box which is used to configure the RS232 serial port in a user friendly manner x m Communications Port comi gt Byte Size le x Baud Rate faso0 Stop Bits ho Parity No Parity v oie Cancel Apply Figure 8 0b Screen dump of options dialog in sim exe V1 007a 29 03 2002 Figure 8 0c shows a screen dump of the About dialog box which displays information about the program and the author including some useful hyperlinks About PC Based Oscillosco
209. onours Project Page 30 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord But alternate has a disadvantage timing information between different channels e g channel 1 leads channel 2 by 25ms is lost It is possible to software correct this problem for example using one of the PICs real time timers it is known how mush time as elapsed between the sampling of channels this information could be transmitted to the PC Scope program which then draws waveforms with the correct time gap between channels Another disadvantage is that continuous monitoring is impossible as there are gaps in channel data e g continuous monitoring required for an ECG signal It is clear that alternate mode is only useful for periodical waveforms e g sinewave else chop mode should be used 6 2 Storage Mode Read a finite number of samples storing them into RAM external RAM chip The readings are then transferred to the PC in one large block hence removing the RS232 bottleneck and providing faster sample rates E Leti 1 No Delay Yes v v Transmit Array Read ADC a A Array i ADC Value a Yy Increment i Figure 6 2a Illustration of storage mode with one channel gt Leti 1 No Array i Array i i gt 1000 Delay Channel2 gt Incrementi
210. op interrupt time base 10 10 Mark 10 c Test External RAM Chip 10 11 Mark 11 c Main Program 11 0 Test Results 11 1 Test Session 1 FG Wilson Lab 26 02 2002 11 1 1 Test 1 Test RS232 Communications TX only 11 1 2 Test 2 Fully Test RS232 Communications 11 1 3 Test 3 Test ADC 11 1 4 Conclusion 11 2 Test Session 2 FG Wilson Lab 05 03 2002 11 2 1 Test 4 Test RS232 Communications Baud Rate set by DIP Switches 11 2 2 Test 5 Fully Test RS232 Communications Baud rate set by DIP Switches 11 2 3 Test 6 Test ADC Scope Program and Real time Communication Protocol 11 2 3 1 Sample Rate Changed to 2000Hz mark6b c 11 2 3 2 Sample Rate Changed to 5000Hz mark6c c 11 2 4 Test 7 Test Timer Interrupts 11 2 5 Conclusion 11 3 Test Session 3 FG Wilson Lab 22 03 2002 11 3 1 Test 8 Dual Channel Test 11 3 2 Test 9 Interrupt Drive Time Base Real Time Sampling Four Channels 11 3 2 1 Dual Channel Operation Using Two Signal Generators 11 3 2 2 Quad Channel Operation 11 3 2 3 5 000Hz Sample Rate Single Channel 11 3 3 Test 10 Test External RAM Chip 11 3 4 Test 11 5V Regulator 11 3 5 Test 12 Analogue Circuitry 11 3 6 Conclusion 12 0 Conclusions 13 0 Recommendations For Further Work 13 1 Control Protocol 13 2 Storage Mode 13 3 Multiple Serial Ports 13 4 USB Transport Medium 13 5 Bootstrap EEE516J4 Honours Project Page VI Colin K McCord Pages 77 to 80 Pages 78 to 80 Pages 81 to 8
211. opes ia oN lt a fia oN z z gt iia ON fa 7 Basic scopes Advanced scopes Sees with long Storage scopes Sampling scopes x persistence screens x gt A D traditional storage d i Dual trace dual beam i ae Single trace scopes scopes with storage Digital storage scopes scopes L L CRT x Figure 3 1b Types of CRT oscilloscopes EEE516J4 Honours Project Page 5 Chapter 3 Fundamentals Friday 21 June 2002 Final Report Colin K McCord 3 2 Digital Sampling Oscilloscopes Digital sampling oscilloscopes use an ADC analogue to digital converter to converter analogue voltages to binary representation The sampling rate specifies the number of samples taken per second Figure 3 2a demonstrates clearly how an analogue wave form is digitally sampled and displayed onto the screen LCD Computer Monitor etc 50Hz sine wave sampled at 500Hz x10 S1 S2 3 S4 5 S6 S7 S8 S9 S10 Array containing ADC readings at each sample point Draw Waveform using Pulse Interpolator join the dots Figure 3 2a Example showing how a sine wave is digitally sampled 3 3 Display Formats There are three main methods of presenting the captured waveform on the screen These are dot display dot joining also called linear or pulse interpolation and sine interpolation These are illustrated in Figure 3 3a Dot display requires 20 to 25 sampl
212. or is to large at slower speeds PIN C6 rcv PIN C7 parity N bits 8 use fast_io E Fast access to PortE don t fiddle with TRISE Forward declaration of functions void SetBaudRate main NOTE by default in CCS all var s are unsigned long int adcValue 16 bit storage for ADC reading char adcHI adcLO 8 bit storage for real time frames set_tris_e 0x17 TRISE 00010111 RE2 RE1 and REO TTL Inputs SetBaudRate setup_adc_ports A_ANALOG RAO RA4 Analogue REO RE2 digital setup adc ADC CLOCK INTERNAL Use internal ADC clock set_adc_channel 0 delay_us 20 Delay for sampling cap to charge while TRUE adcValue read_adc Get ADC reading Convert 16 bit adcValue to Real time frame structure CH1 adcHI char adcValue gt gt 5 amp Oxlf 01 0101d9 d81da7 d6 d5 adcLO char adcValue amp Oxl1f 0x80 11010 d4 d3 d2 d1 da0 putc adcHI Transmit Byte 1 d9 d5 putc adcLO Transmit Byte 2 d4 d0 delay ms 1 Preset delay repeat every lms that s 1000 Hz baud rate must be at least 20000bps try 32768bps void SetBaudRate switch PORTE amp 0x07 Read dip switches and setup baud rate case 0 set_uart_ speed 4800 break case 1 set_uart_ speed 9600 break case 2 set_uart_speed 14400 break case 3 set_uart_speed 19200 break case 4 set_uart_speed 32768 brea
213. ord before the hardware is constructed and PIC embedded software is written This program works well and was successfully used to test the scope program allow storage mode operation and the control protocol are yet to be implemented hence more development is still required Evidently the entire system has been demonstrated to work together as a basic real time low frequency oscilloscope up to 5 kHz as the test results show in chapter 11 Clearly the maximum possible real time sample rate is 5 75 kHz with one RS232 link a low pass filter is required anti aliasing to filter all frequencies above half the sample rate in this case the filter should filter out frequencies above 2 875kHz hence because the system has a low frequency cut off of OHz e g DC waveforms can be monitored the system has an analogue bandwidth of 2 875 kHz Clearly there is no reason why multiple scopes cannot be used for example two scope programs can be executed in windows one could be configured to use COM1 the other COM2 Hardware can be connected to COM1 and other set of hardware connected to COM2 Hence up to 8 channels can be monitored simultaneously on one computer screen Obviously the only limit is the number of serial ports the PC has and how many scope programs it is capable of running simultaneously i e processor power Also it is important to note that the chosen PIC has 8 input pins to the ADC hence with minor modifications to the scope program cut am
214. ort Medium The USB port is ideal for this type of application 12 Mbps this takes away the RS232 bottleneck providing faster real time sample rates Note the USB throughput if far faster than the PICs ADC 43 63 ksps hence this is the new bottleneck of the system There is no need for storage mode as the USB throughput is capable of transmitting a sample rate up to 600 kHz 12 000 000 20 in real time using external ADC Note the USB port can have many devices daisy chained the communication protocol must be complaint with the USB standard This USB communication protocol standard is quite large and complex hence a dedicated PIC maybe required to deal with USB communication while another does the sampling Note that USB communication protocol is packet based lets other devices share the same link hence the actual throughput will be less than stated above Note the scope program is designed to flexible and should be easy to integrated with the USB standard actually Microsoft probably has a standard C plug in object available for visual C designed for letting C programmers e g the scope program use the USB port without total knowledge of the USB communication protocol e g automatically converts into correct packets Unfortunately interfacing the PIC will be a completely different story 13 5 Bootstrap The chosen PIC can protect blocks of program memory hence a bootstrap program can be written to check the serial interface before
215. p include XTabCtrl cpp include StatLink cpp include ColorStatic cpp Step 2 Add include BCMenu h m_default and m_menu to MainFrm h MainFrm h interface of the CMainFrame class 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 111 if defined AFX_MAINFRM H 8C66EB30 6DEB 4044 863D D90EA5FE5723__ INCLUDED define AFX_MAINFRM H _8C66EB30 6DEB 4044 863D D90EA5FE5723_ INCLUDED if MSC VER gt 1000 pragma once endif _MSC_VER gt 1000 class CMainFrame public CMDIFrameWnd public void ComRealTimeBuffered void ComRealTimeScroll Step 3 Add function NewMenu to class CMainFrame Notice menu bitmaps are from toolbars EEE516J4 Honours Project Page 78 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord HMENU CMainFrame NewMenu static UINT toolbars IDR_MAINFRAME IDR_TOOLBAR Load the menu from the resources m_menu LoadMenu IDR_SCOPETYPE One method for adding bitmaps to menu options is through the LoadToolbars member function This method allows you to add all the bitmaps in a toolbar object to menu options if they exist The first function parameter is an array of toolbar id s The second is the number of toolbar id s There is also a function called LoadToolbar that just takes a
216. p paste drawing of waveforms etc hardware remove dip switches from port E and embedded software sample channel 1 to 8 eight channels could be monitored simultaneously that s 16 channels if two scopes are used but at a reduced sample rate when all eight channels are enabled unless using storage or real time alternate mode Adding storage functionally to the scope was the last thing to be done clearly this feature is not complete but good progress has been made as block diagrams of the communication protocol and frame structure were included in this report It is important to relies that storage mode should theoretically allow for faster sample rates which are not limited by the speed of the transport medium e g the PIC reads 1000 readings from channel 1 at 20KHz then stops sampling and transfers the data to the PC using the storage mode frame structure including CRC via RS232 once ACK Acknowledgement is received from the PC the PIC starts sampling again If NAK Negative Acknowledgement is received or a timeout occurs the PIC retransmits the frame Clearly most of the ground work for implementing storage mode operation has been done for example functions for writing to the RAM chip were successfully written and tested and implementation can easily be achieved if more time was available Evidently the maximum sample rate when operating in storage mode is the speed of the ADC this was calculated to be 43 63 kHz Hence since freq
217. pbi bi Call GetDIBits with a NULL lpBits param so the device driver will calculate the biSizeImage field GetDIBits hDC HBITMAP bitmap GetSafeHandle OL DWORD bi biHeight LPBYTE NULL LPBITMAPINFO lpbi DWORD DIB RGB COLORS bi lpbi I the driver did not fill in the biSizeImage field then compute it Bach scan line of the image is aligned on a DWORD 32bit boundary if bi biSizeImage 0 bi biSizeImage bi biWidth bi biBitCount 31 amp 31 8 bi biHeight If a compression scheme is used the result may infact be larger Increase the size to account for this if dwCompression BI_RGB bi biSizeImage bi biSizeImage 3 2 Realloc the buffer so that it can hold all the bits dwLen bi biSizeImage if handle GlobalReAlloc hDIB dwLen GMEM MOVEABLE EEE516J4 Honours Project Page 74 Chapter 7 The Scope Program Friday 21 June 2002 Final Report hDIB handle else GlobalFree hDIB Reselect the original palette SelectPalette hDC hPal FALSE ReleaseDC NULL hDC return NULL Get the bitmap bits lpbi LPBITMAPINFOHEADER hDIB FINALLY get the DIB BOOL bGotBits GetDIBits hDC HBITMAP bitmap GetSafeHandle OL Start scan line DWORD bi biHeight of scan lines LPBYTE lpbi address for bitmap bits bi biSize nColors sizeof RGBQUAD LPBITMAPINEFO lpbi address of bitmapi
218. pe PIC Simulator Exi Low cost PC based real time storage oscilloscope Version 1 007a By Colin McCord Date 29 March 2002 itry of U lord Course BEng hons Electronic Systems Module Honours Project EEE516J4 First Supervisor Dr S Katzen Second Supervisor DrC Tuner Figure 8 0c Screen dump of about dialog in sim exe V1 007a 29 03 2002 8 1 How Channel Simulation Is Achieved A real time software interrupt is used to call the communication protocol function ComProtocolTop When an interrupt occurs the program first checks that communications is enabled if its enabled function EEE516J4 Honours Project Page 87 Chapter 8 The Simulator Program Friday 21 June 2002 Final Report Colin K McCord ComProtocolTop is called then it sets the timer delay until next interrupt based on the specified simulated sample rate so that the specified number of samples per second is actually transmitted per second This function is called on software interrupt void CSimDlg OnTimer UINT nIDEvent double timer freq if nIDEvent ID_TIMER_COMS KillTimer ID TIMER COMS if m Enable true ComProtocolTop Set the timer based on the value in the sample rate edit box freq double GetDlgItemInt IDC_SAMPLERATE timer 1 0 freq 10000 0 SetTimer ID _TIMER_COMS int timer NULL CDialog OnTimer nIDEvent This function is called by the
219. per cycle hence the calculated frequency of the waveform is 1 9 9 0 005 20 2Hz EEE516J4 Honours Project Page 128 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord ce gt gt EHER f 3 f a f Figure 11 2 3 1i Screen dump of scope program sample rate 2 000Hz input wave 20Hz trianglewave 0 5V 20Hz squarewave 0 5V connected to CH1 ANO see figure 11 2 3 1j resolution 200 x 160 that s 20 x 16 divisions 9 9 division per cycle hence the calculated frequency of the waveform is 1 9 9 0 005 20 2Hz pe B Fle Edt Vew Toos Window Help d S S S a a F f 3 F f 3 F Ready Figure 11 2 3 1j Screen dump of scope program sample rate 2 000Hz input wave 20Hz squarewave 0 5V 11 2 3 2 Sample rate changed to 5000Hz mark6c c Hence scope time base is 0 002 seconds per division that s 500Hz EEE516J4 Honours Project Page 129 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 50Hz sinewave 0 5V connected to CH1 ANO see figure 11 2 3 2a resolution 200 x 160 that s 20 x 16 divisions 8 division per cycle hence the calculated frequency of the waveform is 1 8 0 002 62 5Hz Clearly something bad has happed here there are gaps in the data The reason for this is that the UART transmit buffer fills up and the program must wait until the transmit buffer is free to accepted another character hence there is an
220. play multiple scope windows each one with its own selected channels enabled impendent triggering time bases scales and grid resolution It was not sure how useful this feature might be and during development it was considered that this feature may have been dropped on the finished application Fortunately this was not the case and indisputably it may have some use for specialist applications and it s another one of those features Bells and Whistles that sets this project apart EEE516J4 Honours Project Page 149 Chapter 12 Conclusions Friday 21 June 2002 Final Report Colin K McCord from other similar products It is clear that there is no limit on how many scope windows can be opened simultaneously perhaps until the computer runs out of memory which on a modern PC could be 1000s of windows Evidently direct access to the hardware is not allowed under Windows NT 2000 XP Hence the reason why interaction with the serial port was achieved using a file handle and various WIN32 communication API s Note this method is also Windows 95 98 ME compatible The scope program has been successfully tested on Windows 98 NT 2000 XP and theirs no reason why the program should not work on Windows 95 ME allow comprehensive testing is required Simulated random noise tests running for hour s non stop was used to test the reliability of the scope application e g can it recover when the noise is removed or has it crashed the program continued
221. ramming language C was chosen and not the low level assembly code normally associated with PIC programming There are many advantages for using C including ease of programming ease of modification reusability of code use of standard functions e g printf getc putc etc etc But there is one drawback C code is much less efficient for example typically code produced by the C compiler CCS is at least twice as large as that programmed in assembly Since the PIC16F877 has a large program store 8k and runs at 20MHz this drawback is not a problem 10 1 Mark 1 c Test RS232 Communications This program is extremely simple basically it initialises RS232 communications and transmits Testing once a second see figure 10 1a This program was used to test RS232 communications transmit mode including MAX232 PIC UART and cable The PIC is connected to a PC which is running the DOS based test program in RX terminal mode to receive the incoming characters T Setup RS232 z r meneniete UNRI T GN gt 1 Second Delay baud rate 9600 esting Figure 10 1a Mark 1 flowchart Mark 1 c source code ee a a ee a a ee a a FILE mark l c PROJECT Low Cost PC Based Oscilloscope DESC Test RS232 SSSSSS SSS SS SSS SSS SSS SSS SSS SS SSS SSS SSS SSS SSS SS SSS SSS DATE 19 02 2002 BY Colin K McCord VERSION 1 0 include lt 16F877 h
222. rk 5 c Fully Test RS232 Communications Adjustable Baud Rate Same as mark2 c with the addition of function SetBaudRate this function sets the UART baud rate based on the positions of the DIP switches that are connected to port E This program is used to fully test RS232 communications at different baud rates Mark 5 c source code ah pai pes poa pa poa pen poai pan poa ma paa paa poa pa a a a ho pa a p FILE mark_5 c PROJECT Low Cost PC Based Oscilloscope DESC Test Serial Communications waits for an incoming char and transmits the char Baud rate set by dip switches DATE 01 03 2002 BY Colin K McCord VERSION 1 0 a a a a ee ee include lt 16F877 h gt device PIC16F877 16 ADC 10 fuses HS NOWDT NOPROTECT NOLVP byte PORTE 0x09 PortE lives in File 9 Note 20MHz clock must be used for 115 000 bps the error is to large at slower speeds use delay clock 20000000 20MHz clock use rs232 baud 9600 xmit PIN C6 rcv PIN C7 parity N bits 8 Forward declaration of functions void SetBaudRate main set_tris e 0x17 TRISE 00010111 RE2 RE1 and REO TTL Inputs SetBaudRate Note kbhit can be used to check for incoming char before calling getc while TRUE putc getc Wait for incoming char and transmit void SetBaudRate switch PORTE amp 0x07 Read dip switches and setup baud rate case 0 set_uart_speed 4800 break
223. roject Page 20 Chapter 4 The PIC16F877 Microcontroller Friday 21 June 2002 Final Report Colin K McCord 5 0 HARDWARE DEVELOPMENT The purpose of this project is to design built and test a low cost PC based digital real time storage oscilloscope The main reasoning behind hardware development was to keep the hardware cost to an absolute minimum It was decided to use the PIC16F877 flash version The PIC16F877 is a high performance FLASH microcontroller that provides engineers with the highest design flexibility possible In addition to 8192x14 words of FLASH program memory 256 data memory bytes and 368 bytes of user RAM PIC16F877 also features an integrated 8 channel 10 bit Analogue to Digital converter Peripherals include two 8 bit timers one 16 bit timer a Watchdog timer Brown Out Reset BOR In Circuit Serial Programming RS 485 type UART for multi drop data acquisition applications and 12C or SPI communications capability for peripheral expansion Precision timing interfaces are accommodated through two CCP modules and two PWM modules The PIC16F877 also supports low voltage self programming allowing the user to program the device in circuit at the user s operating voltage The in circuit debugging feature allows the designer to emulate the PIC16F877 device without an in circuit emulator the MCU itself is the emulator PIC16F877 applications range from body controllers programmable machine controls n
224. roject Page 60 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord else if temp_int 1 m_sComPort Com2 else if temp_int 2 m_sComPort Com3 else if temp_int 3 m_sComPort Com4 else m_sComPort Coml temp_int pApp gt GetProfileInt Config Baud D BAUD if temp_int 0 baud 1200 else if temp_int 1 baud 2400 else if temp_int 2 baud 4800 else if temp_int 3 baud 9600 else if temp_int 4 baud 14400 else if temp_int 5 baud 19200 else if temp_int 6 baud 32768 else if temp_int 7 baud 38400 else if temp_int 8 baud 57600 else if temp_int 9 baud 115200 else baud 9600 temp_int pApp gt GetProfileInt Config Byte Size D BYTE if temp_int 0 byte 7 else if temp_int 1 byte 8 else byte 8 temp_int pApp gt GetProfileInt Config Parity D PARITY if temp_int 0 parity EVENPARITY else if temp_int 1 parity MARKPARITY else if temp_int 2 parity NOPARITY else if temp_int 3 parity ODDPARITY else if temp_int 4 parity SPACEPARITY else partiy NOPARITY temp_int pApp gt GetProfileInt Config Stop Bits D STOP if temp_int 0 StopBits ONESTOPBIT else if temp_int 1 StopBits ONESSTOPBITS else if temp_int 2 StopBits TWOSTOPBITS else StopBits ONESTOPBIT m_hCom CreateFile m_sComPort GENERIC READ GENERIC
225. s occurred Channel 2 unaffected Fr SC Scopel E O x Fie Edt Vew Toos Window Hep Peou gRtmwt ESE ga Sample Disp Trig Time Base Men fiviov gt Moe sviov cus fiviov E 23 Toos Window Help IAE Men fvov Mohe svov gt Men fiviov gt f Figure 11 3 2 1f Screen dump of scope program sample rate 1 kHz CH1 500Hz sinewave CH2 30Hz sinewave EEE516J4 Honours Project Page 137 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Channel 1 connected to 10Hz sine wave 5Vpp channel 2 connected to 10Hz sine wave 4Vpp see figure 11 3 2 1f Channel 1 10 divisions per cycle hence the calculated frequency is 1 10 0 01 10Hz Channel 2 4 2 divisions per cycle hence the calculated frequency is 1 10 0 01 10 Hz Channel 1 connected to 10Hz sine wave 5Vpp channel 2 connected to 50Hz sine wave 4Vpp see figure 11 3 2 1g Channel 1 unaffected Channel 2 2 divisions per cycle hence the calculated frequency is 1 2 0 01 50 Hz e 8 8 So Figure 11 3 2 1h Screen dump of scope program sample rate 1 kHz CH1 10Hz sinewave CH2 100Hz sinewave EEE516J4 Honours Project Page 138 10 x Sample Disp Trig Time Base vy CHI TV DIV v M cHe 5viDV CH3 Sample Disp Trg Time Base hem fiviov x Mohe fsviov eH fiviov B iv Chapter 11 Test Results Friday 21 June 2
226. screen e The ability to hold or retain a signal in memory for long periods Core Objectives Design and construct hardware required for data acquisition Design of the real time communication protocol Design of a Windows application for displaying low frequency waveforms in real time Design of a simulation program Demonstrate the entire system working Further Development e Add storage functionally increasing its sampling rate to at least 20 kHz e Using external ADC and external RAM explain how it would be possible to monitor high frequency waveforms e Investigate how far this storage technique can be pushed what are the limits Summary Low Cost PC Based Oscilloscope PIC16F877 microcontroller for data acquisition using 4 of the built in ADCs 4 channel scope Analogue circuitry to insure 0 to 5 V input to ADC e g 100 to 100V converted to 0 to 5V i e bipolar Windows application scope exe for displaying waveforms Simulator program for testing graphical display communication protocols and triggering techniques Possible Application e Demonstration oscilloscope using data projector and laptop Advantages Large high resolution display Windows GUI advantage such as cut amp paste into documents Low cost less than 50 Software Upgradeable EEE516J4 Honours Project Page Il Executive Summary Friday 21 June 2002 Final Report NOTATION Abbreviations and symbols used in this report are listed
227. se the mouse wheel to change zoom levels while halding down the following keys F Shift F Ctr Zoom Window Style C Magnifying glass z Launch 2 Wind Centred on cursor ee ad Figure 7 14c nView Desktop Manager Clearly the scope program is far too processor hungry and future modification is required to make it more efficient Allow if 10 of the processor is used for a 1 5GHz machine this means the program should run on a 150 MHz machine perhaps poorly By reducing the refresh rate of the scope display or using a high end video card the scope program could be ran on slower machines it has been tested on a p90 and runs smoothly with a refresh rate of 200 milliseconds but the CPU load is at 100 and scope controls are sluggish to react to user input EEE516J4 Honours Project Page 85 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord 8 0 THE SIMULATOR PROGRAM This program is a windows dialog based program written in Microsoft Visual C 6 0 Figure 8 0a shows a screen dump of the main dialog The program is easy to use the user selects the type of waveform amplitude and frequency for each channel The PC based scope program will automatically enable disable channels using the control protocol user can override using the tick boxes beside channel number z PC Based Oscilloscope PIC Simulator x File Tools Help M Chanell M Channel Sinewave Freq Hz 50
228. sically it waits for an incoming character and transmits it This is a very simple method of fully testing the RS232 communication PIC software PIC MAX232 cable and wiring The DOS based test program test exe version 1 05 was used to carryout two separate tests The first used the TX terminal to transmit a message then the RX terminal is used to receive the message if the RX amp TX messages are identical the test is successful The second used the loop back test function of the test program this stresses the communications as a large amount of data is transmitted and compared with the received block of data Screen dump of test program test exe in TX terminal mode then RX terminal mode TX Terminal Type your message hit ENTER to transmit Testing RS232 Communications Sending Messaging Testing RS232 Communications Message sent successfully RX Terminal Waiting for message press a key to stop Testing RS232 Communications Screen dump of test program test exe after loop back test was completed Test Started 13 37 31 Testing 100 PASS Test 1 PASS Test 2 PASS Test 3 PASS Test Finished 13 37 33 Hit any Key to return to main menu Clearly the RS232 communication tests were successful note baud rate 9600bps OSC 4 MHz RS232 cable length unshielded 1 5m 11 1 3 Test 3 Test ADC Program mark3 c Version 1 1 was compiled and load
229. single 5V power supply Recall that RS232 requires 3 to 12 volts for a logic 0 and 3 to 12 volts for a logic 1 the MAX232CPE has a built in external capacitors required voltage doubler circuit 10V and a voltage inverter circuit 10V This reduces product cost as the other option is to using a switch mode DC to DC converter cost about 5 to generate required power supply Allow a 15 and 15 supply is required for the analogue circuit hence a DC to DC converter is required anyway Allow the max232 data sheet states that the 10 and 10 voltage pins could be used to drive other circuits but it is not recommended plus its good design practice to keep analogue and digital circuits separate problems with noise Figure 5 2b Dip switch configuration EEE516J4 Honours Project Page 23 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord Y amp IA Y 8 IN 8 Al N al R a al A M6264P 15 4 D 2 39 I 41 CH1 DG c5 c3 CH2 3 38 oa it 1uF ro VCC CH3 4 37 5 36 fe 1 vec 2 CH4 IC1 V 6 7 8 2 9 2 VCC D70 D 7 uF 5V to 10V 35 3 Ic4 Voltage D3 Ker oes DIP SW R1 R2 RS 1 DO 32 c4 as 8 1uF 10 31 d 1 Q 1 30 6 d K L 12 29 2 i i 13 28 7 A 14 27 3 O a A 15 26 8 C A 8 16 25 4 g J 17 24 9 10 J 4 40 20MHz 18
230. space Bell etc If anykey is pressed the program returns to the main menu This function can be used to test the PICs RS232 transmit mode and all of the hardware involved e g PIC UART MAX232 and cable It can also be used to help debug the PIC software e g printf CCS code can be used to display variable information in order to try and workout what is happening 2 TX Terminal TX Terminal Type your message hit ENTER to transmit Simple TX terminal the user types in a message and then hits the ENTER key to transmitted the message through RS232 Note after transmission the RX Terminal function is automatically called so that any replay can be received This function can be used to test the PICs RS232 receive mode and all of the hardware involved e g PIC UART MAX232 and cable Since RX terminal is called automatically after transmission it is possible to fully test RS232 communications e g setup the PIC so that it transmits every character it receives If the received message is the same as the transmitted message clearly RS232 communications is working EEE516J4 Honours Project Page 90 Chapter 9 Test Program Friday 21 June 2002 Final Report Colin K McCord 3 Manual RTU frame with CRC Manual RTU frame with added CRC Enter RTU frame in byte s enter DF when finished RTU frame 0 e g 01 01 RTU frame 1 e g 01 02 RTU frame 2
231. tage over using preset delays delay routines do not take into consideration processing delays e g waiting for UART buffer to empty while the PICs real time timer will continue to count no matter what the PIC is doing and will cause an interrupt every 20uS assuming interrupt routine is finished before it is time to called it again This program samples all four channels chop mode E g channel 1 is sampled then channel 2 then channel 3 then channel 4 It is expected that Alt mode will be added some time in the future e g sample channel 1 a thousand times then sample channel 2 a thousand times etc The following experiments were carried out with the TimeBaseMux equal to 50 that s a time base of 1000Hz 1 50 20uS and baud rate was set at 115kbps Scope exe version 1 036 19 03 2002 was used and a calibrated function generator Fluke PM5139 used to generate input signals Note Sample rate 1000Hz 10 horizontal samples per division Hence scope time base is 0 01 seconds per division Time base is fixed on this version of the scope program EEE516J4 Honours Project Page 132 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord 25Hz sinewave 0 5V connected to CH1 ANO and all other channels connected to 5V see figure 11 3 2a 4 divisions per cycle hence the calculated channel 1 frequency is 1 4 0 01 25Hz Channels 2 3 amp 4 are at 5V DC e Scope Scopel ae la x Ee Edt Vew Toos
232. tals Friday 21 June 2002 Final Report Colin K McCord PICs use the Harvard architecture The Harvard architecture Figure 3 5b is an adaptation of the standard von Neumann structure with separate program and data memory data memory is made up by a small number of 8 bit registers and program memory is 12 to 16 bits wide EPROM FLASH or ROM Memory CPU N Memory Data Program Figure 3 5b Simplified illustration of the Harvard architecture Traditional CISC Complex Instruction Set Computer machines Used in 80X86 8051 6800 68000 etc have many instructions usually gt 100 many addressing modes and it usually takes more than 1 internal clock cycle to execute PIC microcontrollers are RISC Reduced Instruction Set Computer machines which have 33 12 bit to 58 15 bit instructions reduced addressing modes PICs have only direct and indirect each instruction does less but usually executes in one internal clock The combination of single word instructions the simplified instruction decoder implicit with the RISC paradigm and the Harvard separate program and data buses gives a fast efficient and cost effective processor implementation B3 3 5 1 Summary of the PICs Built in Peripherals SPI Serial Peripheral Interface uses 3 wires data in data out clock Master Slave can have multiple masters very high speed 1 6 Mbps and full speed simultaneous send and receive full duplex C Inter IC uses 2
233. teProfileInt Config Parity m Combo Parity GetCurSel pApp gt WriteProfilelInt Config Stop Bits m Combo Stop Bits GetCurSel pApp gt WriteProfilelInt Config Timer GetDlgItemInt IDC_TIMER OnChange Screen dump showing where RS232 configuration is stored amp Registry Editor u 5 xj Regstry Edt View Favorites Help 3 MeCords Software Type Data Scope ab Default REG_SZ value not set B Config Baud REG_DWORD 0x00000009 9 E PageSetup Byte Size REG_DWORD 0x0000000 1 1 Gy Recent File List j Ecom REG_DWORD 0x00000000 0 Settings alParity REG_DWORD 0x00000002 2 Stop Bits REG_DWORD 0x00000000 0 Pam zj Timer REG_DWORD 0x00000001 1 My Computer KEY CURRENT _LSER Softwaree Cords Sftwar Scope Coriig i Figure 7 5b Screen dump of windows registry Note direct access to the hardware is not allowed under Windows NT 2000 XP Interaction with the serial port is achieved through a file handle and various WIN32 communication API s This method is Windows 95 98 ME compatible This function initialises the communications using configuration settings from windows registry void CMainFrame InitalCom 24 12 01 by colin mccord CScopeApp pApp CScopeApp AfxGetApp int temp_int DWORD baud BYTE parity byte StopBits temp_int pApp gt GetProfileInt Config COM D COM if temp_int 0 m_sComPort Com1 EEE516J4 Honours P
234. ted yet do not continue if penCH1 NULL return Select CH1 pen CPen pOldPen m_dcCH1 SelectObject penCH1 Clear display m_dcCH1 SetBkColor BLACK m_dcCH1 FillRect amp m_ClientRect amp Brush EEE516J4 Honours Project Page 56 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord If Channel 1 is disabled do not continue if pDoc gt m_bCH1 ENABLE false m_dcCH1 SelectObject pOldPen Invalidate TRUE Redraw Display return if pDoc gt m_TimeBaseMUX lt 0 Increase Timebase m_ Skip pDoc gt m_TimeBaseMUX 1 m MUX 1 else Reduce Timebase m Skip 1 m MUX pDoc gt m_TimeBaseMUX Draw waveform to memory DC for i m_nTriggerCH1 m_nCH1 Offset m _MUX m_Skip i lt 10000 i i m MUX if m_Skip gt 5000 break Check for possible overflow yl m_nCH1POS pApp gt m_nCH1Volt i m_MUX m_nVPD_CH1 ie yl Sy yl y if yl lt 0 yl 0 if a m_Skip lt 0 a m Skip if i gt 0 m_dcCH1 MoveTo m_nGridX a m_Skip m_nGridY y1 y2 m_nCH1POSt pApp gt m_nCH1Volt i m_nVPD_CH1 iE ya gt yp ye Sys LE y2 lt 0 ye Q if i gt 0 m_dcCH1 LineTo m_nGridx a m_nGridY y2 a a m Skip Lf a gt i 10001 break draw zero point Arrow m_dcCH1 MoveTo 8 m_nGridY m_nCH1POS m_dcCH1 LineTo 2 m_nGridY m_nCH1POS 5 m_dcCH1 LineTo 2 m_nGridY m_nCH1POS 5 m_dcCH1
235. that s 1638 Cycles Lookup table CRC test program crcLT c include lt 16F877 h gt Table of CRC values for high order byte const char Table CRC_Hi 256 EEE516J4 Honours Project Page 39 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report 0x00 OXC1 OX81 OX40 OX01 OXCO 0X80 0X41 0X01 OXCO 0X80 0x40 OX01 OXCO OX80 OX41 OX00 OXC1 0X81 0X40 OX00 OXC1 0x80 OX41 OX01 OXCO 0X80 OX41 0X00 OXC1 0X81 0X40 0X00 OXCO 0x80 0X41 0X00 OXC1 0x81 0X40 0X01 OXCO 0X80 0X41 0x00 0XC1 0X81 0x40 0X01 OXCO 0X80 0X41 0X00 0XC1 0X81 0x40 0X01 OXCO 0x80 0X41 0x00 OXC1 0X81 0X40 0X01 OXCO 0x80 0x41 0X00 0XC1 0X81 0x40 0X00 0XC1 0X81 0X40 0X01 OXCO 0x80 0X41 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0X41 0x00 0XC1 0X81 0x40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0x40 0X00 OXC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X00 OXC1 0x80 0x41 0X01 OXCO 0X80 OX41 0X00 0XC1 0X81 0X40 0X00 OXCO 0x80 0X41 0X01 OXCO 0x80 0X41 0x00 OXC1 0X81 0X40 0x00 0XC1 0X81 0x40 0X00 0XC1 0X81 0X40 0X01 OXCO 0X80 0x40 0X01 OXCO 0x80 0X41 0X01 OXCO 0x80 0X41 0X00 0XC1 0x80 0x41 0x00 0XC1 0X81 0x40 0X00 0XC1 0X81 0X40 0X01 OXCO 0x80 0X41 0X00 OXC1 OX81 0X40 0x00 OXC1 0X81 0X40 0x00 OXC1 0X81 0X40 0X01 OXCO 0X80 0X41 0X01 OXCO 0X80 0x40
236. the readings to the PC via RS232 in one large block including CRC or check sum once ACK Acknowledgement is received from the PC the PIC starts sampling again and the process repeats forever Another option is to use a different transport medium e g USB Parallel which would allow for faster real time sample rates Note the real time communication protocol does not rely on the transport medium hence if the transport medium is changed the real time protocol should be OK Expect for maybe USB as USB ports can be shared with other devices many devices connected to the same port e g printer scanner mouse etc hence the communication protocol must be compliant with the USB standard 6 6 Frame Structure Storage Mode Figure 6 6a shows the frame structure for the storage mode each field is 1 byte in size expect for the data field which is variable and its size is specified in the count field Since each frame could contain up to 255 data bits large block of data it is much more likely that an error will error when compared to the short real time frames Hence the need for error detection at present a 16 bit CRC is included in the frame which will detect almost every possible error including burst errors EEE516J4 Honours Project Page 34 Chapter 6 Communication Protocol Development Friday 21 June 2002 Final Report Colin K McCord SOF Start of But the generation of the CRC is processor hungry at first it Fr
237. the scope data file void CScopeDoc Save 07 04 2002 by CKM CView pView GetActiveView if pView NULL return CChildFrame pChild CChildFrame pView gt GetParentFrame CScopeView SView CScopeView pChild gt m_wndSplitter GetPane 0 0 CScopeApp pApp CScopeApp AfxGetApp FILE infile int i 0 if infile fopen m_Filename wr NULL AfxMessageBox Unable to create file return rewind infile Save Channel 1 2 3 amp 4 EEE516J4 Honours Project Page 66 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord for i 0 i lt 10000 it t fprintf infile d n pApp gt m_nCH1Volt i for i 0 1 lt 10000 it fprintf infile d n pApp gt m_nCH2Volt i for i 0 i lt 10000 i fprintf infile d n pApp gt m_nCH3Volt i for i 0 i lt 10000 i fprintf infile d n pApp gt m_nCH4Volt i Save Variables printf infile Sd n SView gt x printf infile Sd n SView gt y printf infile sd n SView gt m_nCH1POS print printf print printf infile d n SView gt m_nCH2POS infile d n SView gt m_nCH3POS infile d n SView gt m_nCH4POS infile sd n SView gt m_nCH1 Offset r i printf infile Sd n SView gt m_nCH2 Offset print print print infile sd n SView gt m_nCH3 Offset r infile sd n SView gt m_nCH4 Offset r infile d n
238. ting Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing EEE516J4 Honours Project Page 114 Chapter 11 Test Results Friday 21 June 2002 Final Report Colin K McCord Clearly the test was a success and it has been proven that the transmit mode of the RS232 communications is working Note Baud rate 9600bps OSC 4 MHz RS232 cable length unshielded 1 5m 11 1 2 Test 2 Fully Test RS232 Communications Program mark2 c Version 1 0 was compiled and loaded into PIC using Microchip MPLAB This program is extremely simple ba
239. to Real time frame structure CH1 adcHI char adcValue gt gt 5 amp Oxlf 01 010 da9 d81d7 d6 d5 adcLO char adcValue amp Oxl1f 0x80 1 0 0 d4 d3 d2 d1 d0 putc adcHI Transmit Byte 1 d9 d5 putc adcLO Transmit Byte 2 d4 d0 delay ms 10 Preset delay repeat every 10ms EEE516J4 Honours Project Page 98 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord 10 4 Mark 4 c Test RS232 Baud Rate Set by Dip Switches Same as mark 1 c with the addition of function SetBaudRate this function sets the UART baud rate based on the positions of the DIP switches that are connected to port E This program is used to test the reading of the DIP switches and RS232 communications at different baud rates Note that the PIC must be running at 20MHz because the percentage error for 115Kbps is too large at slower clock speeds Mark 4 c source code ee poni paa poa pen paag pen jaa a pa a poa pa poa pen poa panh poai pot poa pon poai pan poai pon paat pan pani pan ponk pam paa pank poa ee ee paa paa pa FILE mark 4 c PROJECT Low Cost PC Based Oscilloscope DESC Test RS232 baud rate set by dip switches SS SS SS SS SS SS SS SS SS DATE 01 03 2002 BY Colin K McCord VERSION 1 0 include lt 16F877 h gt device PIC16F877 16 ADC 10 fuses HS NOWDT NOPROTECT NOLVP byte PORTE 0x09 PortE lives in File 9
240. to operate correctly once the noise was removed but when the noise was present no CRC check in real time mode all sorts of strange waveforms were being drawn on the display Clearly there is problem when the user has selected an out of range time base i e aliasing can occur even if sampling at more than twice the waveform frequency recall that the scope program increases the time base by skipping readings and decreases the time base by duplicating readings Obviously it is possible for aliasing to occur skipping reading if the selected time base requires for less than 2 samples per cycle to be displayed hence it is important that the user makes sure that the selected time base is optimal for the waveform being monitored at the selected sample rate Evidently the scope program is far too processor hungry and future modification is required to make it more efficient for example the trigger point for all enabled channels are always calculated even if all channels are triggering of one channel clearly this is inefficient and bad programming practice and needs to be improved It has been proven that the scope program requires a reasonably fast PC to run smoothly the minimum spec being 200MHz for a reasonable refresh rate and probably SOOMHz for quad channel operation at a high refresh rate 50ms and resolution Clearly modern PCs will have no problems running the scope program as the minimum spec computer on the market today are all above 1GHz
241. to the modern user It can control very old primitive modems and has many control signals to do this in hardware but often it is used without these old control and status lines Its major feature is that it does not require the transmission of a clock the reception of a start bit is enough to cause the receiver to time all its actions from this one edge This is called asynchronous transmission RS232 allows a 5 difference in transmitted timings and receiver chip timings This is important if using a EEE516J4 Honours Project Page 13 Chapter 3 Fundamentals Friday 21 June 2002 Final Report Colin K McCord PIC as the datasheet specifies the error of the baud rate generator at certain baud rates the higher the baud rate the higher the error as long as this error is less than 5 the RS232 standard is capable of coping Electronic data communications between elements will generally fall into two broad categories single ended and differential RS232 single ended was introduced in 1962 and despite rumours for its early demise has remained widely used Logic Logic Levels Levels a ike i ee ie 15m 20kb Figure 3 6a Illustration of RS232 1 driver and 1 receiver Both RS232 and RS423 are unbalanced or single ended standards where the receiver measures the potential between signal line and ground reference Even though the transmitter and receiver grounds are usually connected though the transmiss
242. ty if i_get amp buffer SIZE i _get buffer return 0 Changing the baud rate after Initialisation void baud_rate void Re ete ese A e as Poe ees eee oe ee Se eee areas e se Function baud_rate void Description User selects baud rate via keyboard Input keyboard Output baud rate changed Return none Bote Sse cobs cele l sachet ace eee Beco See Sa See Sec E EE E int rate Baud Rate 0x01 115200 bps 0x02 57600 bps 0x03 38400 bps 0x06 19200 bps 0x08 14400 bps Ox0c 9600 bps clrscr rate 115200 baud if baud 1 printf Baud Rate Current 6u bps rate EEE516J4 Honours Project Page 94 Chapter 9 Test Program Friday 21 June 2002 Final Report else printf Baud Rate Current 115200 bps ORINtLCWnaHs ineen sas sors Sees a printf n 115200 bps bit 1 printf n 57600 bps hit 2 printf n 38400 bps hit 3 printf n 19200 bps hit 4 printf n 14400 bps hit 5 printf n 9600 bps hit 6 printf n 4800 bps hit 7 printf n 2400 bps hit 8 printf n 1200 bps hit 9 printf n No Change hat O s switch getch case l baud 0x01 break case 2 baud 0x02 break case 3 baud 0x03 break case 4 baud 0x06 break case 5 baud 0x08 break case 6 baud 0x0c break case 7 baud 0x18 break
243. ud rate of 115kbps que M6264P 15 8kBbyte RAM Chip MAX232 PIC 277 20 MHZ Clock Line Buffer Micrc ar 100 gt 100V 100 gt 100Vv 100 gt 100V 100 gt 100V CH1 CH2 CH3 CH4 Figure 5 1a Simplified Block diagram EEE516J4 Honours Project Page 22 Chapter 5 Hardware Development Friday 21 June 2002 Final Report Colin K McCord The block diagram figure 5 1a clearly illustrates that the analogue circuitry required for each channel is identical Note four 741 op amps are available in a single IC chip that s two op amp ICs required in total 2 741s for each analogue circuit block Not shown on this diagram which is one option is the input of additional control lines from the PIC to each Analogue Circuitry block These control lines will be used to select different input voltage ranges e g 1V to 1V 10V to 10V 100V to 100V Analogue switches could be used to switch in different resistor values to the op amps hence changing the gain of the op amp MAX4066 or MM74HC4066 A better solution is the use of digital potentiometers resistance controlled by microcontroller to change the gain of the op amp At first it appears that there is not enough free pins on the PIC to control the analogue input range this is true but it is possible use the data and address bus as long as the RAM chip is disabled But this mains that additional IC chips are required latches e g 74373 is an 8
244. ue to Digital converter Peripherals include two 8 bit timers one 16 bit timer a Watchdog timer Brown Out Reset BOR In Circuit Serial Programming RS 485 type UART for multi drop data acquisition applications and 12C or SPI communications capability for peripheral expansion Precision timing interfaces are accommodated through two CCP modules and two PWM modules W3 4 1 Overview of the File Registers The data memory is partitioned into multiple banks which contain the general purpose registers and the special function registers Bits RP1 and RPO are the bank select bits these bits are found in the STATUS register b6 amp b5 18Eh RESERVED 18Fh RESERVED 190h General General Purpose Purpose Register Register 96 Bytes 96 Bytes General General Purpose Purpose Register Register 80 Bytes 80 Bytes 6Fh EFh 16Fh 1EFh h General Purpose on Accesses Global Tuh Accesses Global TO Accesses Global i Global Register Register A Register j Register 7Fh 16 Bytes FFh 70h 7Fh 17Fh 70h 7Fh 1FEFh 70h 7Fh Bank 0 Bank 1 Bank 2 Bank 3 Figure 4 1a PIC16F877 register file map Each bank extends up to 7Fh 128 bytes The lower locations of each bank are reserved for the special function registers shown in yellow Above the special function registers are general purpose registers shown in blue implemented as static RAM All implemented banks contain specia
245. uencies above half the sample rate must be filtered anti aliasing the actual maximum analogue bandwidth of the system is 21 815Hz note flow OHZ Undoubtedly an external ADC with direct memory access makes it possible to monitor very high frequencies e g AD9070 10bit JOOMSPS ADC but these chips are expensive hence the low cost of the design is lost It is clear the following limits the maximum storage sampling rate the maximum sampling speed of the ADC time taken to send to RAM and the amount of memory Overall progress has been good although it has taken much longer than expected to complete certain aspects of the project e g triggering of waveforms The project was a success real time waveforms have been successfully displayed on a PC in real time and it has been demonstrated how storage mode operation could be added to project to increase maximum sampling rate even if the transport medium is slower than the sample rate EEE516J4 Honours Project Page 151 Chapter 12 Conclusions Friday 21 June 2002 Final Report Colin K McCord 13 0 RECOMMENDATIONS FOR FURTHER WORK Clearly there is a lot of additional development work that can be done to improve the design of this low cost PC based quad channel real time storage oscilloscope This chapter will briefly highlight areas of the design that merits improvement and additional features to make the scope more powerful reliable flexible and commercially marketability 13
246. urs that can be used by the program e g the scope display is not 32 bit colour as used by the system 2 The high end Creative Labs 3D Blaster GeForce 3 Titanium 200 64MB 400MHz DDR RAM 3D accelerator video card in the desktop running dual boot Windows 98 Windows 2000 is able to do some of the work Although the scope program is not using DirectX or OpenGL hence this is unlikely Scope exe Properties tix 21x Generel Shoncut Compatibility Themes Deskiop Screen Sever Appeecance Sefings Hycu have problems wih his program end A worked comecty cn an Drag the montor icons to match the physical amrangemect at your monitors auha version of Windows select the comp bity mode that matches hot earker version Compaibiiy mode I Ran this program in compatibility mode tor Display setings Pan in 256 colors T Pian in 840x 430 screen resohston Serer meealetion Disable vieus thames less m ee More 1024 by 768 pols A cal Laan mere ebot pogram campatbelty Hentty Troubleshoot Aonad ok cnca C o ce Figure 7 13a Screen dump of Compatibility option in Win XP Figure 7 13b Screen dump of display properties in Win XP EEE516J4 Honours Project Page 83 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord Figure 7 13a shows the compatibility options available for the scope program running in Windows XP notice the Run in 256 colours option If this option is clicked th
247. ve input has been applied and the output is 0 to 5V Figure 5 3 1d clearly shows a triangle wave input of 5v to 5v and an output of to 1 3V to 3 70V Notice the input and output waveforms are the same phase and polarity Oscilloscope S Oscilloscope ac 6 ail Figure 5 3 1c Screen dump of oscilloscope CH A Input CH B Figure 5 3 1d Screen dump of oscilloscope CH A Input CH B Output Output From figure 5 3 1e using 50 to 50V input it is clear that a 50 to 50V sinewave input has been applied and the output is 0 to 5V Figure 5 3 1f clearly shows a squarewave input of 25v to 25v and an output of to 1 24V to 3 76V Notice the input and output waveforms are the same phase and polarity Oscilloscope 50 09000 vV 2 5197 V Ther Charest s tye a tevel y wn aa E a p o eco i Figure 5 3 1f Screen dump of oscilloscope CH A Input CH B Output Output 5 4 Analogue Circuit Diagram Mark 2 Figure 5 4a shows the modified circuit diagram for ensuring that the input voltage falls between zero and five volts without the use of variable resistors The first op amp is designed to change the input voltage so that it does not go over zero volts for example changes 2 5 to 2 5V to 5 to OV The second op amp is configured in negative amplifier mode with a gain of unity changing 5 to OV to O to 5V The third part with the two di
248. ved difficult to debug The high level programming language C was chosen and not the low level assembly code normally associated with PIC programming clearly there are many advantages of this including ease of programming ease of modification reusability of code and use of standard functions Clearly PIC embedded software mark9 c was successfully designed implemented and tested to read the ADC at a certain sample rate interrupt time base and transfer the data to the PC using the real time communication protocol It is clear that a Windows dialog based simulator program was successfully developed this program is easy to use the user selects the type of waveform amplitude and frequency for each channel The simulated waveforms are then transmitted to the scope program using the real time frame structure storage not implemented Clearly accurate timing is difficult to achieve and no attempt has been made to achieve this as it would have wasted a large amount of time plus the timing of the simulator would have been completely different to the timing of the PIC hence the code would not be reusable actuate timing on PIC only Clearly even though the simulator does not have actuate timing it still is a powerful tool it will allow the communication protocol graphical display and triggering method of the scope program to be easily tested EEE516J4 Honours Project Page 150 Chapter 12 Conclusions Friday 21 June 2002 Final Report Colin K McC
249. wWindow wp showCmd Function CMainFrame InitialShowWindow is called from CScopeApp InitInstance BOOL CScopeApp InitInstance The main window has been initialized so show and update it pMainFrame gt UpdateWindow return TRUE Before the window is destroyed its position is saved in the windows registry void CMainFrame OnClose before mainframe it is destroyed save the position of the window WINDOWPLACEMENT wp wp length sizeof wp if GetWindowPlacement amp wp wp flags 0 if IsZoomed wp flags WPF _RESTORETOMAXIMIZED and write it to the windows registry WriteWindowPlacement amp wp CMDIFrameWnd OnClose Note the same technique can be used for saving and restoring the position of the scope display window but at present multiple scope display windows can be used and it s not ideal if they all open at exactly the same place amp Registry Editor Er 5 xj Regsty Edt View Eavorites Help MeCords Software Name Type Data Ga Scope at Defauit REG_SZ value not set Config fab AdSampingPos REG_SZ 0 1 1 1 4 24 152 309 768 599 Sy Pagesetup a Scope REG_SZ 0 1 1 1 1 1 23 23 836 466 Gy Recent Fie Listy B WindowPos REG_SZ 2 3 1 1 1 1 82 99 1024 687 JES 2 Sim M My Computer HKEY_CURRENT_USER Software mcCords Software Scope Settings y Figure 7 4a Screen dump of window registry showing
250. ween the bytes The second has a random delay between bytes and the third has a user configurable delay between the bytes This function is used to test the reliability of both the scope exe program and the PIC embedded software For example simulated noise is sent to the scope exe program for a couple of hours during this time the program must not crash and when the random noise has been removed the program must continue to operate normally EEE516J4 Honours Project Page 91 Chapter 9 Test Program Final Report Colin K McCord Friday 21 June 2002 6 Loop Back Test Test Started LTO2 523 Testing Test 1 FAIL Test 2 FAIL Test 3 FAIL 100 FAIL Test Finished 11 02 25 Three tests are carried out Test 1 Data 0 gt 255 gt 0 is transmitted with a 16 bit CRC and compared with the received block 514 bytes Test 2 Random data from 0 to 255 is transmitted with a 16 bit CRC and compared with the received block 514 bytes Test 3 Random data 0x00 or OxFF is transmitted with a 16 bit CRC and compared with the received block 514 bytes This function can test the PC serial port by connecting pin2 and pin3 together RX amp TX or PIC software can be written to fully test communications by transmitting every character it receives If this test is successfully it is certain that communications between the PC and the PIC is extremely good as this test requires
251. where the window position is stored EEE516J4 Honours Project Page 59 Chapter 7 The Scope Program Friday 21 June 2002 Final Report Colin K McCord 7 5 Setting Up RS232 Communications xi The configuration settings are easily configurable using Communication the configuration dialog from menu Tools Configuration This dialog is user friendly and easy to Basic use notice that a tab control was used and at present com comi BeudRate 5760 there is only one tab communication additional tabs will be added at a later date e g calibration Note Advanced when the user hits OK or Apply the configuration settings are saved to the windows registry Apply button is only enabled if changes have been made and the Restore Defaults button is only enabled when the current configuration differs from the defaults see figure 7 5a Byte Size 8 z Parity No Parity w Stop Bits 1 x Timet ms 100 a Restore Defaults ok _ Conceit LCa Figure 7 5a Screen dump of the configuration dialog box When user hits OK or Apply this function is called void CConfigPagel Save_ Changes UpdateData TRUE CScopeApp pApp CScopeApp AfxGetApp pApp gt WriteProfileInt Config COM m Combo _COM GetCurSel pApp gt WriteProfileInt Config Baud m Combo Baud GetCurSel pApp gt WriteProfileInt Config Byte Size m Combo Byte Size GetCurSel pApp gt Wri
252. with the top range above 2GHz and computers up to 3 years 300 MHz or above old should conformable run the scope program Obviously the development of the scope program is not complete and there remains many additional features yet to be added for example the addition of 4 user configurable virtual channels e g VC1 CH1 CH2 or CH1 CH2 or CH1 CH2 etc auto frequency calculation auto time base auto voltage scale print directly from scope program and storage mode operation Overall good progress was made the program can display up to four real time waveforms either scrolling across the screen or triggering waveforms can be saved and reopen graphical display can be exported to a bitmap or the Windows clipboard voltage scales are adjustable zero point and waveform offset easy adjustable using unique user interface small triangles and channels are easy disable enabled The philosophy used during the development of the PIC embedded software was to keep it simple straightforward comprehensible and to a minimum Many small programs were designed for testing the hardware and ideas clearly the end result is that the PIC code was gradually built up step by step instead of writing the entire program at once Evidently this ensures that operational results are obtained as testing producers were carried at each stage while if the program had been written all at once there would have been little chance of it working and could have pro
253. ww codeproject com The Code Project a ry community of Windows developers specialising in W4 THE CODE PROJECT C MFC C and NET who have come y F together to share source code articles and mmt tutorials W5 http www lvr com usb htm USB Central Information tools and links to material about the Universal Serial Bus W6 _http Awww lvr com serport htm Serial Port Central A collection of files and links to material relating to serial links and networks especially in monitoring and control applications W7 _ http Awww lvr com parport htm Parallel Port Central A collection of files and links to material about the PC s parallel port including ECP EPP bidirectional and IEEE 1284 modes we http msdn microsoft com Microsoft Developer Network W9 _ http Awww engj ulst ac uk sidk PIC index html PIC Resource Site An assorted set of data sheets instruction sets and web sites by Dr S Katzen PROGRAMMERS Bee p www programmersheaven com Over W10 18449 resources to explore HOME OF THE DEVELOPER W11 http www codeguru com C source code etc W12 http Awww intelinfo com newly researched free training C html Free C Programming Training and Tutorials EEE516J4 Honours Project Page 157 Chapter 14 Bibliography References Friday 21 June 2002 Final Report Colin K McCord W13 www picotech com PC Based Test amp Measurement Data Sheets D1 PIC16F87X Data Sheet 2
254. xFF TRISE 11111111 RBO to RB7 TTL Inputs Set Address Put RAM chip in Read Mode PORTD char address Set A7 A0 PORTC PORTC amp 0xE0 address gt gt 8 Set A12 A8 delay cycles 1 200nS delay same as NOP 1 20 000 000 4 1 200nS return PORTB make sure data is valid before reading EEE516J4 Honours Project Page 111 Chapter 10 PIC Software Development Friday 21 June 2002 Final Report Colin K McCord 10 11 Mark 11 c Main Program Setup RS232 and 1 0 ADC timeout 1 Setup Timer 2 a Interrupt every A 20us eceived char no TimeBaseMUX l 1 4 may ti t 41 1000Hz meou yes Call Function Call Function fail ControlProtocol StorageMode A pass v v Implement controll Pa Tai message ie Set mepu TimeBaseMUX no AA Call Function Real timeMode bSample FALSE Sample CH1 and Kee transmit reading using real time Sample CH2 and transmit reading using real time Sample CH3 and transmit reading Sample CH4 and transmit reading using real time using real time frame structure frame structure frame structure frame structure vy vy b d y Delay 20us Delay 20us Delay 20us Delay 20us
255. y Figure 5 4 1f clearly demonstrates the operation of the diodes an input of 5 to 5V voltages is applied to the 2 5 to 2 5V input The peaks of the output waveform have been clipped giving an ADC input voltage range of 0 7 to 5 7V Oscilloscope O a a EE w Ti 464 9454 ms T2 474 8204 ms T2 T1 9 8750 ms VAI 4 9379 y VAR 4 9575 y VA2 VAI 9 8954 y vai 65 7196 y V82 718 5178 mV VB2 B1 6 4381 y Edge Ea i f2viow Bl zvov E Reduces Level Y position 0 00 f Yposition o co _ amp Reverse E Alel Er ac 0 ig Aci olma Save Figure 5 4 1f Screen dump of oscilloscope CH A Input CH B Output 5 5 System Powering Circuit Figure 5 5a shows the circuit diagram clearly a 5V regulator is used to generate a 5 volt DC output to power the circuit The 0 1uF capacitors absorb line noise while the 100uF capacitors are used for storage in the event of a minor drop in power milliseconds the circuit operation will not be affected MC7805CT 8 to 20 VDC 5 VDC Ta Tv I C2 y 0 1uF 50V Figure 5 5a System powering circuit This means that the circuit has now got a wide operating voltage range as 8 to 20 volts DC will power the circuit Note there are higher spec 7805 chips available that can operate up to 30 volts DC if there is a need for a higher voltage range EEE516J4 Honours Project Page 28 Chapter 5 Hardware Development Fri
256. ycle and probably at lot more at high sampling rates Also because it is real time the screen is continuously refreshed hence the error will probably not stay on the screen for very long a couple of milliseconds until it is replaced by new readings 6 5 Sample Rate Real Time Mode The RS232 communications is the bottleneck as the maximum sampling frequency of PIC16F877 microcontroller ADC is higher than can be transmitted over RS232 Therefore it makes since to calculate the maximum sample rate based on how much data can be transmitted through RS232 at different baud rates Two bytes are sent per frame note each byte contains 8 bits plus a start and stop bit Hence 20 bits are sent per reading Baud Rate Sample Rate No of Channels Number of Max Sample Rate Max Sample rate Max Sample Rate at Channels at 115 Kbps at 56 6 Kbps 33 6 Kbps 1 5 75 KHz 2 83 KHz 1 68 KHz 2 2 87 KHz 1 41 KHz 840 Hz 3 1 91 KHz 0 94 KHz 560 Hz 4 1 43 KHz 0 70 KHz 420 Hz Figure 6 5a Table showing the theoretical real time sample rates chop 10 bit ADC Note that the values shown in Figure 6 5a assume that there is no time delay between readings Clearly this is not the case in practice and the actual maximum sample rates will be lower than specified e g PIC takes 19 72uS see datasheet for PIC16F877 to acquire each sample plus there will be processing delays However these values should be reasonably accurate because th

Download Pdf Manuals

image

Related Search

Related Contents

取扱説明書 2・3本針フラットベッド型 偏平縫いミシン INSTRUCTIONS 2  ECOLOGY  FA-T-P01 カタログ  Mynute S CSI - Caldaiafacile.it  

Copyright © All rights reserved.
Failed to retrieve file