i am just trying to get a readAd function working on a pic10f322 using the built in gcb routines but it seems like the adc part is not working.
for now i am just adjusting a potentiometer to change a preload value into timer0 to alter interrupt periods and toggle an led on a pin between on and off states.
if i manually adjust the numeric value of timer0 preload by typing in different numbers in the code then it works fine and the pin toggles at the differinng rates but if i use readAD with the pot into a variable and use that to alter the timer0 preload then i get no change to the led output.
i honestly cant see why its not working and just assume that i can use the gcb ADC commands to deal with setting up the adc for use but im guessing as its a lower end chip that i am probably going to have to manually set the adc registers unless someone can shed some light on the situation.
~~~
#chip 10f322, 2
#config MCLRE_off, OSC_INTOSC
#define led PORTA.0
#define ssr_out PORTA.1 'led on this pin for testing
#define timer_pot AN2
#define foot_switch PORTA.3
TRISA = b'00001100'
LATA = b'00000000'
' ANSELA = b'00000100'
Let me post an updated adc library. It will be in my morning. The library has been improved and we should get you ont the latest library before we try to resolve.
Check back at 0800 London time.
I may have the same chip so I can confirm also in my morning.
Anobium
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
While Evan works on the adc header for you, I have worked with the 10f322 a bit. Sometimes I set up a procedure just for a certain chip, just because.
dir PortA.2 in 'a-d on PIC10F32X development BD.
....
....
Call AD10F322
linear = potvalue/5 '51 steps
....
....
SUB AD10F322
ANSELA = b'00000100' 'turn off digital input ANSA2
CHS1 = 1:CHS0 = 0 'AN2
ADON = 1 'ENABLE ADC AND START CONVERSION
wait 10 us
GO_NOT_DONE = 1
ADCPOLL:
BTFSC ADCON,GO_NOT_DONE
goto ADCPOLL
ADCON = 0
ANSELA = 0 'Shut down adc module
potvalue = ADRES 'read out the result
End SUB
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Works here with library from the upcoming release. I did optimise the library is the coming release to improve support.
This was my test program. I have attached the full program to show the optimisation that you can add - in some compilers... you have to pay for optimisation. :-)
See here for the latest ADC library. This is the library for the upcoming v.0.97.02 release.
#chip 10f322, 2;-----Includelibrary#include<SoftSerial.h>;-----ConfigSerialUART:#define SER1_BAUD 9600 ; baudrate must be defined;ConfigI/Oportsfortransmitting:#define SER1_TXPORT PORTA ; I/O port (without .bit) must be defined#define SER1_TXPIN 1 ; portbit must be definedSer1Send13'newlineinTerminalSer1Send10Ser1Print"10F322 ADC test"Ser1Send13'newlineinTerminalSer1Send10doSer1PrintReadAD(AN2)Ser1Send13'newlineinTerminalSer1Send10wait100msloop
I am impressed by the generated ASM. The code is very similar to @Kent's code.. which is should be. Remember this is a library so there will be some logic to support the huge number of potential configurations but this is pretty good code for a library. I have left the comments in the ASM below.
i am just trying to get a readAd function working on a pic10f322 using the built in gcb routines but it seems like the adc part is not working.
for now i am just adjusting a potentiometer to change a preload value into timer0 to alter interrupt periods and toggle an led on a pin between on and off states.
if i manually adjust the numeric value of timer0 preload by typing in different numbers in the code then it works fine and the pin toggles at the differinng rates but if i use readAD with the pot into a variable and use that to alter the timer0 preload then i get no change to the led output.
i honestly cant see why its not working and just assume that i can use the gcb ADC commands to deal with setting up the adc for use but im guessing as its a lower end chip that i am probably going to have to manually set the adc registers unless someone can shed some light on the situation.
~~~
#chip 10f322, 2
#config MCLRE_off, OSC_INTOSC
#define led PORTA.0
#define ssr_out PORTA.1 'led on this pin for testing
#define timer_pot AN2
#define foot_switch PORTA.3
TRISA = b'00001100'
LATA = b'00000000'
' ANSELA = b'00000100'
dim pot_val as Byte
InitTimer0 Osc, PS0_256
on Interrupt Timer0Overflow call timer_int
TMR0 = 0
do
loop
sub timer_int
MOVLW b'00000010'
XORWF LATA, F
pot_val = ReadAD(timer_pot)
TMR0IF = 0
TMR0 = pot_val
end sub
~~~
thanks,
tony
Last edit: tony golding 2017-06-12
Let me post an updated adc library. It will be in my morning. The library has been improved and we should get you ont the latest library before we try to resolve.
Check back at 0800 London time.
I may have the same chip so I can confirm also in my morning.
Anobium
great to hear, thanks evan.
While Evan works on the adc header for you, I have worked with the 10f322 a bit. Sometimes I set up a procedure just for a certain chip, just because.
thanks kent,
i ended up manually setting the adc registers and all is working good now so ill just wait for the updated adc file to add into gcb.
tony
Works here with library from the upcoming release. I did optimise the library is the coming release to improve support.
This was my test program. I have attached the full program to show the optimisation that you can add - in some compilers... you have to pay for optimisation. :-)
See here for the latest ADC library. This is the library for the upcoming v.0.97.02 release.
I am impressed by the generated ASM. The code is very similar to @Kent's code.. which is should be. Remember this is a library so there will be some logic to support the huge number of potential configurations but this is pretty good code for a library. I have left the comments in the ASM below.