count=0
main:
do while Button =0
count=count+1
loop
goto main
Not sure exactly what you're trying to do, but you need to set the port/pin assignment and say whether its an input or output. Also may be some confusion going on with the variable count, so why not name the port/pin something else?
Kent
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hugh, I have understood the syntax and now all is working well.
Kent, I don't want to read a button on an input, but I want to test when a bit of the register TMR0 change its value. I use it as a fake interupt on a pic without interupt.
stefano
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Kent, I will try to explain you what I would like to do, but please remember two things, english isn't my language and, I am not a skilled programmer, I only enjoy myself to do very simple things using Pics.
TMR0 is the register of Timer0 module inside the pic. You can write or read the register TMR0 using GCbasic, for example the instruction TMR0=0 clears the register TMR0.
the following code is my first tentative to do a pwm modulation, I know that there are Pics that have the possibility of pwm but I want to try to pwm without use this possibility. At the moment I have only a square wave at portb.0 with a fixed duty cycle of 10%.
When I detect that the bit tmr0.7 has change its value (0 --> 1) I execute some code , but pay attention the time for execution has to be less of the time used for tmr0 to reach the cahnge of state of tmr0.7. In my code this takes place every 136 us. Of course this time could be changed.
5 complete counts of tmr0 produce ton, and the others 45 complete count of tmr0 produce toff.
An other thing 16F84A has the possibility of interupts, I don't use this possibility because I further would like to use this code in pics without interupt module.
DIR PORTA b'11111111' 'PORTA as input
DIR PORTB b'11111110' 'PORTB as output
OPTION_REG=b'00001000'
clrf INTCON
status_on=1
ton=0
set portb.0 on
Main:
lbl01:
do while tmr0.7 OFF
loop
tmr0=0
if status_on=0 then goto out_off
ton=ton+1
if ton=5 then goto lbl02 '<- 5 ton
goto lbl01
lbl02:
toff=0
status_on=0
set portb.0 off
out_off:
toff=toff+1
if toff=45 then goto lbl03 '<- 45 toff
goto lbl01
lbl03:
status_on=1
set portb.0 on
ton=0
goto lbl01
goto Main
--------------------------------------
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Stefanodel, thank you for sharing your code. You have answered my question about how to use TMR0.
Since I've got the blinking LED's going, it is probably time to start thinking about turning some hobby motors. So your example of a software PWM is one way to go. Or maybe use the hardware PWM of TMR2 first, just to get familiar.
I have no background in software, so the programming rules and syntax are slow in coming to me.
Regards,
Kent
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Kent, my point of view is to try both the solution, in order to understand how to use a microcontroller and how to write firmware.
To drive electrical motors is a good exercise, software and hardware.
My advise is to to begin with a simple circuit, for example the dc-motor connect between the collector and the power supply (remember to use the freeweeling diode) and then a full bridge circuit, and so on.
If you take apart printers, old floppy drivers(5-inch), hard disks, you can find stepper motors. Also to drive a stepper is a good exercise.
Hardware is more familiar for me than firmware.
stefano
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried the following simple code:
#chip 16F84A, 4
#mem 68
count=0
main:
do while count.2=0
count=count+1
loop
goto main
When I try to compile I get the following message in the dos window:
Illegal function call in module GCB_SUBS at address 1F7A:6AFD
Hit any key to return to system
I don't know if I make a mistake to use a bit (count.2) as the test condition in the while loop.
It is possible to do this?
Thank You very much
stefano
Wouldn't you use something like:
#chip 16F84A, 4
#mem 68
#define Button PortB.2
dir PortB.2 output
count=0
main:
do while Button =0
count=count+1
loop
goto main
Not sure exactly what you're trying to do, but you need to set the port/pin assignment and say whether its an input or output. Also may be some confusion going on with the variable count, so why not name the port/pin something else?
Kent
When checking individual bits, you need to use ON and OFF rather than = 1 and = 0. The do while needs to be like this:
do while count.2 off
I've had a few other people say to me offline that this is confusing, so I'll make =0 and =1 valid in the next version of GCBASIC.
thank you for your answers.
Hugh, I have understood the syntax and now all is working well.
Kent, I don't want to read a button on an input, but I want to test when a bit of the register TMR0 change its value. I use it as a fake interupt on a pic without interupt.
stefano
Aha. How is the TMR0 (or for that matter TMR1, TMR2) register tied to Count in your program or GCBASIC in general? Or is this done in assembly?
Can you just use, #define Count TMRO? And then inherently have access to all 8 bits ( or 16 bits for TMR1).
Thanks,
Kent
Hi Kent, I will try to explain you what I would like to do, but please remember two things, english isn't my language and, I am not a skilled programmer, I only enjoy myself to do very simple things using Pics.
TMR0 is the register of Timer0 module inside the pic. You can write or read the register TMR0 using GCbasic, for example the instruction TMR0=0 clears the register TMR0.
the following code is my first tentative to do a pwm modulation, I know that there are Pics that have the possibility of pwm but I want to try to pwm without use this possibility. At the moment I have only a square wave at portb.0 with a fixed duty cycle of 10%.
When I detect that the bit tmr0.7 has change its value (0 --> 1) I execute some code , but pay attention the time for execution has to be less of the time used for tmr0 to reach the cahnge of state of tmr0.7. In my code this takes place every 136 us. Of course this time could be changed.
5 complete counts of tmr0 produce ton, and the others 45 complete count of tmr0 produce toff.
An other thing 16F84A has the possibility of interupts, I don't use this possibility because I further would like to use this code in pics without interupt module.
stefano
--------------------------------
'square wave ton=5 toff=45
#chip 16F84A, 4
#mem 68
#CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
DIR PORTA b'11111111' 'PORTA as input
DIR PORTB b'11111110' 'PORTB as output
OPTION_REG=b'00001000'
clrf INTCON
status_on=1
ton=0
set portb.0 on
Main:
lbl01:
do while tmr0.7 OFF
loop
tmr0=0
if status_on=0 then goto out_off
ton=ton+1
if ton=5 then goto lbl02 '<- 5 ton
goto lbl01
lbl02:
toff=0
status_on=0
set portb.0 off
out_off:
toff=toff+1
if toff=45 then goto lbl03 '<- 45 toff
goto lbl01
lbl03:
status_on=1
set portb.0 on
ton=0
goto lbl01
goto Main
--------------------------------------
Stefanodel, thank you for sharing your code. You have answered my question about how to use TMR0.
Since I've got the blinking LED's going, it is probably time to start thinking about turning some hobby motors. So your example of a software PWM is one way to go. Or maybe use the hardware PWM of TMR2 first, just to get familiar.
I have no background in software, so the programming rules and syntax are slow in coming to me.
Regards,
Kent
Hi Kent, my point of view is to try both the solution, in order to understand how to use a microcontroller and how to write firmware.
To drive electrical motors is a good exercise, software and hardware.
My advise is to to begin with a simple circuit, for example the dc-motor connect between the collector and the power supply (remember to use the freeweeling diode) and then a full bridge circuit, and so on.
If you take apart printers, old floppy drivers(5-inch), hard disks, you can find stepper motors. Also to drive a stepper is a good exercise.
Hardware is more familiar for me than firmware.
stefano