Still very new to this, so forgive me if it's a daft question or if I've posted in the wrong place.
I tried changing the device in the demo "Fixed Voltage Reference @ 16f1829" to 18F26K22. I added a blinky after the existing code in the main loop. I see no serial output on either TX1 or TX2 and the blinky doesn't blink. Is there some limitation to LCD2SerialRedirect on 18F26K22.
My hardware seems to be ok, the hello world demo generated serial data and a blinky ran as expected at the correct speed (both on 18F26K22).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#Chip 18F26K22, 64
#define USART_BAUD_RATE 19200
#define USART_TX_BLOCKING
Dir PORTc.6 Out
Dir PORTc.7 In
wait 100 ms
HserPrint "Hello World"
HserPrintCRLF
Do you have a TTL convertor? or, not?
When you have something on the terminal then text the LCD emulator.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As I said I have a working serial chain (device - TTL to RS232 - COM port)
I amended the minimal example to
#Chip 18F26K22, 64
#include <LCD2SerialRedirect.h>
; Required to LCD to Serial redirection
#define LCD_IO 0
CLS
#define USART_BAUD_RATE 19200
#define USART_TX_BLOCKING
Dir PORTc.6 Out
Dir PORTc.7 In
do
wait 100 ms
'HserPrint "Hello World"
'HserPrintCRLF
Locate 4,0 : Print "Fixed Voltage Reference"
loop
I get the expected output.
So I quess the problem is in the FVR code?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Interesting one - this issue. By working thru the LCD emulator issue in a systematic way then... the only place where the issue could be... in the FVR methods.
:-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Given the results I pretty sure you're correct but I think my problem is with the raw numbers not my math which in my non-GCB example produces results that tally with multimeter reading off Vdd.
Last edit: George Towler 2018-11-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FWIW the following produces the correct Vdd albeit not using GCB 18F26K22
~~~
GetVdd:
VREFCON0 = %10010000 ' FVR Enable, 1.024V
ADCON0 = %01111101 ' Select FVR, ADC on
ADCON1 = %00000000 ' pos = VDD NEG = VSS
ADCON2 = %10111110 ' right justified, acquisition time = 20TAD, Clock = FOSC/64
While FVRST = 0 : Wend ' Wait For 1.024v reference To stabilize
DelayUS 15 ' Wait for sample/hold capacitors to charge
GO_DONE = 1 ' Start conversion
While GO_DONE = 1 : Wend ' Poll the GO_DONE flag for completion of conversion
ADCON0 = %01111100 ' Select 1.024, ADC off
FVREN = 0 ' FVR Disable
EchoResult = Ad_Result
VDD = 10486/Ad_Result ' convert input reading to VDD voltage *VDD must be a Word
' 1.024 * 1024 = 1048.6 - 10486 To get 1/10th's
Return
~~~
Last edit: George Towler 2018-11-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you refering to A20. I think perhaps you are misinterpreting Microchips confusing numbers. The only restrictions I see are that FVR maynot exceed Vdd, so you could not use 4.096 if Vdd was 3.3V
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Deep in the bowels of the the 18F266K22 Datasheet under Electrical Specifications ( Page 451 - Table 27-21 - parameter A20)
There is no misinterpretation.
A20 is the delta minimum between VREF+ and VREF-. If VREF- is assumed to to be ground or 0V then the "minimum" VRFEF+ is 2.0V where specified accuracy is guaranteed. This precludes FVR 1.024.
So it is not that it cannot be used, it is that it should not be used if accuracy is critical.
That being said, I have used FVR 1.024 sucessfully and with good accuracy on several projects but care must be taken to assure that accuracy.
1) The ADC device ground must be tied as close ae possible to the PIC ground pin. Not somewhere on the other side of the board where it snakes around all over the board on a thin trace before it gets to a point common to the PIC ground pin. Use "star" grounding if possible. Bad or improper grounding can cost you 10 lsb or more.
2) Likewise the signal line to the ADC input should connect as close as possible to the PIC ADC pin and not snake around all over the board.
3) The ADC impedance should not exceed 10K Ohms.
4) A clean power source. No dodgy power supplies
5) A proper bypass capacitor across the PIC VDD and ground pins ( 100nF)
6) If considerable loads are drawn from the same supply as the PIC is using then fit a 10uF to 47uF bulk capacitor on the board.
Good Luck !
Last edit: William Roth 2018-11-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the input, you obviously have a better handle on Microchipess than I. I also have successfully used the 1.024V ref to measure Vdd. I wonder what happens on some of the earlier devices that only had 1.024V?
Anyway I still can't get the Vdd measurement to work. I tried using ReadAd (which I assume returns a 8 bit result) but that just returns all ones.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anyway I still can't get the Vdd measurement to work. I tried using ReadAd (which I assume returns a 8 bit result) but that just returns all ones.
By all ones, I assume you mean a decimal value of 255. This seems to indicate that the input voltage to the ADC pin is > 1.024v.
To measure VDD using FVR 1024 you will need a voltage divider from VDD to Ground.
For good resolution and easy maths the use a 10K fixed resistor over a 2K Trimer. Connect the center of this divider to the ADC input. Then use "ADC10" in your code .
Adjust the trimmer so that when VDD = 5V the ADC value is 500. This will give you a resolution of 10 mv and good accuracy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@William, you're knowledge of electronics is infinitely greater than mine and I would not disagree with anything you've posted (as much as I understand it). But the fact remains that using non-GCB code I have successfully measured Vdd using the 1.024v FVR to better than 0.1V (according to my cheap ebay multimeter) without any additional hardware. I will take your advice and from now on will use 2.048V FVR (where available) to measure VDD. Soon as I get a chance I'll try 2.048v and the hardware you suggest.
@Anobium. Same code as 5 days ago. I've tried ReadAd with AdVal declared as a byte. I'm obviously missing something. ADC timing? I don't understand how variables used in libraries are declared, for instance Adval, should I declare it or does the lib do that?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@George. Post your code, as an attachment, and then we can help.
We can explain the internals of the libraries when we know what methods you are using. You may not need to know the library variables as the majority are not intended to be used in a user program.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think I might know whats wrong, in the 16F1829 FVR demo code, the ReadAd command is being passed the parameter AN0, I'm pretty sure thats not the correct value. Sorry if my terminology is incorrect.
The code I'm using is the 11th. post in this thread. In my non-GCB code above I have
ADCON0 = %01111101, I'm not sure how this equates to the parameter passed to ReadAd.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Still very new to this, so forgive me if it's a daft question or if I've posted in the wrong place.
I tried changing the device in the demo "Fixed Voltage Reference @ 16f1829" to 18F26K22. I added a blinky after the existing code in the main loop. I see no serial output on either TX1 or TX2 and the blinky doesn't blink. Is there some limitation to LCD2SerialRedirect on 18F26K22.
My hardware seems to be ok, the hello world demo generated serial data and a blinky ran as expected at the correct speed (both on 18F26K22).
No limitation.
Post the code as an attachment so we can review.
Device changed and blinky added. Dir's added experimentally.
Last edit: George Towler 2018-11-09
Minimise the code. Does serial work?
Do you have a TTL convertor? or, not?
When you have something on the terminal then text the LCD emulator.
Thanks for responding so quickly.
Yes, the minimal example works
As I said I have a working serial chain (device - TTL to RS232 - COM port)
I amended the minimal example to
I get the expected output.
So I quess the problem is in the FVR code?
So, that emulates the LCD?
If yes,
Then, now out the ADC - ONLY the readad. Does that work?
Last edit: Anobium 2018-11-09
adding "ADVal = ReadAd(AN0)" to the modified minimal code produces the same output ie the string "Fixed Voltage Reference"
Can you clarify please? Does the ADVal when display on the LCD emulator show a value that represents the ADV value of the pot?
@George et al.
Updated ADC library. This will be included in future releases. So, for now download and put in the C:\GCB@Syn\GreatCowBasic\Include\lowlevel directory. This is the updated library: https://sourceforge.net/p/gcbasic/code/816/tree/GCBASIC/trunk/include/lowlevel/a-d.h?format=raw
The library has been updated to handle the 18F FVR. Previous release support 16F only.
Should work like this.
Last edit: Anobium 2018-11-11
Good catch guys, well done, fast turn around.
On Sat, 10 Nov 2018 at 17:35, Anobium evanvennn@users.sourceforge.net
wrote:
Interesting one - this issue. By working thru the LCD emulator issue in a systematic way then... the only place where the issue could be... in the FVR methods.
:-)
Thanks for all your effort, I'll give the new ADC library a spin as soon as I get back,
Added later.
I tried the following but I'm missing something because the actual Vdd values are wrong
383 VREF = Vdd
1023 Vdd * 10 = 41 VREF = 4.096
1023 Vdd * 10 = 20 VREF = 2.048
511 Vdd * 10 = 20 VREF = 1.024
But I see you're about to release a new version. So I'l wait for that and give it another spin.
Wrong direction George. Use the upadated library. Your approach is a tad incorrect. {=)
Given the results I pretty sure you're correct but I think my problem is with the raw numbers not my math which in my non-GCB example produces results that tally with multimeter reading off Vdd.
Last edit: George Towler 2018-11-12
FWIW the following produces the correct Vdd albeit not using GCB 18F26K22
~~~
GetVdd:
VREFCON0 = %10010000 ' FVR Enable, 1.024V
ADCON0 = %01111101 ' Select FVR, ADC on
ADCON1 = %00000000 ' pos = VDD NEG = VSS
ADCON2 = %10111110 ' right justified, acquisition time = 20TAD, Clock = FOSC/64
While FVRST = 0 : Wend ' Wait For 1.024v reference To stabilize
DelayUS 15 ' Wait for sample/hold capacitors to charge
GO_DONE = 1 ' Start conversion
While GO_DONE = 1 : Wend ' Poll the GO_DONE flag for completion of conversion
ADCON0 = %01111100 ' Select 1.024, ADC off
FVREN = 0 ' FVR Disable
EchoResult = Ad_Result
VDD = 10486/Ad_Result ' convert input reading to VDD voltage *VDD must be a Word
' 1.024 * 1024 = 1048.6 - 10486 To get 1/10th's
Return
~~~
Last edit: George Towler 2018-11-11
try the library - the results I posted are real - direct from the device with no maths.
Just a reminder you cannot use the 1.024 V ref+ for the ADC.
Are you refering to A20. I think perhaps you are misinterpreting Microchips confusing numbers. The only restrictions I see are that FVR maynot exceed Vdd, so you could not use 4.096 if Vdd was 3.3V
Deep in the bowels of the the 18F266K22 Datasheet under Electrical Specifications ( Page 451 - Table 27-21 - parameter A20)
There is no misinterpretation.
A20 is the delta minimum between VREF+ and VREF-. If VREF- is assumed to to be ground or 0V then the "minimum" VRFEF+ is 2.0V where specified accuracy is guaranteed. This precludes FVR 1.024.
However Microchip Developer Help ( FVR) ignores this and indicates that that all 3 FVR voltages can be used.
So it is not that it cannot be used, it is that it should not be used if accuracy is critical.
That being said, I have used FVR 1.024 sucessfully and with good accuracy on several projects but care must be taken to assure that accuracy.
1) The ADC device ground must be tied as close ae possible to the PIC ground pin. Not somewhere on the other side of the board where it snakes around all over the board on a thin trace before it gets to a point common to the PIC ground pin. Use "star" grounding if possible. Bad or improper grounding can cost you 10 lsb or more.
2) Likewise the signal line to the ADC input should connect as close as possible to the PIC ADC pin and not snake around all over the board.
3) The ADC impedance should not exceed 10K Ohms.
4) A clean power source. No dodgy power supplies
5) A proper bypass capacitor across the PIC VDD and ground pins ( 100nF)
6) If considerable loads are drawn from the same supply as the PIC is using then fit a 10uF to 47uF bulk capacitor on the board.
Good Luck !
Last edit: William Roth 2018-11-15
Thanks for the input, you obviously have a better handle on Microchipess than I. I also have successfully used the 1.024V ref to measure Vdd. I wonder what happens on some of the earlier devices that only had 1.024V?
Anyway I still can't get the Vdd measurement to work. I tried using ReadAd (which I assume returns a 8 bit result) but that just returns all ones.
Works here... post your code as an attachment,
By all ones, I assume you mean a decimal value of 255. This seems to indicate that the input voltage to the ADC pin is > 1.024v.
To measure VDD using FVR 1024 you will need a voltage divider from VDD to Ground.
For good resolution and easy maths the use a 10K fixed resistor over a 2K Trimer. Connect the center of this divider to the ADC input. Then use "ADC10" in your code .
Adjust the trimmer so that when VDD = 5V the ADC value is 500. This will give you a resolution of 10 mv and good accuracy.
@William, you're knowledge of electronics is infinitely greater than mine and I would not disagree with anything you've posted (as much as I understand it). But the fact remains that using non-GCB code I have successfully measured Vdd using the 1.024v FVR to better than 0.1V (according to my cheap ebay multimeter) without any additional hardware. I will take your advice and from now on will use 2.048V FVR (where available) to measure VDD. Soon as I get a chance I'll try 2.048v and the hardware you suggest.
@Anobium. Same code as 5 days ago. I've tried ReadAd with AdVal declared as a byte. I'm obviously missing something. ADC timing? I don't understand how variables used in libraries are declared, for instance Adval, should I declare it or does the lib do that?
@George. Post your code, as an attachment, and then we can help.
We can explain the internals of the libraries when we know what methods you are using. You may not need to know the library variables as the majority are not intended to be used in a user program.
I think I might know whats wrong, in the 16F1829 FVR demo code, the ReadAd command is being passed the parameter AN0, I'm pretty sure thats not the correct value. Sorry if my terminology is incorrect.
The code I'm using is the 11th. post in this thread. In my non-GCB code above I have
ADCON0 = %01111101, I'm not sure how this equates to the parameter passed to ReadAd.