I find readad not giving 0 to 255 or my code is wrong.
If I use a number instead of readad then I get the pulse width I want but the valve only goes down to 10ms pulses. If I give the valve_pot_val =5 then it gives 5ms pulses.
in this I changed the valve_pot_val to 2
valve_pot_val = 2 ;readad (drop_size_pot) / 14 + 1
and I get the desired value but readad is not working as I expected
is it an arduino issue?
any help appreciated,cheers
'#define strobe_pot portc.1' is a constant the sets strobe_pot to portc.1
and, then, you use the constant to read the ADC strobe_pot_val = readad (strobe_pot)
So, in the Help. For a normal ( also called a Single Channel ) read use.
byte_variable = ReadAD( ANX )
Where ANXis constant and the ANX is the constant the points to the ADC you want to read.
So, strobe_pot_val = readad (strobe_pot) will fail the value of the constant that refers to the port will be 0 or 1.
YES , you are correct...my mistake.I did read the help but ANX I thought refered to an a- to-d port.
Changed this line...didn't even need scale funtion and now sweeps 1 to 19 ms pulse every 20 ms
valve_pot_val = readad (AN0) / 14 + 1
Thank you for you time helping me...I know how busy you must be. It is appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
ps. with all respect,data sheets are too complicated. I thought the idea of basic was to dumb down the technical under the hood stuff as much as possible or else why use it?
I wish I could look at a devices data sheet and write a lib for it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
does not assemble.
Why in my code did I get varying pot values? Not 0 to 255 but more like half the pot like 0 to 127
but still reading something. I should have sent the values to the terminal to see what I was getting.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
WARNINGs / ERRORs reported by Great Cow BASIC (if Syntax Error, doubleclick on the errormessage below) <<<
addefinetest.gcb (10): Error: 0 is not a valid I/O pin or port
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Where ANX is constant and the ANX is the constant the points to the ADC you want to read within the context of the READADC, READADC10 or READADC12 commands.
You should not use ANX outside of the context stated above.
If you use DIR ANx IN|OUT you will get an error. Use DIR PORTn.n IN|OUT
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks,cleared things up a bit.
Still don't know the ad values I got from my first post but they varied.
What were they if the defines were all messed up..a bit?
I thought this was some 328 error.
What was it doing when I readad portc.0 defined as valve_pot and got half range values...
or is it just don't do it that way? :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If I change line 10 to dir portc.0 in then I can use valve_pot_val = readad (drop_size_pot) / 14+1...
well it assembles ok.
It scopes ok with full 0 to 255 pot sweep.
This works but why the define didn't work for the port dir ??
Couldn't the help just say
If using 328 then readad port is C.
portc.0 is AN0
portc.1 is AN1
portc.2 is AN2
Always use readad (AN0)
Do not use readad (portc.0)
Cos it looks like ANX is not a keyword but a representation of the specific port...IMHO
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Cos I'm using readad in a timed loop then can I ask if readad always take the same time to execute?
If not then should it be interrupt driven?...which I am interested in at the moment, cos they seem to solve many problems.... and as Chris Roper said..needs discussing.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I find readad not giving 0 to 255 or my code is wrong.
If I use a number instead of readad then I get the pulse width I want but the valve only goes down to 10ms pulses. If I give the valve_pot_val =5 then it gives 5ms pulses.
ps...what has happened to the coding and forum editor....it erases next char as you write
in this I changed the valve_pot_val to 2
valve_pot_val = 2 ;readad (drop_size_pot) / 14 + 1
and I get the desired value but readad is not working as I expected
is it an arduino issue?
any help appreciated,cheers
It is a case of the read the manual.
'#define strobe_pot portc.1' is a constant the sets
strobe_pot
toportc.1
and, then, you use the constant to read the ADC
strobe_pot_val = readad (strobe_pot)
So, in the Help. For a normal ( also called a Single Channel ) read use.
byte_variable = ReadAD( ANX )
Where
ANX
is constant and theANX
is the constant the points to the ADC you want to read.So,
strobe_pot_val = readad (strobe_pot)
will fail the value of the constant that refers to the port will be 0 or 1.And, where
strobe_pot_val = readad (AN1)
will work as AN1 is PC1 (ADC1/PCINT9) as shown on the datasheet page 3 - http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdfand, the same applies to the READADC( drop_size_pot ) ....
Last edit: Anobium 2020-08-02
YES , you are correct...my mistake.I did read the help but ANX I thought refered to an a- to-d port.
Changed this line...didn't even need scale funtion and now sweeps 1 to 19 ms pulse every 20 ms
valve_pot_val = readad (AN0) / 14 + 1
Thank you for you time helping me...I know how busy you must be. It is appreciated.
ps. with all respect,data sheets are too complicated. I thought the idea of basic was to dumb down the technical under the hood stuff as much as possible or else why use it?
I wish I could look at a devices data sheet and write a lib for it.
So how to define AN0 as portc.0
does not assemble.
Why in my code did I get varying pot values? Not 0 to 255 but more like half the pot like 0 to 127
but still reading something. I should have sent the values to the terminal to see what I was getting.
We need more code. How are you using the constant? What is the error?
Source-File = C:\Users\stanley555\Documents\GCBasic stuff\Arduino\addefinetest.gcb
Updated for you.
Where ANX is constant and the ANX is the constant the points to the ADC you want to read within the context of the READADC, READADC10 or READADC12 commands.
You should not use ANX outside of the context stated above.
If you use DIR ANx IN|OUT you will get an error. Use DIR PORTn.n IN|OUT
thanks,cleared things up a bit.
Still don't know the ad values I got from my first post but they varied.
What were they if the defines were all messed up..a bit?
I thought this was some 328 error.
What was it doing when I readad portc.0 defined as valve_pot and got half range values...
or is it just don't do it that way? :)
If I change line 10 to dir portc.0 in then I can use valve_pot_val = readad (drop_size_pot) / 14+1...
well it assembles ok.
It scopes ok with full 0 to 255 pot sweep.
This works but why the define didn't work for the port dir ??
Couldn't the help just say
If using 328 then readad port is C.
portc.0 is AN0
portc.1 is AN1
portc.2 is AN2
Always use readad (AN0)
Do not use readad (portc.0)
Cos it looks like ANX is not a keyword but a representation of the specific port...IMHO
Not really. We would have to do the same for about 1000 other chips.
Cos I'm using readad in a timed loop then can I ask if readad always take the same time to execute?
If not then should it be interrupt driven?...which I am interested in at the moment, cos they seem to solve many problems.... and as Chris Roper said..needs discussing.
Yes same time to execute.
You can use an timed interrupt to call the readad methods.
Thanks,handy to know.
Assume the help is ok and I misunderstood.
no one will make the mistakes I made on wrong assumptions..hopefully.
cheers.