trying to alter the example code for A2D scaling for the 16F690 on the low
pin count demo board
code
#chip 16f690,8
#config FOSC_INTOSC , WDTE_OFF , PWRTE_OFF , MCLRE_OFF , CP_OFF , CPD_OFF
, BOREN_ON , IESO_OFF, FCMEN_OFF
#script
'reference voltage 5v
'actual voltage at port when 100% Pot 4.15
'adc max 1023
'number of graduations requried 15
reference_voltage = 4.15
vcc = 5
numberofgrads = 15
maxADC = 1023
ADC_adjustment = int((reference_voltage*100)/(vcc*10))
ADC_adjustment = int(ADC_adjustment * maxADC / numberofgrads / 10 )
#endscript
dir portc out
dir porta.0 in
Do
If ( ReadAD10 ( AN0 ) / ADC_adjustment ) > 500 Then
Set portc.3 On
Else
Set portc.3 Off
End If
Loop
end code
it will only work if i remove the ADC adjustment part;i must be formatting
it incorrectly?
the example compiles and works; the altered version compiles OK then sits
doing nothing..
I have assumed 1019 is the max ADC for that board - you code calibrate and then change this value.
#chip 16f690,8
#config MCLRE_OFF
dir portc out
dir porta.0 in
Do
If ( Scale(ReadAD10(AN0), 0, 1019, 0, 103) > 500 ) Then
Set portc.3 On
Else
Set portc.3 Off
End If
Loop
For an example of self calibation see, C:\GCB@Syn\GreatCowBasic\demos\Vendor_Boards\Great_Cow_Basic_Demo_Board\18F25Q10_ChipRange_Demonstrations\050_Show_A2D_value_on_LEDs.gcb You can adapt the method to a scale of 0 to 1023.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Silly error in my previous post.. Scale(ReadAD10(AN0), 0, 1019, 0, 103)..103 should read 1023.
This code has serial output to terminal also - so, you can understand the raw value at the ADC and the Scaled value/
Enjoy
Anobium
#chip 16f690,8#option Explicit'USART settings - connection 0V and TX on Port = RB7#define USART_BAUD_RATE 9600#define USART_TX_BLOCKINGdirportcoutdirporta.0in'Dimension a variabledimADCValueasworddimMaxADCValaswordMaxADCVal=0DoADCValue=ReadAD10(AN0)'Print Raw valueHSerPrintADCValueHSerSend9'Ensure the ADC value supports the widest range.'Use the MaxADCVal as the top range measure then scale from 0 to the MaxADCVal'You will have to swing the potentiometer through the complete range, but, do this once and you have a full range!if(ADCValue>MaxADCVal)ThenMaxADCVal=ADCValueendifADCValue=Scale(ADCValue,0,MaxADCVal,0,1023)If(ADCValue>500)ThenSetportc.3OnElseSetportc.3OffEndIf'Print Scaled valueHSerPrintADCValueHSerPrintCRLFwait25msLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
many thanks. i added the missing 2 and it runs OK! and shows how noisy the pot on my LPCDB really is...:/ i did a fresh install and now have 2 Vendor board folders,odd.including the one referenced which wasn't in the version i was using. that'll teach me to mess about with things...8)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes.. the demo folder is now ALL lowercase to support Linux installation. So, delete the demo folder (save all your own stuff!).... and reinstall to tidy up.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have replaced the pots on my boards here. They do play up. The serial terminal should show the raw values and if that if leaping about.....replace the pot.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
trying to alter the example code for A2D scaling for the 16F690 on the low
pin count demo board
code
end code
it will only work if i remove the ADC adjustment part;i must be formatting
it incorrectly?
the example compiles and works; the altered version compiles OK then sits
doing nothing..
Last edit: Anobium 2019-03-16
Let us remove the script and use Scale()
I have assumed 1019 is the max ADC for that board - you code calibrate and then change this value.
For an example of self calibation see, C:\GCB@Syn\GreatCowBasic\demos\Vendor_Boards\Great_Cow_Basic_Demo_Board\18F25Q10_ChipRange_Demonstrations\050_Show_A2D_value_on_LEDs.gcb You can adapt the method to a scale of 0 to 1023.
nope; the new version does nothing either! it compiles and flashes the chip but sits unresponsive.
I will get out a 690 and LPC board.
15 mins.....
Operational code.
Silly error in my previous post.. Scale(ReadAD10(AN0), 0, 1019, 0, 103)..103 should read 1023.
This code has serial output to terminal also - so, you can understand the raw value at the ADC and the Scaled value/
Enjoy
Anobium
many thanks. i added the missing 2 and it runs OK! and shows how noisy the pot on my LPCDB really is...:/ i did a fresh install and now have 2 Vendor board folders,odd.including the one referenced which wasn't in the version i was using. that'll teach me to mess about with things...8)
Yes.. the demo folder is now ALL lowercase to support Linux installation. So, delete the demo folder (save all your own stuff!).... and reinstall to tidy up.
See https://learn.sparkfun.com/tutorials/analog-to-digital-conversion/relating-adc-value-to-voltage for the explain of the calcultation on the LPC board.
My VDD is 4.90v
My Analog Voltage measured, the maximum is 4.08v
therefore: 4.90v / 1023 * 4.08 = 851. And, 851 is the ADC raw value... it works!
my VDD measures a measly 4.65V on the demo header; my mileage definately varies! this explains why nothing made much sense...
I have replaced the pots on my boards here. They do play up. The serial terminal should show the raw values and if that if leaping about.....replace the pot.