I have a DC-motor that has a Hall sensor attached to its spindle.
I want to use the signal from the sensor to stabilize the motor to the speed set by the potentiometer.
I need speeds from 240 to 6000 rpm. At these spindle speeds the sensor gives pulses from 130 to 5 mSec.
The value from the potentiometer goes from 0 to 255. The formula "SetSpeed = (255-ReadAD(An3))/2" converts this to 127 to 0 which is close enough.
In the loop the pulse width will be adjusted until SensorSpeed is same as SetSpeed.
#chip12F1840
#defineMotorPORTA.2
#definePotmeterPORTA.4
#defineLED3PORTA.5
#defineLED5PORTA.1
#defineSensorPORTA.0dirPotmeterIndirLED3OutdirLED5OutdirMotorOutdirSensorIndimSetSpeedasBytedimCurrentSpeedasBytedimSensorSpeedasWORD'Pin1 5V - pickit p2'Pin2 A5 - LED3'Pin3 A4 - (An3) POTMETER'Pin4 A3 - pickit p1'Pin5 A2 - (CCP1) PWM MOTOR'Pin6 A1 - pickit p5, LED5'Pin7 A0 - pickit p4, Sensor'Pin8 0V - pickit p3'LED A5 (pin2)'Potmeter A4 (pin3)'PWM output A2 (HPWM Channel1 = CCP1 = RA2 = Pin5)'POST repeat 5 PulseOut LED3, 50 ms PulseOut LED5, 50 ms Wait 100 ms end Repeat'Initializing Motor = 1 CurrentSpeed = 178' HPWM 1,10,255-readAD(An3) HPWM 1,10,CurrentSpeed wait 5 s'Main do SetSpeed = (255-ReadAD(An3))/2'wait for rising edge do while Sensor=off Loop PulseIn Sensor, SensorSpeed, ms if SensorSpeed < SetSpeed Then CurrentSpeed = CurrentSpeed +1 PulseOut LED5, 25 ms wait 100 ms end if if SensorSpeed > SetSpeed Then CurrentSpeed = CurrentSpeed -1 PulseOut LED3, 25 ms wait 100 ms end if HPWM 1, 10,CurrentSpeed Loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Which port do have the serial device connected to?
What is connection? The device type. Does it have an inverted serial line?
Please add the chip the desired clock frequency.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
#chip12F1840
#defineLEDPORTA.1
#defineRS232OUTPORTA.5'Config Software-UART #define SendAHigh Set RS232Out ON #define SendALow Set RS232Out OFF set RS232Out On'Set up serial connection InitSer 1, r2400, 1 + WaitForStart, 8, 1, none, invertwait 1 sSerPrint 1, "test text"doloop
Last edit: JohanDenRidder 2018-01-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tried clock frequencies from 4 to 32 MHZ with command #chip 12F1840, 16
It made no difference.
The LCD does print something, but it doesn't make no sense.
About the polarity, I am not sure if it is inverted, but the LCD works ok on a Picaxe pin using "serout".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your solution prints 4 characters at a time, but they don't make sense.
The Picaxe display is 2400 baud, so I changed 'define USART_BAUD_RATE 9600' to
2400. The display now shows 10 characters at a time.
I tried HSerPrint "AAAAAAAAAA" to see if the characters would be all the same, but they weren't,
But the are the same at every loop though.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is it a serial oled? http://www.picaxe.com/docs/axe133.pdf
Looks like normal 4bit display.
At least Johan got 10 chars to display. Did it ever work with picaxe?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I set up a Picaxe with the display and that worked normally.
Then I hooked up a logic analyzer feeling a bit stupid that I haven't done so right away. One channel on the Picaxe and one channel on the GCB pic (12F1840).
The analyzer showed right away that the serial signals have different polarities. GCB gives a high signal that is pulled low for data, the Picaxe is the other way around.
A transistor on the output of the P12F1840 (pin 7) solved that problem.
Still no readable text though.
The analyzer also showed that the Picaxe pause between bytes is larger than GCB (1.043 mS vs 0.419 mS)
So I tried sending pauses between bytes. Now I had normal text for the first time.
This work around to print "GCBasic RS232 Test" must be optimized of course, but it works:
#chip 12F1840, 16
'USART settings
#define USART_BAUD_RATE 2400
#define USART_TX_BLOCKING
dim Delay as Byte
Delay=5
wait 1 S
; clear display (Picaxe specific commands)
HSerSend(254)
Wait 50 mS
HSerSend(1)
Wait 50 mS
; move to start of first line (Picaxe specific commands)
Wait 50 mS
HSerSend(254)
Wait 50 mS
HSerSend(128)
Wait Delay mS
HSerPrint "G"
Wait Delay mS
HSerPrint "C"
Wait Delay mS
HSerPrint "B"
Wait Delay mS
HSerPrint "A"
Wait Delay mS
HSerPrint "S"
Wait Delay mS
HSerPrint "I"
Wait Delay mS
HSerPrint "C"
Wait Delay mS
HSerPrint " "
Wait Delay mS
HSerPrint "R"
Wait Delay mS
HSerPrint "S"
Wait Delay mS
HSerPrint "2"
Wait Delay mS
HSerPrint "3"
Wait Delay mS
HSerPrint "2"
Wait Delay mS
HSerPrint " "
Wait Delay mS
HSerPrint "T"
Wait Delay mS
HSerPrint "e"
Wait Delay mS
HSerPrint "s"
Wait Delay mS
HSerPrint "t"
Johan
Last edit: JohanDenRidder 2018-01-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
GCB/PIC complies with the RS232 Standard for timing and polarity, PICKAxe is a soft serial so timing and polarity are software dependent and as it is proprietary, the display it is built to expect that.
The 12F1840, however, has a hardware invert function on Tx so:
'Set chip model:
#chip 12LF1840, 4
'Config Hardware-UART:
#define USART_BLOCKING
#define USART_BAUD_RATE 2400
SCKP = 1 ' Invert Tx Bit
Do
HSerPrint "AAAAAAAAAA"
HSerPrintCRLF
Wait 1 s
Loop
Will solve your inversion issue and save you a Transistor.
The timing issue though is another story.
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Picaxe have a serial LCD (and OLED) that needs only 1 wire. This can be a handy device for debugging.
Anyone got it working with GCB?
I tried Serprint and Hserprint using a PIC 12F1840 but I can't get it to work.
Any ideas?
Kind regards,
Johan den Ridder
Yes, is the answer. We have serial LCD support and one wire OLED. The demos show how one wire LCD can be achieved.
I published a onewire K107(K117) LCD support for Serial, I2C and SPI.
Re the SerPrint and HSerPrint = these should work. If you post your code then a few guys will help figure that out.
In gcb only one byte sent eg
SerSend 1, 13
SerSend 1, 10
in picaxe a number of bytes
SEROUT pin,baudmode,(13,10)
I have a DC-motor that has a Hall sensor attached to its spindle.
I want to use the signal from the sensor to stabilize the motor to the speed set by the potentiometer.
I need speeds from 240 to 6000 rpm. At these spindle speeds the sensor gives pulses from 130 to 5 mSec.
The value from the potentiometer goes from 0 to 255. The formula "SetSpeed = (255-ReadAD(An3))/2" converts this to 127 to 0 which is close enough.
In the loop the pulse width will be adjusted until SensorSpeed is same as SetSpeed.
Since the motor does not behave like expected I need to check the value of the PulseIn command. That's why I connected the serial LCD.
I tried HSerPrint:
Last edit: JohanDenRidder 2018-01-24
Which port do have the serial device connected to?
What is connection? The device type. Does it have an inverted serial line?
Please add the chip the desired clock frequency.
...and SerPrint:
Last edit: JohanDenRidder 2018-01-24
I don't know about lcd but tried sending to terminal? to see motor results..remember to set baud and com port.
I have a Pickit3 connected on USB. I don't think it is possible to write to the UART since that function is grayed out.
With HSerPrint I used Port.0 (pin 7)
When using SerPrint I had the LCD on PortA.5 (pin 2)
I tried clock frequencies from 4 to 32 MHZ with command #chip 12F1840, 16
It made no difference.
The LCD does print something, but it doesn't make no sense.
About the polarity, I am not sure if it is inverted, but the LCD works ok on a Picaxe pin using "serout".
Hi Anobium,
Your solution prints 4 characters at a time, but they don't make sense.
The Picaxe display is 2400 baud, so I changed 'define USART_BAUD_RATE 9600' to
2400. The display now shows 10 characters at a time.
I tried HSerPrint "AAAAAAAAAA" to see if the characters would be all the same, but they weren't,
But the are the same at every loop though.
This sounds like older version of Great Cow BASIC - can you tell me the version in use is?
I am not sure where I can find the version, but I downloaded GCB in november 2017
Compile the source and attach the ASM to the post.
Source:
In test.asm (attachment) it says version 0.98.01 2017-10-27
Last edit: JohanDenRidder 2018-01-24
I am travelling until Friday. I will look into this when I get back
Meanwhile, anyone else got this chip?
I did a copy and paste of your code above, changed the chip to 12LF1840 as I only had the LF part on hand and did a HEX/Flash operation.
It worked first time.

I used pin 7 (RA0) as Tx to the Rx of a USB serial converter as I do not have a Serial LCD.
I think you need to test your electrical hook up as the software works fine.
Cheers
Chris
Edit - for traceability:
2.9 Sec. Compiler Version: 0.98.01 2017-10-27 Program Memory: 161/4096 words (3.93%) RAM: 10/256 bytes (3.91%) Chip: 12LF1840
Last edit: Chris Roper 2018-01-25
At the behest of Anobium I also tested the code without the Oscon hack and at different speeds.
I can confirm that it works at 32MHz, 16MHz and 4MHz.
so the line:
Set OSCCON = b'11110000'
is not needed, the compiler has already take care of it..
Cheers
Chris
Is it a serial oled? http://www.picaxe.com/docs/axe133.pdf
Looks like normal 4bit display.
At least Johan got 10 chars to display. Did it ever work with picaxe?
Yes, that's the display that I have. It used to work on Picaxe.
I set up a Picaxe with the display and that worked normally.
Then I hooked up a logic analyzer feeling a bit stupid that I haven't done so right away. One channel on the Picaxe and one channel on the GCB pic (12F1840).
The analyzer showed right away that the serial signals have different polarities. GCB gives a high signal that is pulled low for data, the Picaxe is the other way around.
A transistor on the output of the P12F1840 (pin 7) solved that problem.
Still no readable text though.
The analyzer also showed that the Picaxe pause between bytes is larger than GCB (1.043 mS vs 0.419 mS)
So I tried sending pauses between bytes. Now I had normal text for the first time.
This work around to print "GCBasic RS232 Test" must be optimized of course, but it works:
Johan
Last edit: JohanDenRidder 2018-01-25
So it works? If so, well done for sorting the problem.
Is gcb or picaxe not "standard"...or either?
GCB/PIC complies with the RS232 Standard for timing and polarity, PICKAxe is a soft serial so timing and polarity are software dependent and as it is proprietary, the display it is built to expect that.
The 12F1840, however, has a hardware invert function on Tx so:
Will solve your inversion issue and save you a Transistor.
The timing issue though is another story.
Cheers
Chris