For a frequency counter, I need to display large numbers (>65535) on an lcd. Problem is that the frequency is greater than a word. If I use TMR0 as a oscillator and TMR1 as the actual counter, I will need to count the number of times TMR1 overflows (in the variable overflow) and the remainder in the variable "raw". When I go to display the frequency, I use print (61*(raw + (overflow*65536)), but the data is never displayed correctly. Also, the 61 is to make up for the prescaler. Here is the actual program:
Perhaps I should narrow the question. If I have two words, one is the overflow of TMR1 and the other is the remainder. Since the actual frequency is (overflow*65536+remainder) and then this is multiplied by a specific factor to obtain the actual frequency per second and not the frequency per 10th of a second is equal to a number over 65535, I cannot print this value on an LCD. If I print a sum of two variables over 65536, the LCD does not print. I need a method to circumvent this issue.
Any Suggestions?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What you are trying to do is beyond the scope of Gcbasic as it stands.
Essentially you are trying to print a value > 16 bits , which is normally termed a long variable.
It would be possible to write a routine in Gcbasic to do this , given an input of 2 , 16 bit variables, but in the constrained
memory of a 16F628 pretty unlikley the code would fit.
If you have a look at the code in lcd.h , you can see how it works for word variables.
Its not too hard to extend the print routine to long variables.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For a frequency counter, I need to display large numbers (>65535) on an lcd. Problem is that the frequency is greater than a word. If I use TMR0 as a oscillator and TMR1 as the actual counter, I will need to count the number of times TMR1 overflows (in the variable overflow) and the remainder in the variable "raw". When I go to display the frequency, I use print (61*(raw + (overflow*65536)), but the data is never displayed correctly. Also, the 61 is to make up for the prescaler. Here is the actual program:
#chip 16f628A, 4
#config osc = int
#define LCD_IO 4
#define LCD_DB7 PORTA.1
#define LCD_DB6 PORTA.0
#define LCD_DB5 PORTA.7
#define LCD_DB4 PORTA.6
#define LCD_Enable PORTB.7
#define LCD_RW PORTB.4
#define LCD_RS PORTB.5
on interrupt Timer1overflow call T1Overflow
on interrupt Timer0overflow call Calc
dir portb.6 in
dim raw as word
dim overflow as word
inittimer0 osc, PS0_1/64
inittimer1 ext, PS1_1/1
cleartimer 0
cleartimer 1
starttimer 0
starttimer 1
overflow = 0
raw = 0
MAIN:
wait 2 s
goto MAIN
sub T1Overflow
overflow = overflow + 1
end sub
sub calc
intoff
stoptimer 1
raw = TMR1L
raw_h = TMR1H
print (61*(raw + (overflow*65535)))
wait 100 ms
raw = 0
overflow = 0
cls
cleartimer 1
cleartimer 0
starttimer 1
inton
end sub
Any help relating to displaying large numbers or frequency counting would be helpful.
Perhaps I should narrow the question. If I have two words, one is the overflow of TMR1 and the other is the remainder. Since the actual frequency is (overflow*65536+remainder) and then this is multiplied by a specific factor to obtain the actual frequency per second and not the frequency per 10th of a second is equal to a number over 65535, I cannot print this value on an LCD. If I print a sum of two variables over 65536, the LCD does not print. I need a method to circumvent this issue.
Any Suggestions?
What you are trying to do is beyond the scope of Gcbasic as it stands.
Essentially you are trying to print a value > 16 bits , which is normally termed a long variable.
It would be possible to write a routine in Gcbasic to do this , given an input of 2 , 16 bit variables, but in the constrained
memory of a 16F628 pretty unlikley the code would fit.
If you have a look at the code in lcd.h , you can see how it works for word variables.
Its not too hard to extend the print routine to long variables.