Using GPIOs on the R-Pi
Pages: 1 2
Rick Murray (539) 13851 posts |
That is “nominally” correct, however as has been pointed out above, the memory, I/O, etc runs at a slower speed (in some cases, much slower) than the processor. In these cases, the memory addressing subsystem will just stall the processor while waiting on the hardware. There’s a whole science to knowing how to write code to maximise throughput. For example, a conversion from VFP to ARM register takes something like 22 cycles. So if you do an FP compare and then want the result immediately, your processor will be doing nothing for all those cycles. However, if you can get the processor to do other stuff for that time (reorder your code so you don’t need results immediately), you can use those cycles for execution. |
Tank (53) 375 posts |
Just for fun, I have added GPIO_FlashOn/Off, that will flash the GPIO pin sent in R0 at a rate set by R1 as on time in centi-seconds and R2 as off time in centi-seconds. |
Wouter Rademaker (458) 197 posts |
“GPIO_FlashOn, foo, 0, bar” and “GPIO_FlashOn, foo, bar, 0” are somewhat counter intuitive, the first is like “GPIO_WriteDate, foo,1” (always on) and the second is like “GPIO_WriteDate, foo,0” (always off). |
Tank (53) 375 posts |
I may not have explained it correctly, GPIO_FlashOn turns on the GPIO pin in R0 to pulse at the mark-space ratio determined by the R1,R2 values. |
Jochen Lueg (1597) 13 posts |
That new SWI (FlashOn) works a treat, Tank. I for one thank you very much for all your hard work. Are there any plans to get D/A conversion going? |
adonis (2014) 4 posts |
This is not a reply to any issue here but a question that I have no answer since I bought my two (made in UK and China) RPi Rev B. I’ve got no problem with the 17 GPIOs on P1 header using RISCOS with the GPIO Module from Tank and BBC BASIC Programming Language, all are working fine. I’ve read on many websites more than a year ago that there are additional GPIOs on P5 connector. So, I tried it but I could not make it work. Both the 5 Volts and 3.3 Volts were present on P5. Then, I tried the RTB (Return to Basic) and the RASPbian, I was surprised that the additional 4 GPIOs works. So, I suspected that the GPIO Module does not include access to the P5 GPIOs or the RISCOS itself. Since I used BBC BASIC for my Robotics Project and already used-up all 17 GPIOs, having additional 4 more GPIOs from P5 would be great for adding more sensors to my project. I hope anyone out there could provide me some answer for this long time question on my mind. Thanks in advance for any reply. |
Tank (53) 375 posts |
Adonis, If you are running on a B rev 2 the extra GPIO’s should work (they are GPIO28,29,30,31) unless you are using an old version of the GPIO module. |
adonis (2014) 4 posts |
Hi Tank! Yes both UK and China made RPi are Rev 2 and confirmed again from this website (http://www.qube2.org/2013/09/27/raspberry-pi-model-b-v1-vs-v2/). I also able to find the Task Window (after several attempts) and it says ‘We are running RaspberryPi B Rev2 hardware’. I downloaded the latest GPIO Module from (http://www.tankstage.co.uk/Software/) many times and used the same GPIO# you mentioned but still couldn’t make it work. Perhaps there is something I need to change on part of my BBC BASIC code below: DEFPROCinit DIM A%(21) BTW, I used 10 GPIOs as outputs and 7 GPIOs as inputs and all works well except the P5 GPIOs. I even confirmed the voltage on this 4 additional GPIOs with a multimeter but it doesn’t change its level to HIGH. Many thanks for your response. |
Tank (53) 375 posts |
I see the problem. The extra 4 GPIO’s are not part of the Expansion header, so don’t get set up with the GPIO_ExpAsGPIO call. |
adonis (2014) 4 posts |
Thanks very much Tank! Finally, it’s working now although there were some strange things that happened. At first run of the program after incorporating the command GPIO_WriteMode, 28,1 to 31,1, the voltage I measured on 4 extra GPIOs were 3.3 Volts. Then afterwards, the state becomes reverse and the voltage level remain 1.3 Volts instead of 3.3 Volts. I tried several variation within the program to confirm but SYS “GPIO_WriteMode”,28,1 to 31,1 call triggers a LOW (0.0 Volt)state while SYS “GPIO_WriteMode”,28,0 TO 31,0 triggers a HIGH (1.3 Volts) state. The 1.3 Volts level on pins is not much of a problem, I will just connect a resistor to pull it up to 3.3 Volts. The state level is not a problem as long as it changes to HIGH and LOW vice-versa when instructed. I’m not sure though yet if it will stabilize once I used the extra 4 GPIOs as an INPUT for sensors. So, I will just consider the default state for 4 extra GPIOs as HIGH. Also, I found-out that SYS “GPIO_WriteData” call won’t work on P5 GPIOs. Am I correct? Have a good day! |
Tank (53) 375 posts |
Adonis, |
adonis (2014) 4 posts |
Good Day to you Tank! Finally, I was able to figured it out. I never thought it took me more than a year to find an answer! Good thing you showed-up here Tank because I already gave-up solving my P5 problem. Here is the routine I wrote for checking the P5 GPIOs: DEFPROC_p5_test The P5 GPIO’s are HIGH now = 3.3 Volts and LOW= 1.3 Volts I realized that I have to set the MODE individually for P5 GPIOs unlike the P1 GPIOs which can be set altogether with I intended to use the extra 4 GPIOs for additional two IR Sensors, Wheel rotation counter/Distance Measurement and Power Reset. I already have an RPi 2 and A+ but before migrating I need to resolve some more issues I have on RPi B REv 2. I think it was all rectified now. Many thanks again Tank. |
Evert Jan Henken (2788) 12 posts |
I like de GPIO module from Tank and want to use it with Pibrella on a Raspberry Pi. Evert Jan Henken |
Tank (53) 375 posts |
Evert, I’m afraid the GPIO module uses the centisecond timer callback to time the switching, so it will not be fast enough to be used as a PWM for the LED. You may need to use your own timing (maybe with the HAL_Timer) for quicker switching, or just loop call the GPIO module with delays. This may need to be in assembler to call quick enough to act as a PWM. |
Rick Murray (539) 13851 posts |
Is there no hardware PWM? A programmable GPIO? |
Evert Jan Henken (2788) 12 posts |
Rick, |
Pages: 1 2