Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

pic oscilloscope with pic18F4550

Status
Not open for further replies.

aduri

New Member
program oscope_4550_20mhz


Hello everyone,
my goal is to get an oscilloscope in XY mode that works to make a curvetracer.
The display on the oscilloscope with the analog part is finished.
For the digital oscilloscope I used a PIC18F4550 with 20MHz oscill. and Glcd 128x64 Wintek the mod. W12864A.
It works but has a bandwidth ridiculous.
I started from a code found on the forum for the 16F877A and 4MHz oscill.. but as you can imagine was even slower.
I tried to send a sinusoidal signal but after a few Hz, also changing (via sw) the 'Sweep rate factor' no improvement.
I was thinking of bypassing the ADC, making it a library dedicated to increase the sampling rate but I do not know if it will do.
I think we should also work on synchronism and variable (word instead of float).
Any advice?
I put some working code I hope it can be a stimulus for a common developmen..

Thanks for your help

Antonio


Code:
'Microprocessor: 18F4550
'Xtal 20MHz no PLL
'pbaden=off
'This program is designed to make a simple oscilloscope.
'with GLCD W12864A
'Mikrobasic 7.0.2
'--------------------------------------------------------------------
symbol DDRA=TRISA
symbol DDRB=TRISB
symbol DDRC=TRISC
symbol DDRD=TRISD
symbol ControlPort=PortB
symbol DataPort=PortD
symbol Channel=0

dim
X as integer
Y, K, Sr, Offset as float
Xmin, Xmax, Ymin, Ymax as float
XX, YY as short
GLCD_VSize as byte
GLCD_HSize as byte

const   'for GLCD Wintek 128x64 W12864A
cs1=2
cs2=3
rs=4
rw=5
rst=7
en=6

sub procedure Initialize
ADCON1=0x0E 'A0 as analog input
DDRA=0x01 'ADC on A0
DDRB=0x00
DDRC=0x00
DDRD=0x00
glcd_Init(ControlPort,cs1,cs2,rs,rw,rst,en,DataPort)
Glcd_Fill(0) 'Clear display
end sub

main:
Initialize
'User defined
'----------------------
GLCD_VSize=63
GLCD_HSize=127
Sr=1 'Sweep rate factor
Xmin=0.0
Ymin=0.0
K=10.0 'ADC bits
'----------------------

Xmax=float(GLCD_HSize)*Sr
Offset=float (GLCD_VSize)/2.0 'Bottom of GLCD = 0V
Ymax=pow (2.0, K)-1.0 'Top of GLCD = 5V

Display:
for X=integer(Xmin) to integer(Xmax) step 1

Y=float(Adc_Read(Channel))+ Offset

YY=short((float (GLCD_VSize)/(Ymax-Ymin))*(Ymin-Y))
XX=short((float (GLCD_HSize)/(Xmax-Xmin))*(float(X)-Xmin))
Glcd_Dot(XX,YY,1)
next X
Glcd_Fill(0)
Goto Display

end.
 
This chip can use a system clock of 48MHz and you are using 20MHz. You need to use the PLL to do so but you get 2.4X the speed.

Using floating point numbers on an 8 bit micro when you are speed sensitive is a big no no. Scale the numbers.

Unless you plan to add a faster ADC chip you will have to stick with the onboard ADC.
aaa

Code:
Y=float(Adc_Read(Channel))+ Offset
This line is a problem. The use of the ADC unit requires a delay between the when you start the conversion and when you can read it. I expect Adc_Read() uses a delay. More on that later.

Code:
YY=short((float (GLCD_VSize)/(Ymax-Ymin))*(Ymin-Y)) XX=short((float (GLCD_HSize)/(Xmax-Xmin))*(float(X)-Xmin)) Glcd_Dot(XX,YY,1)

Remember no floats. Do you need to display the code as it is generated? How about storing the results in an array and dumping it after data acquisition is over.

You are making calculations that involve only constant. For example (float (GLCD_VSize)/(Ymax-Ymin)), or the integer version of it, should be calculated once outside the loop. The compiler could already be doing this optimization but without looking at the generated we do not know.

You might look at starting the ADC read and then doing something else that has to be done inside the loop instead of delaying. Maybe calculating or storing the previous result to the array or LCD. If you know how long the delay needs to be you can taylor this code using the simulator and stopwatch.
 
Last edited:
Thank you for your interest.
For now I just created an array and written in Glcd later but I believe we need a trigger to do otherwise can not see above 15 Hz.
Can you help me?

this is the part of code modified:

Display:
'load on ram
for X=integer(Xmin) to integer(Xmax) step 1

Y=float(Adc_Read(Channel))+ Offset

YY=short((float (GLCD_VSize)/(Ymax-Ymin))*(Ymin-Y))
YP[x]=YY
XX=short((float (GLCD_HSize)/(Xmax-Xmin))*(float(X)-Xmin))
XP[x]=XX

next X
'write on glcd
for X=integer(Xmin) to integer(Xmax) step 1

Glcd_Dot(XP[x],YP[x],1)

next X

bye
Antonio
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top