Hi Experts .........(flattery is always a good start!) I have had some really good fun since I started with GC Basic. I've made many gadgets, and some timer/pulse generators for my electric control-line model planes. I've even managed to use a feedback loop for a constant speed circuit, but now I need a finer control. I can only resolve 100 rpm and I need to improve it. I'm using the PIC 12F675 with the basic servo loop program as below:
Dir ServoPin Out
Do
For Temp = ServoMin to ServoMax
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
For Temp = ServoMax to ServoMin
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
Loop
This works, but each step is 1 times 10 micro seconds, so the smallest increment of 10 us divides the 1 ms servo movement (1.0 to 2.0 ms) into 100 steps. I thought that I would make a real fine resolution of 1000 steps by using the number 1000 multiplied by 1 us. I soon found when I compiled the program that I need a 20 MHz clock, so I got hold of some 20 MHz crystals with some caps as per the data sheet. The PIC works this way, but then I can't seem to make the servo work. Here is my program:
Dir ServoPin Out
Do
For Temp = ServoMin to ServoMax
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
For Temp = ServoMax to ServoMin
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
Loop
When I try to run this, then the servo just runs to the short pulse width side. Is my program wrong? The other thing is that when I remove the space from "Temp 10 us" and type it as "Temp 10us" then a warning comes up when I compile, that says " Current chip does not have enough common (non-banked) RAM, and also that the Delay units are not specified."
What does this all mean? Can I use this PIC to make such fine resolution? Thanks very much.
Keith R
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think you should have
#config OSC=HS
I would also be tempted to swich off the wdt and mclre.
This works for me
#chip 12F675, 20
#config OSC=HS, MCLRE=OFF, WDT=OFF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I did in fact change the speed. I just cut & pasted the wrong section. It reads:
#chip 12F675, 20
#config Osc = HS
Here it as modified:
'PIC 12F675 Servo cycler with 20 MHz clock
#chip 12F675, 20
#config OSC=HS, MCLRE=OFF, WDT=OFF
#define ServoPin GPIO.1
Dim PW as word
Dir ServoPin Out
Do
For PW = 1000 to 2000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
For PW = 2000 to 1000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
Loop
I tried what you suggested but still does not compile unless I put the space back after the PW, 10us. I changed the "temp" for PW or pulse width to make more sense to me.
Keith R
'PIC 12F675 Servo cycler with 20 MHz clock
#chip 12F675, 20
#config OSC=HS, MCLRE=OFF, WDT=OFF
#define ServoPin GPIO.1
Dim PW as word
Dir ServoPin Out
Do
For PW = 1000 to 2000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
For PW = 2000 to 1000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
O.K. I've checked this out on my scope now, and it looks as if GC Basic does not accept anything under 10 us. Maybe Hugh or Kent can confirm this? Thanks.
Keith R
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi David, Thanks for that. I just managed to see what the problem is after trying many frustrating things and looking at the pulse with my scope. It is the "1" in front of us that is my problem. I always used 10us because the 4 MHz clock could not go any faster. Once I got the 20 MHz clock running, I reduced the 10 to a 1 instead of just leaving it out. Anyway, now it's working fine........if you'll excuse the pun! Now I can get back to my constant speed governor thing. Thanks so much.
Keith R
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Experts .........(flattery is always a good start!) I have had some really good fun since I started with GC Basic. I've made many gadgets, and some timer/pulse generators for my electric control-line model planes. I've even managed to use a feedback loop for a constant speed circuit, but now I need a finer control. I can only resolve 100 rpm and I need to improve it. I'm using the PIC 12F675 with the basic servo loop program as below:
'PIC 12F675 Servo cycler
#chip 12F675, 4
#config Osc = Int
#define ServoPin GPIO.1
#define ServoMin 100
#define ServoMax 200
Dir ServoPin Out
Do
For Temp = ServoMin to ServoMax
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
For Temp = ServoMax to ServoMin
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
Loop
This works, but each step is 1 times 10 micro seconds, so the smallest increment of 10 us divides the 1 ms servo movement (1.0 to 2.0 ms) into 100 steps. I thought that I would make a real fine resolution of 1000 steps by using the number 1000 multiplied by 1 us. I soon found when I compiled the program that I need a 20 MHz clock, so I got hold of some 20 MHz crystals with some caps as per the data sheet. The PIC works this way, but then I can't seem to make the servo work. Here is my program:
'PIC 12F675 Servo cycler
#chip 12F675, 4
#config Osc = Int
#define ServoPin GPIO.1
#define ServoMin 100
#define ServoMax 200
Dir ServoPin Out
Do
For Temp = ServoMin to ServoMax
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
For Temp = ServoMax to ServoMin
PulseOut ServoPin, Temp 10us
Wait 20 ms
Next
Loop
When I try to run this, then the servo just runs to the short pulse width side. Is my program wrong? The other thing is that when I remove the space from "Temp 10 us" and type it as "Temp 10us" then a warning comes up when I compile, that says " Current chip does not have enough common (non-banked) RAM, and also that the Delay units are not specified."
What does this all mean? Can I use this PIC to make such fine resolution? Thanks very much.
Keith R
You changed the clock frequency from 4MHz to 20MHz, so I think this: "#chip 12F675, 4" should really be this: "#chip 12F675, 20".
Joe
I think you should have
#config OSC=HS
I would also be tempted to swich off the wdt and mclre.
This works for me
#chip 12F675, 20
#config OSC=HS, MCLRE=OFF, WDT=OFF
Oops....sorry guys,
I did in fact change the speed. I just cut & pasted the wrong section. It reads:
#chip 12F675, 20
#config Osc = HS
Here it as modified:
'PIC 12F675 Servo cycler with 20 MHz clock
#chip 12F675, 20
#config OSC=HS, MCLRE=OFF, WDT=OFF
#define ServoPin GPIO.1
Dim PW as word
Dir ServoPin Out
Do
For PW = 1000 to 2000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
For PW = 2000 to 1000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
Loop
I tried what you suggested but still does not compile unless I put the space back after the PW, 10us. I changed the "temp" for PW or pulse width to make more sense to me.
Keith R
'PIC 12F675 Servo cycler with 20 MHz clock
#chip 12F675, 20
#config OSC=HS, MCLRE=OFF, WDT=OFF
#define ServoPin GPIO.1
Dim PW as word
Dir ServoPin Out
Do
For PW = 1000 to 2000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
For PW = 2000 to 1000
PulseOut ServoPin, PW 1us
Wait 20 ms
Next
Loop
O.K. I've checked this out on my scope now, and it looks as if GC Basic does not accept anything under 10 us. Maybe Hugh or Kent can confirm this? Thanks.
Keith R
Well what you could do instead is...
for pw=2000 to 1000 step -1
set servopin on
wait pw us
set servopin off
wait 20 ms
next pw
Hi David, Thanks for that. I just managed to see what the problem is after trying many frustrating things and looking at the pulse with my scope. It is the "1" in front of us that is my problem. I always used 10us because the 4 MHz clock could not go any faster. Once I got the 20 MHz clock running, I reduced the 10 to a 1 instead of just leaving it out. Anyway, now it's working fine........if you'll excuse the pun! Now I can get back to my constant speed governor thing. Thanks so much.
Keith R