This is my first post on this forum and I have probably an very beginner question:
I wonder how it is possible in GCBasic program on ATMega328p switch between 5 V Vcc and 1.1 V internal reference voltage for the ADC?
I'm writing a program in GCB@Syn (last release) for the Arduino UNO, which would use keyboard shield (it requires 5 V for ADC) and LM35 temperature sensors (requires 1.1 V).
I appreciate any help that you can provide.
Best regards from Slovenia.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The ATmega 328P data sheet says you need to set the ADMUX register bits REFS0 and REFS1 for the internal 1.1V reference. So you can try and see if setting those bits, prior to reading the LM35 channel, survives the adc.h manipulations? You would of course clear those bits right after the read to get back to the 5V reference.
Set ADMUX.REFS0 On
Set ADMUX.REFS1 On
LM75temp = READAD(whatever pin)
Set ADMUX.REFS0 On
Set ADMUX.REFS1 Off
EDIT: My bad, I think you need to leave REFS0 bit on for AVcc (no external ref).
Last edit: kent_twt4 2015-07-11
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Arduino board is yet to come, this will be my first project with AVR and I was not sure whether it is enough just to change:
Set ADMUX.REFS1 On 'For 1.1 V reference source
or
Set ADMUX.REFS1 Off 'For 5 V reference source
In this manner written my program (previously was written for the PIC 16F88 and operational amplifier for magnifying sensor voltage) I tested on demo version of Oshon AVR Simulator IDE. It worked everything, except change the ADC voltage source. So I did not know whether that limit / defect in the simulator or I did something wrong in my program (needs more parameters, a different form of set command, etc). Because of this I also put this question.
Limit 30 starts of the demo version of simulator, I'm exceeded yesterday, so now I have to wait for the real Arduino hardware and determine how the program will work on it.
.
Thanks again.
Last edit: Friderik Back 2015-07-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
GCBASIC will overwrite anything that you put into te ADMUX register - but there is an option that lets you change the ADC reference source on AVR. You can set the AD_REF_SOURCE constant to whatever you want to use. It defaults to the VCC pin, but you can tell it to use the 1.1V reference with this:
#define AD_REF_SOURCE AD_REF_256
(256 refers to the 2.56V reference on some older AVRs, but the same code will select the 1.1V reference on an ATmega328p.)
You can also use some tricks to switch this dynamically. Here's an example of some code that will does this:
Here, we set the AD_REF_SOURCE to a variable, and then change the value of the variable to select the source. With this approach, we also need to allow time to charge the reference capacitor to the correct voltage. To use this second bit of code, you'll need to get an updated copy of the a-d.h file from https://svn.code.sf.net/p/gcbasic/code/GCBASIC/trunk/include/lowlevel/a-d.h
Hope this helps!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, the manufacturer has spared an single ultra low-cost resistor. Unfortunately, in this way, many programs, that use LCD backlight, become inappropriate. Because overloading the mcu and its power source (and Q1).
My solution of this problem is a simple software trick (PWM does not work!):
By the way, diode for the diode mod it should be an Schottky diode (BAT85 or similar). With silicon diodes can not be guaranteed that the backlight is really completely turned off.
@Hugh
Your solution is much better and I have already joined in the my program. Thank you.
Now I just wait to get a Arduino board and shield. Then I can test my program and give you the results. I would like to made a digital differential thermostat.
I hope you understand my bad English.
Best regards
Last edit: Friderik Back 2015-07-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
This is my first post on this forum and I have probably an very beginner question:
I wonder how it is possible in GCBasic program on ATMega328p switch between 5 V Vcc and 1.1 V internal reference voltage for the ADC?
I'm writing a program in GCB@Syn (last release) for the Arduino UNO, which would use keyboard shield (it requires 5 V for ADC) and LM35 temperature sensors (requires 1.1 V).
I appreciate any help that you can provide.
Best regards from Slovenia.
The ATmega 328P data sheet says you need to set the ADMUX register bits REFS0 and REFS1 for the internal 1.1V reference. So you can try and see if setting those bits, prior to reading the LM35 channel, survives the adc.h manipulations? You would of course clear those bits right after the read to get back to the 5V reference.
EDIT: My bad, I think you need to leave REFS0 bit on for AVcc (no external ref).
Last edit: kent_twt4 2015-07-11
Thank you very much for your reply.
Arduino board is yet to come, this will be my first project with AVR and I was not sure whether it is enough just to change:
or
In this manner written my program (previously was written for the PIC 16F88 and operational amplifier for magnifying sensor voltage) I tested on demo version of Oshon AVR Simulator IDE. It worked everything, except change the ADC voltage source. So I did not know whether that limit / defect in the simulator or I did something wrong in my program (needs more parameters, a different form of set command, etc). Because of this I also put this question.
Limit 30 starts of the demo version of simulator, I'm exceeded yesterday, so now I have to wait for the real Arduino hardware and determine how the program will work on it.
.
Thanks again.
Last edit: Friderik Back 2015-07-12
Keep us informed of progress.
Be aware that some of the Ardiuno keyboard shields require modification if you are not to damaged your device. See this folder, https://sourceforge.net/projects/gcbasic/files/Demonstration%20Files/LCD%20Solutions/Four%20Wire%20LCD%20Solutions/Arduino_LCDShield/, I had to adapt all my LCD shields last month when I used a Mega328p.
Evan
@Frederik
Please note that the ADMUX register initial, or reset value, is b'00000000', so still need to set the REFS0 bit.
GCBASIC will overwrite anything that you put into te ADMUX register - but there is an option that lets you change the ADC reference source on AVR. You can set the AD_REF_SOURCE constant to whatever you want to use. It defaults to the VCC pin, but you can tell it to use the 1.1V reference with this:
(256 refers to the 2.56V reference on some older AVRs, but the same code will select the 1.1V reference on an ATmega328p.)
You can also use some tricks to switch this dynamically. Here's an example of some code that will does this:
Here, we set the AD_REF_SOURCE to a variable, and then change the value of the variable to select the source. With this approach, we also need to allow time to charge the reference capacitor to the correct voltage. To use this second bit of code, you'll need to get an updated copy of the a-d.h file from https://svn.code.sf.net/p/gcbasic/code/GCBASIC/trunk/include/lowlevel/a-d.h
Hope this helps!
Thank you, I really did not expect so many responses.
@Evan
Yes, I know this problem. The consequence of stupid saver. Look schematic around Q1:
Keypad version 1.0:
http://www.dfrobot.com/image/data/DFR0009/LCDKeypad%20Shield%20V1.0%20SCH.pdf
Keypad version 1.1:
http://www.dfrobot.com/wiki/images/a/a7/LCDKeypad_Shield_SCH.png
source:
http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_(SKU:_DFR0009)
Yes, the manufacturer has spared an single ultra low-cost resistor. Unfortunately, in this way, many programs, that use LCD backlight, become inappropriate. Because overloading the mcu and its power source (and Q1).
My solution of this problem is a simple software trick (PWM does not work!):
By the way, diode for the diode mod it should be an Schottky diode (BAT85 or similar). With silicon diodes can not be guaranteed that the backlight is really completely turned off.
@Hugh
Your solution is much better and I have already joined in the my program. Thank you.
Now I just wait to get a Arduino board and shield. Then I can test my program and give you the results. I would like to made a digital differential thermostat.
I hope you understand my bad English.
Best regards
Last edit: Friderik Back 2015-07-13