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.

Moving from mikroBasic to OshonSoft Basic

A/D coversion and the entire code simulation is ok, except when values for AN0 are set small.
Then the LCD does not show "Input is too low".
P.S.: The logarythmic signal detector (ahaed of the MCU circuit) output is ca. 0.45 VDC (broadband noise signal) without any input signal applied. In this case I want to display the above message.

again:
Lcdcmdout LcdClear
ADC_Read 0, ADCRead 'Result of A/D conversion from AN0
ADCResult = ADCRead*5/1024
Lcd_Out(1,1, "ADC OUT = " + #ADCResult +" V")
If ADCResult<0.5 Then
Lcd_Out(2,1, "Input is too low")

Else
dBmResult = (ADCResult-ZEROXING)*SLOPE
Lcd_Out(2,1, "PWR = " + #dBmResult + " dBm")
Endif
WaitMs 500
Goto again 'Make a new A/D conversion

Goto main
End
 
Well, I have tested the program in more detail and it seems that in these new versions of the compiler ADC_Read configures the pin as analog and as input. I thought that the problem was that the pin was not output as analog in the simulator. Anyway, if you wanted to do this, it does work.

I didn't see this configure the AN0 pin: Sub GlobInit.


dBm.jpg
 

Attachments

  • V_dBm_Meter (1).bas
    3.2 KB · Views: 27
Last edited:
Gentlemen,
My project works (simulation and hardware), mission accomplished.
Thank you all who contributed with advice, and help.
I have learnt a lot and will continue exploring OshonBasic.
Best regards,
Robert
 
I want to eliminate the 0.01 dBm variation on the LCD display that happens for a constant input RF signal level to the ADC of the circuit. The ADC conversion slope is 19.61 dBm/Volt.
Therefore 0.1 dBm level change is caused by 0.1 dBm/(19.61 dBm/V) = 5.1 mV change in the analog input voltage.
My goal is to keep the display value unchaged for 2*5.1 mV = 10.2 mV, i.e. <= 2 bit change in ADC output.
Please find attached the source code. Would the error message mean that the syntax "abs" is not known in OshonBasic? Any cure for that?
 

Attachments

  • V_dBm_Meter v3.bas
    3.3 KB · Views: 4
The only way to "eleminate" this tiny variation is to over sample.

If you are running at 5V a bit change is 4.88Mv. Then you need to decide how to get the best information to screen.. You set your decimal places to two.

I do not use floating point numbers on small devices as I know how they work and its not how you think.

lets take your calculation 2.5V should be 512 bits.. 512 * 5 = 2560 / 1024 = 2.5v BUT!!!!! ADCRead is an interger only the result is floating so it may need casting.. Vlad does allow casting

So
adcread = adcin(0) * 5 'integer multiply
adcresult = adcread ' basic cast to float
adcresult = adcresult / 1024 ' now it works..

But!! you want MORE precision

do this
for idx = 0 to 10
adcresult = adcresult + adcin(0)
' you can place a tiny delay here to slug readings
next idx
adcresult * 5 / 10240 ' gives 2.5V

You can play around ie read adc 5 times then times by 100 then / 10240

The point is the output will be more stable.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top