Let me take a stab at your question. But first let me say that when asking for advise/help it is a good idea to let us know what specific chip you are referring to. They are not all the same. The mor details you provide the better the help will be.
I am not aware of any current microcontrollers that support an interrupt on a specific ADC value. This is not a limitation of GCB as it is the microcontroller that determines what interrupts are available.
But all is not lost ! We can get creative.
We can set up a comparator to trigger at a voltage level that correlates to the ADC value. Then the output or that comparator can trigger an interrupt. The comparator can be either internal or external to the microcontroller.
Let us know what microcontroller you have and possibly more help can be provided. In the mean time may I suggest you read the interrupts section of the GCB help as it will tell you what interrupts are available.
William
Last edit: Anobium 2016-07-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A really good start is the demo folder of your installation. See \GreatCowBasic\Demos\Interrupt Solutions\Interrupt driving LED via PWM - 16F886.gcb an example of interrupts.
Another good example in your context is \GreatCowBasic\Demos\Vendor Boards\Xpress Evaluation Board\26 Reversible LEDS with ADC Variable Delay an Interrupt.gcb
Can you give me a little more context on what you are trying to do? I am hoping that you have the latest installation installed.
We can help with a little more info,
Last edit: Anobium 2016-07-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Recreating lost messages - originally posted by William Roth
With a 20MHz System clock you will likley never get to a precise 20ms interrupt on overflow unless "preset" the timer value.
With a 16Mhz Clock and Prescale of 1:1 (none) I get about 16.4 ms. So to get 20ms I use a prescale of 1:2 and "preset" the timer to adjust when the interrupt occurs
GCB does not have a preset option so it is done with "settimer" as the very first line in the ISR. I know that with at 16MHz system clock and a prescale of 1:2 that each timer tick should be ~500 nano seconds ( 1/2 microsecond)
20ms = 20,000 microseconds 20 ms would also be ~40000 timer ticks. 65530 - 40000 = 25535
So if I start the timer at 25535, it should overflow 20 ms later.
So for your 20Mhz clock ...... 1 / 20000000 = 0.00000005 * 2 * 4 = .0.0000004 sec per timer tick (400ns per tick) so you will need .020 / .0000004 ticks (50,0000)
65535 - 50000 = 15535 starting value.
Heres my code for 16MHz. (Change for 20Hz Crystal) Use a scope to measure interrupt interval at port b.6.
~~~~@
#chip 16F1829, 16
Dir PortB.6 out
on interrupt timer1overflow Call ISR1
inittimer1(OSC,PS1_2)
Starttimer 1
Do
'wait for interrupt
Loop
SUB ISR1
settimer 1, 25535
pulseout portb.6, 1 ms
end sub
~~~~~
Last edit: Anobium 2016-07-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So for your 20Mhz clock ...... 1 / 20000000 = 0.00000005 * 2 * 4 = .0.0000004 sec per timer tick (400ns per tick) so you will need .020 / .0000004 ticks (50,0000)
65535 - 50000 = 15535 starting value. <<<<<<< AHHHHHHH!!!!!!
THANK YOU SOOOOO MUCH!!!!! THAT MAKES SENSE. I finally understand. This should go in the help manual. Very valuable information!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Guys am new to gcb, pls can someone put me in d right direction how to call a sub usingi interrupt when an analog reading reaches a specific value
Last edit: Anobium 2016-07-07
Hi Aaron and welcome.
Let me take a stab at your question. But first let me say that when asking for advise/help it is a good idea to let us know what specific chip you are referring to. They are not all the same. The mor details you provide the better the help will be.
I am not aware of any current microcontrollers that support an interrupt on a specific ADC value. This is not a limitation of GCB as it is the microcontroller that determines what interrupts are available.
But all is not lost ! We can get creative.
We can set up a comparator to trigger at a voltage level that correlates to the ADC value. Then the output or that comparator can trigger an interrupt. The comparator can be either internal or external to the microcontroller.
Let us know what microcontroller you have and possibly more help can be provided. In the mean time may I suggest you read the interrupts section of the GCB help as it will tell you what interrupts are available.
William
Last edit: Anobium 2016-07-07
Hi.
A really good start is the demo folder of your installation. See \GreatCowBasic\Demos\Interrupt Solutions\Interrupt driving LED via PWM - 16F886.gcb an example of interrupts.
Another good example in your context is \GreatCowBasic\Demos\Vendor Boards\Xpress Evaluation Board\26 Reversible LEDS with ADC Variable Delay an Interrupt.gcb
Can you give me a little more context on what you are trying to do? I am hoping that you have the latest installation installed.
We can help with a little more info,
Last edit: Anobium 2016-07-07
I posted a few example yesterday. These seem to mark this thread as spxm. I will post to the files tab.
See https://sourceforge.net/projects/gcbasic/files/Demonstration%20Files/Interrupt%20Solutions/ReadValues%20using%20Timed%20Interrupt/
Was the rest of this thread moved somewhere? I just sent someone to read this and they said it was gone. He was right. Where did it go????
Last edit: Anobium 2016-07-07
I spent a happy hour today recovering this thread. It was marked as SPxM. :-( If I use that work SPxM is may get marked again.
Last edit: Anobium 2016-07-07
I am opening up a support ticket. My message just got marked as spxm.
Recreating lost messages - originally posted by William Roth
With a 20MHz System clock you will likley never get to a precise 20ms interrupt on overflow unless "preset" the timer value.
With a 16Mhz Clock and Prescale of 1:1 (none) I get about 16.4 ms. So to get 20ms I use a prescale of 1:2 and "preset" the timer to adjust when the interrupt occurs
GCB does not have a preset option so it is done with "settimer" as the very first line in the ISR. I know that with at 16MHz system clock and a prescale of 1:2 that each timer tick should be ~500 nano seconds ( 1/2 microsecond)
20ms = 20,000 microseconds 20 ms would also be ~40000 timer ticks. 65530 - 40000 = 25535
So if I start the timer at 25535, it should overflow 20 ms later.
So for your 20Mhz clock ...... 1 / 20000000 = 0.00000005 * 2 * 4 = .0.0000004 sec per timer tick (400ns per tick) so you will need .020 / .0000004 ticks (50,0000)
65535 - 50000 = 15535 starting value.
Heres my code for 16MHz. (Change for 20Hz Crystal) Use a scope to measure interrupt interval at port b.6.
~~~~@
#chip 16F1829, 16
Dir PortB.6 out
on interrupt timer1overflow Call ISR1
inittimer1(OSC,PS1_2)
Starttimer 1
Do
'wait for interrupt
Loop
SUB ISR1
settimer 1, 25535
pulseout portb.6, 1 ms
end sub
~~~~~
Last edit: Anobium 2016-07-07
Original post by viscomjim.
So for your 20Mhz clock ...... 1 / 20000000 = 0.00000005 * 2 * 4 = .0.0000004 sec per timer tick (400ns per tick) so you will need .020 / .0000004 ticks (50,0000)
65535 - 50000 = 15535 starting value. <<<<<<< AHHHHHHH!!!!!!
THANK YOU SOOOOO MUCH!!!!! THAT MAKES SENSE. I finally understand. This should go in the help manual. Very valuable information!!!