how to simulate interupts
ion
Posts: 101
Hello everybody,
I have a weird question. As all of us know about lack of interrupts on a stamp.
I have a program when if a certain input is on, the program jump to a subroutine to display error messages. Because I wanted to make it nice I put the message to flash, which means display· on, one sec pause , display off, one second pause, return, to check the status of the input.
This is ok , but during the 2 seconds on that subroutine, my stamp is blind for what does happen with the inputs.
What I would like to know if it is a way to put a counter in the program and turn the display on or off based in that counter without spending time in the subroutine.
Original code:
·
MAIN:
····· IF (RESET = 0)· THEN NORMAL_RUN· ······················ ·'RESET
RESET_ON:
AUXIO
LOW LOCK
MAINIO
GOSUB displ_error_start
GOTO MAIN
·
NORMAL_RUN:
AUXIO
LOW DRV
MAINIO
IF (PART=0) THEN·················· 'PART ON· INPUT 3
·
··········· EEADDR=0··········· 'SYSTEM READY"
··········· GOSUB SHOW
.
.·········· rest of the code here
.··········
.
·
end
·
displ_error_start:
··········· SEROUT lcdpin,lcdbaud,[noparse][[/noparse]12]
··········· PAUSE 1000
··········· EEADDR=320··········· 'RESET IS ON
··········· GOSUB SHOW
··········· EEADDR=340··········· 'SYSTEM· IN BYPASS
··········· GOSUB SHOW
··········· EEADDR=460··········· 'CHECK YOUR PARTS
··········· GOSUB SHOW
··········· PAUSE 1000
··········· RETURN
·
·
SHOW:
STORE 1
SEROUT lcdpin,lcdbaud,[noparse][[/noparse]14]
DO
· READ EEADDR, eeData
· SEROUT lcdpin,lcdbaud,[noparse][[/noparse]eedata]
· eeaddr=eeaddr+1
· IF (eedata = CR) THEN EXIT
LOOP
STORE 0
RETURN
So what I want is· that each time when the program pass through the main code, to add 1 to a certain variable. When the variables is a preset number I would like to jump to a subroutine, turn the display on, and start counting again from zero. The next time when the variable is at preset, jump to a different subroutine and turn it off.
In this case, the program executes normal and I have control over the inputs and outputs.
I am using a bs2pe24. The next question, is where to find out what is the length of time for an instruction to execute, so I can calculate my preset number rather then guessing?
And, because we are dealing with instructions, where I can find a table with the space taken for each instruction in the memory? ·In this case, if I run out of space in a slot I can look how to replace an instruction with a different one, which take less space.
I have a weird question. As all of us know about lack of interrupts on a stamp.
I have a program when if a certain input is on, the program jump to a subroutine to display error messages. Because I wanted to make it nice I put the message to flash, which means display· on, one sec pause , display off, one second pause, return, to check the status of the input.
This is ok , but during the 2 seconds on that subroutine, my stamp is blind for what does happen with the inputs.
What I would like to know if it is a way to put a counter in the program and turn the display on or off based in that counter without spending time in the subroutine.
Original code:
·
MAIN:
····· IF (RESET = 0)· THEN NORMAL_RUN· ······················ ·'RESET
RESET_ON:
AUXIO
LOW LOCK
MAINIO
GOSUB displ_error_start
GOTO MAIN
·
NORMAL_RUN:
AUXIO
LOW DRV
MAINIO
IF (PART=0) THEN·················· 'PART ON· INPUT 3
·
··········· EEADDR=0··········· 'SYSTEM READY"
··········· GOSUB SHOW
.
.·········· rest of the code here
.··········
.
·
end
·
displ_error_start:
··········· SEROUT lcdpin,lcdbaud,[noparse][[/noparse]12]
··········· PAUSE 1000
··········· EEADDR=320··········· 'RESET IS ON
··········· GOSUB SHOW
··········· EEADDR=340··········· 'SYSTEM· IN BYPASS
··········· GOSUB SHOW
··········· EEADDR=460··········· 'CHECK YOUR PARTS
··········· GOSUB SHOW
··········· PAUSE 1000
··········· RETURN
·
·
SHOW:
STORE 1
SEROUT lcdpin,lcdbaud,[noparse][[/noparse]14]
DO
· READ EEADDR, eeData
· SEROUT lcdpin,lcdbaud,[noparse][[/noparse]eedata]
· eeaddr=eeaddr+1
· IF (eedata = CR) THEN EXIT
LOOP
STORE 0
RETURN
So what I want is· that each time when the program pass through the main code, to add 1 to a certain variable. When the variables is a preset number I would like to jump to a subroutine, turn the display on, and start counting again from zero. The next time when the variable is at preset, jump to a different subroutine and turn it off.
In this case, the program executes normal and I have control over the inputs and outputs.
I am using a bs2pe24. The next question, is where to find out what is the length of time for an instruction to execute, so I can calculate my preset number rather then guessing?
And, because we are dealing with instructions, where I can find a table with the space taken for each instruction in the memory? ·In this case, if I run out of space in a slot I can look how to replace an instruction with a different one, which take less space.
Comments
The trick is program organization.· Most of my programs have this general structure:
Every time the main loop runs the "interrupt" input is checked and handled if required; then the program runs the nomal task cycle.· So, instead of creating a long linear program, you can create a list of tasks to run (that can run in linear order), but also have the flexibility to be run out of sequence to deal with circumstances that may come up.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
I will try it
Ion
You could add a bit of flexibility to your Show subroutine by using Z-Strings -- this would allow you to embed carriage returns in your messages.· If you're using a multi-line display this can be useful.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Are you sure that you do not have any blood relation with Mother Theresa?
Now serious:
On the help file, under toggle command is an example
OUT2 = IN2 ‘ make output driver match pin state
TOGGLE 2
I have a bs2p40 with in2 on the mainio and out2 on the auxio.
This command seems like it will not work on this chip unless I put an intermediary bit variable. Is this correct ?
You would not use the OUTx = INx thing on two physically different pins. You may want to re-read that section in the help file; its point is to make sure you get what you expect out of TOGGLE.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
The problem is the BS2p40. I can not address the auxiliary IO unless i use a command to transfer the control from MAINIO to AUXIO.
My input is on my PCB on MAINIO and all the outputs are on the AUXIO.
I have OPTO isolators from 24vdc on INPUTS and darlingtons 2003 on the OUTPUTS. How to activate the output from an input based in the same expresion. It is OK for a 16 IO chip where i do not use MAINIO or AUXIO or IOTERM.
Can be done with IF..THEN but i like this aproach more as simpler then IF...THEN.
Any sugestion ?
Thanks
Ion
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
In the interim i used for only one IN and OUT this:
AUXIO
DRV VAR OUT3 'SIGNAL TO DC DRIVER TO ENABLE THE TOOL
MAINIO
VDRV VAR Bit ' Virtual input
TRIG VAR IN7 'FROM DC CONTROLLER TRIGER IS IN ON
MAIN:
vdrv=trig 'make the virtual input to follow the state of the input 7 on mainio
AUXIO
drv=vdrv 'make the output 3 on auxio to follow the virtual bit == input 7 on mainio
MAINIO
It works but i will use yours because i have more then one bit to control
Thanks for help
Ion
If you set the pins on mainio as polling inputs, you can then test the state of those pins without switching back and forth between auxio & mainio. Instead, you test them by GETing the contents of scratchpad locations 128 and 129 (read only--the state of auxio is held in locations 130 and 131).
I don't think the above code is any better than the one Jon suggested, which involved switching to mainio, reading the pins into a word variable, and switching back to auxio to set the outputs.
However, things get interesting if you use POLLMODE 10 instead of POLLMODE 2. The bits in the scratchpad will !!_latch_!! the in the target state. The state of the pins is checked and updated in the scratchpad buffer in between every PBASIC command, so these commands can be quite useful to catch a relatively short input pulse while the program is off doing other tasks. Polling is not a true interrupt, but maybe you can do something with it.
Note that there is also a POLLOUT command, which would automatically (without further program code) transfer an input state to an output state, and the coupled inputs and outputs can be on either mainio or auxio. Don't get excited though! The command is of little use AFAIK when you have multiple outputs to be coupled separately to multiple inputs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks again
Ion