View Full Version : adc programming
geardown
04-21-03, 10:30 PM
Would some one please explain what I am doing wrong
MACHINE W
ON-MACHINE W
APPEND-STATE 1
IN-STATE 1
CONDITION
ADC0 15000 <
CAUSES
GRNLED ON
THEN-STATE 1
TO-HAPPEN
IN-STATE 1
CONDITION
ADC0 15000 >
CAUSES
GRNLED OFF
THEN-STATE 1
TO-HAPPEN
IN-STATE 1
CONDITION
ADC0 15000 =
CAUSES
THEN-STATE 1
TO-HAPPEN
1 SET-STATE
INSTALL W
I tried this several different ways, including not using the
adc0 15000 =
Thank You
nmitech
04-22-03, 11:29 AM
....
CONDITION
ADC0 15000 <
CAUSES
....
should be,
...
CONDITION
ADC0 ANALOGIN 15000 <
CAUSES
....
nmitech
04-22-03, 12:26 PM
MACHINE W
ON-MACHINE W
APPEND-STATE 1
IN-STATE 1
CONDITION
ADC0 ANALOGIN 15000 <
CAUSES
GRNLED ON
THEN-STATE 1
TO-HAPPEN
IN-STATE 1
CONDITION
ADC0 ANALOGIN 15000 >
CAUSES
GRNLED OFF
THEN-STATE 1
TO-HAPPEN
IN-STATE 1
CONDITION
ADC0 ANALOGIN 15000 =
CAUSES
THEN-STATE 1
TO-HAPPEN
ISOMAX-START
1 SET-STATE
INSTALL W
geardown
04-23-03, 01:40 AM
Thank You
Okay that works but where did the
ISOMAX-START come from ?
What is this enabling? It is not in the manual.
Why does the line
ADC0 ANALOGIN 15000 = need to be there ?
Can I create an area of void in the change over
where there is no change in states by using a value like
14000> 16000<
How do I create a wait state where the value is pulled down to a specific number and it waits a given period before checking the value again and acting on it.
nmitech
04-23-03, 11:06 AM
where did the
ISOMAX-START come from ?
What is this enabling? It is not in the manual.
ISOMAX-START is explained in the INSTALL appnote from the IsoPod Download page, http://www.newmicros.com/store/product_manual/download.html
The good reason to use ISOMAX-START because your program is developed in Ram and you need a COLD word at the beginning of your program to clear the previous program so you have room to reload the new program over and over again. Once a word COLD is executed, the IsoMax timer will STOP and you must do ISOMAX-START to enable the timer again in order to run your machine(s) with INSTALL word.
Why does the line
ADC0 ANALOGIN 15000 = need to be there ?
I just copied from your previous posting program. If you don't need it just delete it.
Can I create an area of void in the change over
where there is no change in states by using a value like
14000> 16000<
{see the next two post down}
Why have you place a DROP in the CAUSE statement?
The CAUSE not supposed to take the CONDITION state?
nmitech
04-23-03, 02:57 PM
CIM is right! We have to drop any excess values *before* CAUSES, because the code after CAUSES may not get executed.
GEARDOWN, please try this instead,
IN-STATE S1
CONDITION
ADC0 ANALOGIN DUP 16000 < SWAP 14000 > AND
CAUSES
GRNLED ON
THEN-STATE S1
TO-HAPPEN
By the way, do NOT name states "1" or "2" or any number. This will prevent IsoMax from recognizing those numbers as numbers!
RMDumse
04-24-03, 12:07 PM
Just as a note, reading the A/D (being the subject of this thread) doesn't have to be done with the ANALOGIN word, which is just a convenience.
One could go to the A/D directly.
In that case, a bit of initialization would need to be run one time, then the A/D could be read directly.
Try this, in or as part of an initialization word
: INIT
2003 0E80 ! ( ASSIGN ADC CONTROL REG 1
003D 0E81 ! ( ASSIGN ADC CONTROL REG 2
3210 0E83 ! ( ASSIGN ADC CHANNEL LIST REG 1
7654 0E84 ! ( ASSIGN ADC CHANNEL LIST REG 2
; EEWORD
Then whenever you want an analog reading, just take it from the appropriate register, like this for AN0
E89 @
so instead of
IN-STATE S1
CONDITION
ADC0 ANALOGIN DUP 16000 < SWAP 14000 > AND
CAUSES
GRNLED ON
THEN-STATE S1
TO-HAPPEN
you could do
CIM is right! We have to drop any excess values *before* CAUSES, because the code after CAUSES may not get executed.
IN-STATE
S1
CONDITION
E89 @ DUP 16000 < SWAP 14000 > AND
CAUSES
GRNLED ON
THEN-STATE
S1
TO-HAPPEN
You can decide which you like best. Now I haven't checked the app note on what ANALOGIN does, so there may be some smoothing or scaling in there. You wouldn't get the smoothing or scaling in my example. The reading would be the raw A/D result which should be less than 2uS old. It will be left justified, with the bottom 3 bits being noise (it's a 12 bit A/D and there are a sign and 15 bits in the register location).
nmitech
04-24-03, 03:52 PM
How do I create a wait state where the value is pulled down to a specific number and it waits a given period before checking the value again and acting on it.
The example below will toggle the red led every 1 second, where the machine is scheduled run at every 1 milli-second.
COLD
DECIMAL
0 TCFTICKS !
MACHINE TIMEOUT
ON-MACHINE TIMEOUT
APPEND-STATE BLINKRED
IN-STATE
BLINKRED
CONDITION
TCFTICKS @ 1000 =
CAUSES
0 TCFTICKS !
REDLED TOGGLE ( or whatever you want it here... )
THEN-STATE
BLINKRED ( or next state ... )
TO-HAPPEN
ISOMAX-START
5000 PERIOD
BLINKRED SET-STATE
INSTALL TIMEOUT
( Please refer to the IsoMax Timing appnote for more detail, http://www.newmicros.com/store/product_manual/Isotiming.pdf )
RMDumse
04-25-03, 12:12 AM
I may be missing something, but where is the part in this example that increments the counter, TCFTICKS ? I would suspect there needs to be a TCFTICKS 1+! or something of that nature after CONDITION and ahead of the test feeding the boolean to CAUSES .
Really, this is something the LOOPINDEX were made for, and I've recently started using them. Now, I would have approached the problem like this:
COLD
DECIMAL
LOOPINDEX MSCNT
MSCNT 1000 START 0 END -1 STEP EEWORD
MACHINE TIMEOUT
ON-MACHINE TIMEOUT
APPEND-STATE BLINKRED
IN-STATE
BLINKRED
CONDITION
MSCNT COUNT
CAUSES
MSCNT RESET
REDLED TOGGLE ( or whatever you want it here... )
THEN-STATE
BLINKRED ( or next state ... )
TO-HAPPEN
ISOMAX-START
5000 PERIOD
BLINKRED SET-STATE
INSTALL TIMEOUT
nmitech
04-25-03, 09:56 AM
TCFTICKS is a word in the IsoMax Kernel. It will automatically increment by 1 on every IsoMax processing cycle. The previous example using TCFTICKS word should work the way it is.
RMDumse
04-25-03, 02:42 PM
Oh yes, the system variable! I had not thought about the name cearly. I hadn't thought of changing the system variable on the fly, because if another machine were using it for a time reference as well, there could be conflict. But in the example with a single use per system that would work. But personally, as mentioned above, I'd prefer LOOPINDEX variables for this purpose. Thanks for reminding me of TCFCOUNT!
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.