First it wouldn't compile with the dash infront of the "-#define GLOW_LED GPIO.2".
Also GCB knows where the Libraries are. You don't need "-#include "F:\GCB@Syn_029\GreatCowBasic\include\lowlevel\timer.h""
In a previous post you thought you were getting 3ms but i don't see that.
Timer1 is incremented on every instruction cycle, 4mhz/4 = 1mhz or 1 usec
"InitTimer1 Osc, PS1_1/2" says divide by 2 (500000hertz) or 2usec for timer1 increment.
You set the timer at a min of 165 so and the timer is a 16 bit timer and you are counting UP.
So 65536-165= 65371 * .000002 sec = 0.130742 sec
You set the timer at a max of 1000 so and the timer is a 16 bit timer and you are counting UP.
So 65536-1000= 64536 * .000002 sec = 0.129072 sec
Also you shouldn't redefine Keywords , "Dim GPIO As byte".. But i left it in and it worked ok with it though i would take it out.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi mmotte
1. The dash is only for the forum. If I don't write the dash I'm geting a text like this in attachement. Of course I don't use it in my real code
2. If I don't include the header I don't have the GCB timer routines available, I have then start and stop the timer1 via their general variables
3. Please reread my previus post, it has to do with the wait instruction not with the timer1
4. Can anyone compile this with PIC12F675 to see what is going on?
thank you
You don't need "-#include "F:\GCB@Syn_029\GreatCowBasic\include\lowlevel\timer.h"" if you are running the IDE from the "F:\GCB@Syn_029". I have the feeling you are missing some other Libraries too and that is why it isn't running.
It did run on the 12F683.
I'm sorry i missed the point of your preveious post on the "wait" command. David told you exactly why that was off at low values with the program clock at 1 usec you can't do much else in 3 usec.
Look at your install.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please tell tell us the final application and exacty what it is you want your code to do.
I took the liberty to correct and make changes to your posted code based upon what I "think" you are trying to do. Take a careful look at the comments I added to the code.
'Chip Settings
#chip 12F675,4
'//unnecessary
'#include "F:\GCB@Syn_029\GreatCowBasic\include\lowlevel\timer.h"
;Defines (Constants)
#define GLOW_LED GPIO.2
;Variables
'Dim flag As integer '// unused
Dim pulsew As word
'Dim GPIO As byte '// Do not us "GPIO" as avariable
'Dim gen_counter As byte '//Unused
Dir GLOW_LED Out
'pulsew = 165 '//Unused
'gen_counter = 20 '//Unused
'flag = 0 '//Unused
InitTimer1 Osc, PS1_1 '//Changed to 1:1 (1 timer tick = 1 us)
Starttimer 1 '// Added
' ** Note There is no need to start/stop timer.
' ** Timer can be cleared "on-the-fly"
'ClearTimer 1 '// unnecessary
'TMR1IF = 0 '// Unnecessary
'TMR1IE = on '// Unnecessary
' '// TMR1IF will set anyway
'
' --- Main Loop ---
DO
' wait 10 ms
' pulsew = pulsew + flag
' flag = flag + 1
'
' if pulsew > 1000 then
' pulsew = 165
' flag = 0
' end if
' PULSE_OUT_US (pulsew)
'-------------------------------------------
'*** A more efficient way to do the same
Pulsew = 165 '// start at 165
Do while Pulsew <= 1000
Wait 10 ms
Pulsew ++ '// increment by 1
PULSE_OUT_US (pulsew)
Loop
Loop
Sub PULSE_OUT_US (In TimerVal As word)
TMR1IF = 0 '// Clear the flag here
SetTimer 1, (65535 - TimerVal) '// Timer counts up not down
'StartTimer 1 '//Unnecessary
Set GLOW_LED ON
Do While TMR1IF = 0
'Wait for Timer1 overflow
Loop
Set GLOW_LED off
'StopTimer 1 '// Unnucessary
'TMR1IF = 0 '// Unnecessary
'ClearTimer 1 '// Unnecessary
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is the cleaned up code. If this does not generate pulses from 165 us to 1000 us then let up know and we will investige further. This works fine on PIC12F683 and should work fine on 12F675.
And again please. let us know what you are trying to accomplish. Is this just to dim an LED? Or is it for something else?
Code:
;Chip Settings
#chip 12F675,4
;Defines (Constants)
#define GLOW_LED GPIO.2
Dim pulsew As word
Dir GlOW_LED Out
InitTimer1 Osc, PS1_1 '1 timer count = 1us
Starttimer 1
; --- Main Loop ---
Do
For Pulsew = 165 to 1000 ' 165us to 1000us
Pulse_OUT_US Pulsew
Wait 20 ms
next
Loop
Sub PULSE_OUT_US (In TimerVal As word)
TMR1IF = 0 'clear the flag here
SetTimer 1, (65535 - TimerVal) 'set on-the-fly
Set GLOW_LED ON
Do While TMR1IF = 0
'Wait for Timer1 overflow
Loop
Set GLOW_LED off
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the following code the output pin GLOW_LED should have some pulses outgoing but nothing happens. Any suggestions?
;Chip Settings
-#chip 12F675,4
;Include files (Libraries)
-#include "F:\GCB@Syn_029\GreatCowBasic\include\lowlevel\timer.h"
;Defines (Constants)
-#define GLOW_LED GPIO.2
;Variables
Dim flag As integer
Dim pulsew As word
Dim GPIO As byte
Dim gen_counter As byte
Dir GLOW_LED Out
pulsew = 165
gen_counter = 20
flag = 0
InitTimer1 Osc, PS1_1/2
ClearTimer 1
TMR1IF = 0
TMR1IE = on
redo:
wait 10 ms
pulsew = pulsew + flag
flag = flag + 1
if pulsew > 1000 then
pulsew = 165
flag = 0
end if
PULSE_OUT_US (pulsew)
goto redo
Sub PULSE_OUT_US (In Variable As word)
SetTimer 1, Variable
StartTimer 1
Set GLOW_LED ON
Do While TMR1IF = 0
End Sub
Last edit: sfyris 2016-01-28
I tried it on a 12f683 and it gives pulses.
First it wouldn't compile with the dash infront of the "-#define GLOW_LED GPIO.2".
Also GCB knows where the Libraries are. You don't need "-#include "F:\GCB@Syn_029\GreatCowBasic\include\lowlevel\timer.h""
In a previous post you thought you were getting 3ms but i don't see that.
Timer1 is incremented on every instruction cycle, 4mhz/4 = 1mhz or 1 usec
"InitTimer1 Osc, PS1_1/2" says divide by 2 (500000hertz) or 2usec for timer1 increment.
You set the timer at a min of 165 so and the timer is a 16 bit timer and you are counting UP.
So 65536-165= 65371 * .000002 sec = 0.130742 sec
You set the timer at a max of 1000 so and the timer is a 16 bit timer and you are counting UP.
So 65536-1000= 64536 * .000002 sec = 0.129072 sec
Also you shouldn't redefine Keywords , "Dim GPIO As byte".. But i left it in and it worked ok with it though i would take it out.
Hi mmotte
1. The dash is only for the forum. If I don't write the dash I'm geting a text like this in attachement. Of course I don't use it in my real code
2. If I don't include the header I don't have the GCB timer routines available, I have then start and stop the timer1 via their general variables
3. Please reread my previus post, it has to do with the wait instruction not with the timer1
4. Can anyone compile this with PIC12F675 to see what is going on?
thank you
Last edit: sfyris 2016-01-28
You don't need "-#include "F:\GCB@Syn_029\GreatCowBasic\include\lowlevel\timer.h"" if you are running the IDE from the "F:\GCB@Syn_029". I have the feeling you are missing some other Libraries too and that is why it isn't running.
It did run on the 12F683.
I'm sorry i missed the point of your preveious post on the "wait" command. David told you exactly why that was off at low values with the program clock at 1 usec you can't do much else in 3 usec.
Look at your install.
Hi sfyris.
Please tell tell us the final application and exacty what it is you want your code to do.
I took the liberty to correct and make changes to your posted code based upon what I "think" you are trying to do. Take a careful look at the comments I added to the code.
Here is the cleaned up code. If this does not generate pulses from 165 us to 1000 us then let up know and we will investige further. This works fine on PIC12F683 and should work fine on 12F675.
And again please. let us know what you are trying to accomplish. Is this just to dim an LED? Or is it for something else?
Code: