Hi , how can i use timer 4/6 and their interrupts ? It doesn't seems to be implemented in GCB . In file timer.h i could add this timers but i don't know how to add interrupts
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I use PIC16F1936 as in my post title. It has Timer0 , 1 , 2 , 4 and 6. Only Timer0 , 1 and 2 are implemented for PIC microcontrollers in GCB. For the rest you must use manual register settings. I figured out from help file how to use Timer4 / 6 interrupts by creating a subrutine called "interrupts" for all interrupts and manually checking interrupts flags .
So my problem is solved for now ... but it would be nice to improve GCB by adding all available timers and interrupts
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi , i use last GCB stable release ,i think, that i downloaded from official site http://gcbasic.sourceforge.net/ Intermediate and Advanced GCB@Syn.zip 25/05/2014
All files including timer.h are from that release , i didn't used GCB before
Last edit: Daniel Cioba 2014-10-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I modified the example code code in the help file to use PIC16F1936, timer4, and interrupt on timer4 overflow. It compiles fine. HOwever I don have the Chip to test. Here is the code. I am using Timer.h from the code repository dated 2014-08-23.
~~~~~
chip 16F1936, 8
config osc = int
define MOTOR PORTB.0
'Call the initialisation routine
InitMotorControl
'Main routine
Do
'Increase speed to full over 2.5 seconds
For Speed = 0 to 100
MotorSpeed = Speed
Wait 25 ms
Next
'Hold speed
Wait 1 s
'Decrease speed to zero over 2.5 seconds
For Speed = 100 to 0
MotorSpeed = Speed
Wait 25 ms
Next
'Hold speed
Wait 1 s
Loop
'Add a handler for the interrupt
On Interrupt Timer4Overflow Call PWMHandler
'Set up the timer
InitTimer4 Osc, PS0_2
'Timer 0 starts automatically on a PIC
End Sub
'PWM sub
'This will be called when Timer 4 overflows
Sub PWMHandler
If MotorSpeed > PWMCounter Then
Set MOTOR On
Else
Set MOTOR Off
End If
PWMCounter += 1
If PWMCounter = 100 Then PWMCounter = 0
End Sub
~~~~~~
Last edit: William Roth 2014-10-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@William. On Interrupt Timer6Overflow Call {method} will not compile, but, of course On Interrupt Timer6Match Call {method} will. Constraints of the chip can be removed. :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi , how can i use timer 4/6 and their interrupts ? It doesn't seems to be implemented in GCB . In file timer.h i could add this timers but i don't know how to add interrupts
Hi Daniel,
As I read the help file under Timers/Timer Overview there are functions for timer0 through timer5.
As far as interrupts go you can refer to the help file under Interrupts/ON Interrupt and see that Timer0 = Timer5 are supported.
What PIC are you using ?
Last edit: William Roth 2014-10-16
I use PIC16F1936 as in my post title. It has Timer0 , 1 , 2 , 4 and 6. Only Timer0 , 1 and 2 are implemented for PIC microcontrollers in GCB. For the rest you must use manual register settings. I figured out from help file how to use Timer4 / 6 interrupts by creating a subrutine called "interrupts" for all interrupts and manually checking interrupts flags .
So my problem is solved for now ... but it would be nice to improve GCB by adding all available timers and interrupts
Hi, what release of GCB are your using? The date of the timer.h would also be useful.
Thank you.
Anobium
Hi , i use last GCB stable release ,i think, that i downloaded from official site http://gcbasic.sourceforge.net/ Intermediate and Advanced GCB@Syn.zip 25/05/2014
All files including timer.h are from that release , i didn't used GCB before
Last edit: Daniel Cioba 2014-10-16
I modified the example code code in the help file to use PIC16F1936, timer4, and interrupt on timer4 overflow. It compiles fine. HOwever I don have the Chip to test. Here is the code. I am using Timer.h from the code repository dated 2014-08-23.
~~~~~
chip 16F1936, 8
config osc = int
define MOTOR PORTB.0
'Call the initialisation routine
InitMotorControl
'Main routine
Do
'Increase speed to full over 2.5 seconds
For Speed = 0 to 100
MotorSpeed = Speed
Wait 25 ms
Next
'Hold speed
Wait 1 s
'Decrease speed to zero over 2.5 seconds
For Speed = 100 to 0
MotorSpeed = Speed
Wait 25 ms
Next
'Hold speed
Wait 1 s
Loop
'Setup routine
Sub InitMotorControl
'Clear variables
MotorSpeed = 0
PWMCounter = 0
End Sub
'PWM sub
'This will be called when Timer 4 overflows
Sub PWMHandler
If MotorSpeed > PWMCounter Then
Set MOTOR On
Else
Set MOTOR Off
End If
PWMCounter += 1
If PWMCounter = 100 Then PWMCounter = 0
End Sub
~~~~~~
Last edit: William Roth 2014-10-16
Sorry , i made a mistake , Timer4 is working fine , only Timer6 is not
Compiler error at InitTimer6 ... and On Interrupt Timer6Overflow ...
Other question , timers2/4/6 all have a prescaler and a postscaler , it is possible to set the postscaler value ? InitTimer0 source, prescaler
Last edit: Daniel Cioba 2014-10-16
I have just updated Timer.h. I have asked Hugh to complete a code review. I will post when completed.
Revised file now additionally supports:
Anobium
Last edit: Anobium 2014-10-16
So the problem is restricted to timer6?
Looking at Timer.h, it seems that timer6 is not implemented. Also according to the 16F1936.dat file, only "On Interrupt timer6match is supported."
Anobium is on top of it.
What about the 16F1936 dat file [Interrupt] that does not support timer6 overflow? There will still be a syntax error if this is not remedied.
Last edit: William Roth 2014-10-16
@William. On Interrupt Timer6Overflow Call {method} will not compile, but, of course On Interrupt Timer6Match Call {method} will. Constraints of the chip can be removed. :-)
@All. I have just posted an updated timer.h.
Please see https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/timer.h
This will be part of the next release of GCB and GCGB.
This has all the normal commands for timers, plus the following scalers.
~~~~~
Timer 4 prescales
PS4_1/1
PS4_1/4
PS4_1/16
PS4_1/64
PS4_1
PS4_4
PS4_16
PS4_64
Timer 6 prescales
PS6_1/1
PS6_1/4
PS6_1/16
PS6_1/64
PS6_1
PS6_4
PS6_16
PS6_64