I'm working with a small project that will require using a multiplexed 3 X 7 Segment LED display, there aren't any ballast resistors on the LED segments, so the ideas is to touch them so fleetingly that they do not consume too much current at any on time.
When you look at the source code of this device and similar arrangments, there is usually a interrupt service routiune that handles segment/display managent and other associated timing responsabilities, as a background task of the main program logic.
Does any one have any experience on how to do this in Great Cow Basic, or perhaps some example code to share?
Are you asking for a port on the exiting code? or, are you doing this already? see
We have a number of example of handling interrupts in the Help File. Also, I can let you have a pre-release version of the next release to ease the handling of the interrupts and the driving those LEDs.
So, I think the question is. What is the ask in terms of example code?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What Anobium says. Also having the micro used and what type of 3 digit 7 segment display (common anode or cathode) helps also.
Help has examples of a three digit multiplex display already, just not using interrupts. I am currently using (4) 4 digit multiplexed displays in a project. Not using the standard 7 segment library per se, nor using the timer interrupt for the displays. But, using the TMR1Overflow interrupt to schedule certain events.
This is the goto link on how to setup a Timer overflow interrupt to a fixed time base https://sourceforge.net/p/gcbasic/discussion/579125/thread/03348d5c/#6c76/281f
I would try for a 100us timeroverflow and adjust from there. I am using on times of 40us before changing digits, but am also using 'HC595's" to do the switching. The HC595's can get kinda hot, as only using 10 ohm resistors.
So,
1) Set up timer overflow interrupt to specified time base
2) Set up the counter in the called interrupt sub to advance the digits use conditional if's or select case.
Based off the Help examples the timer setup and interrupt sub might look something like this (Note, the timebase in this example is for 100ms interrupt):
'pre Main setup code
On Interrupt Timer1Overflow Call Event_Schedule
InitTimer1 Osc, PS1_1/8
TMR1H = 133 '10MHz clock, PS1_1/8, TMR1H= 133, TMR1L = 237
TMR1L = 237
StartTimer 1
Digit = 0
...
...
'Main:
...
...
sub Event_Schedule
TMR1IF = 0
TMR1H = 133 '10MHz clock, PS1_1/8, TMR1H= 133, TMR1L = 237
TMR1L = 237
Digit += 1
If Digit = 4 Then Digit = 1
If Digit = 1 Then DisplayValue 1, Num1
If Digit = 2 Then DisplayValue 2, Num2
If Digit = 3 Then DisplayValue 3, Num3
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I had a look at the source web page and the source code. It may be simpler, I hate to say this, but, use the compiler they recommend.
There may be a really good justification, that I am not aware of, to port. Then, we are here for you! :-)
Meanwhile, here is a piece of code to show a development of Kent's approach. This will required v0.95 of the GCB but this draws less than 1ma when at the lowest setting and 9ma at the highest setting for the variable softwarePWM. I have set limits to softwarePWM to ensure I did not draw to much current from the the port. I tested on constant current PSU, a scope and two meters. See the note below. This is essentially the power control is that very large piece of code on the source web site.
Note to readers: Connecting an LED to the output port, or, sinking an LED to an port on a microcomputer will cause damage. The greatest care must be taken to ensure the limits of current are not exceeded. Permanent damage will occur.
Anobium
~~~~~
'This program switch the LED on and off every time Timer2 matchs PR2
#chip 10f320, 16
'Connecting an LED to the output port, or, sinking an LED to an port on a microcomputer will cause damage. The greatest care must be taken to ensure the limits of current are not exceeded. Permanent damage will occur.
dir Porta.0 out
#define LED1 Porta.0
InitTimer2 Osc, PS2_1/64
StartTimer 2
On Interrupt Timer2Match Call handleEvent
' Power control to the LED. set the Bit LED1 to the Compliment of LED1 SetWith( LED1, FnNotBIT( LED1) )'Invert the delay if currentState = ledOff then PR2 = ledOn currentState = ledOn else currentState = ledOff PR2 = ledOff end if
End Sub
~~~~
The attachment shows the current usage and the scope profile for the variable softwarePWM being set to 10 and 100. Left hand meter is LED current and the right hand meter the overall current usage. The scope is the effective PWM of the LED.
Howdy all,
https://www.wayneandlayne.com/projects/metronome/
I'm working with a small project that will require using a multiplexed 3 X 7 Segment LED display, there aren't any ballast resistors on the LED segments, so the ideas is to touch them so fleetingly that they do not consume too much current at any on time.
When you look at the source code of this device and similar arrangments, there is usually a interrupt service routiune that handles segment/display managent and other associated timing responsabilities, as a background task of the main program logic.
Does any one have any experience on how to do this in Great Cow Basic, or perhaps some example code to share?
Best,
Randy
Last edit: Randall Young 2015-10-09
Are you asking for a port on the exiting code? or, are you doing this already? see
We have a number of example of handling interrupts in the Help File. Also, I can let you have a pre-release version of the next release to ease the handling of the interrupts and the driving those LEDs.
So, I think the question is. What is the ask in terms of example code?
What Anobium says. Also having the micro used and what type of 3 digit 7 segment display (common anode or cathode) helps also.
Help has examples of a three digit multiplex display already, just not using interrupts. I am currently using (4) 4 digit multiplexed displays in a project. Not using the standard 7 segment library per se, nor using the timer interrupt for the displays. But, using the TMR1Overflow interrupt to schedule certain events.
This is the goto link on how to setup a Timer overflow interrupt to a fixed time base https://sourceforge.net/p/gcbasic/discussion/579125/thread/03348d5c/#6c76/281f
I would try for a 100us timeroverflow and adjust from there. I am using on times of 40us before changing digits, but am also using 'HC595's" to do the switching. The HC595's can get kinda hot, as only using 10 ohm resistors.
So,
1) Set up timer overflow interrupt to specified time base
2) Set up the counter in the called interrupt sub to advance the digits use conditional if's or select case.
Based off the Help examples the timer setup and interrupt sub might look something like this (Note, the timebase in this example is for 100ms interrupt):
I had a look at the source web page and the source code. It may be simpler, I hate to say this, but, use the compiler they recommend.
There may be a really good justification, that I am not aware of, to port. Then, we are here for you! :-)
Meanwhile, here is a piece of code to show a development of Kent's approach. This will required v0.95 of the GCB but this draws less than 1ma when at the lowest setting and 9ma at the highest setting for the variable softwarePWM. I have set limits to softwarePWM to ensure I did not draw to much current from the the port. I tested on constant current PSU, a scope and two meters. See the note below. This is essentially the power control is that very large piece of code on the source web site.
Note to readers: Connecting an LED to the output port, or, sinking an LED to an port on a microcomputer will cause damage. The greatest care must be taken to ensure the limits of current are not exceeded. Permanent damage will occur.
Anobium
~~~~~
'This program switch the LED on and off every time Timer2 matchs PR2
#chip 10f320, 16
'Connecting an LED to the output port, or, sinking an LED to an port on a microcomputer will cause damage. The greatest care must be taken to ensure the limits of current are not exceeded. Permanent damage will occur.
dir Porta.0 out
#define LED1 Porta.0
InitTimer2 Osc, PS2_1/64
StartTimer 2
On Interrupt Timer2Match Call handleEvent
Do
Wait 200 ms
' Do stuff
Loop
End
Sub handleEvent
End Sub
~~~~
The attachment shows the current usage and the scope profile for the variable softwarePWM being set to 10 and 100. Left hand meter is LED current and the right hand meter the overall current usage. The scope is the effective PWM of the LED.
Last edit: Anobium 2015-10-10
Thanks all!
R.