The Student Room Group

PIC basic to ASM learning

Hi,

I am able to program PICs (not expertly:smile:) in PIC basic, but for technical reasons I need to be able to add some ASM (assembler) blocks into my programs. I've no experience with ASM.

Is there anyone who can help me with this please?

Camerart.
(edited 9 years ago)

Scroll to see replies

Reply 1
What architecture? x86, x64 or other? Assembly is easy to learn (even x64) but it's only practical for a few select tasks (e.g. at work I'm often analyzing crash-dumps). With intrinsic code (in c/c++) where 'hidden' instructions can be directly accessed, one can argue assembly is not needed at all.
(edited 9 years ago)
Reply 2
Original post by elohssa
What architecture? x86, x64 or other? Assembly is easy to learn (even x64) but it's only practical for a few select tasks (e.g. at work I'm often analyzing crash-dumps). With intrinsic code (in c/c++) where 'hidden' instructions can be directly accessed, one can argue assembly is not needed at all.


Hi Elohssa,

Thanks for your reply.

I am using a 18F2431 PIC which has special motor control attributes, and the program is written using a simulator (by Oshonsoft). This simulator doesn't support the special motor control attributes needed, so sections of the program need to be in Assembly. I can't understand c++.

Camerart.
If it doesn't support them, does the hardware? Are you actually going to be controlling a motor? If not, have the simulated program just log what it would have done to a file / window / whatever.
Reply 4
Original post by unprinted
If it doesn't support them, does the hardware? Are you actually going to be controlling a motor? If not, have the simulated program just log what it would have done to a file / window / whatever.


The hardware in the 18F2431 is designed to control motors, and I intend to control a motor with it.
Original post by Camerart
The hardware in the 18F2431 is designed to control motors, and I intend to control a motor with it.


Yes, I got that.

But you're developing the program on a simulator, rather than the real hardware, right?

So is the issue that you don't have a proper development kit that will generate the right code for the hardware, or that you want to test the program with the inadequate simulator?
Reply 6
Original post by unprinted
Yes, I got that.

But you're developing the program on a simulator, rather than the real hardware, right?

So is the issue that you don't have a proper development kit that will generate the right code for the hardware, or that you want to test the program with the inadequate simulator?


Sorry!!

I like the simulator and we are trying to get the administrator to work on this chip, and yes, I am trying to test the program with this simulator. I understand that it won't let me do that properly, so I will need to check it via a computer readout connected to the PIC itself once programmed with a mixture of Basic with ASM sections.

C
While you're testing the program on the simulator, you just want to know what it's doing - that doesn't need any assembler, just PRINT statements (or whatever PIC BASIC has to show stuff).

For running on the hardware, you're going to need PIC assembler, if your development compiler doesn't have the functions you want, however it does that.

Personally I'd be using Forth, which enables you to interactively debug on the hardware itself...
Reply 8
Original post by unprinted
While you're testing the program on the simulator, you just want to know what it's doing - that doesn't need any assembler, just PRINT statements (or whatever PIC BASIC has to show stuff).

For running on the hardware, you're going to need PIC assembler, if your development compiler doesn't have the functions you want, however it does that.

Personally I'd be using Forth, which enables you to interactively debug on the hardware itself...


I can write the program on the simulator, then compile the ASM and HEX with it. I can't test it with the simulator, as it doesn't support the QUAD module, so I can only see results from the PIC once programmed and running, via a UART sending information of counters etc on a receiving computer.
I need to be able to add ASM for the QUAD and PWM into my basic program.
Reply 9
Original post by Camerart
I can write the program on the simulator, then compile the ASM and HEX with it. I can't test it with the simulator, as it doesn't support the QUAD module, so I can only see results from the PIC once programmed and running, via a UART sending information of counters etc on a receiving computer.
I need to be able to add ASM for the QUAD and PWM into my basic program.


Look for the datasheet and go from there. PIC assembly is very simple, especially in comparison to other chips.
Reply 10
Original post by CJKay
Look for the datasheet and go from there. PIC assembly is very simple, especially in comparison to other chips.


Nice to know it's simple, but what is the simple process that will help me learn assembler? So far I've read the data sheet, which is long and has all the instructions, and I have printed out the ASM words, and some examples. When it comes to figuring out how write the code correctly. I'm lost.

Remember Eric Morecombe's quote? "I am playing all the correct notes, but not necessarily in the correct order"

C
Reply 11
Original post by Camerart
Nice to know it's simple, but what is the simple process that will help me learn assembler? So far I've read the data sheet, which is long and has all the instructions, and I have printed out the ASM words, and some examples. When it comes to figuring out how write the code correctly. I'm lost.

Remember Eric Morecombe's quote? "I am playing all the correct notes, but not necessarily in the correct order"

C


You'll just have to Google some tutorials or something. If I remember how I learned it I'll get back to you, but that was a long time ago.
Reply 12
Original post by CJKay
You'll just have to Google some tutorials or something. If I remember how I learned it I'll get back to you, but that was a long time ago.
I've done a lot of googling, but I get the feeling that what I need to do (add ASM into an Oshonsoft basic program) isn't straight forward, and needs to be precise. C
Whilst I've not got any experience with PIC microcontrollers (I've mostly worked on ATMega chips) my understanding is a lot of the hardware interaction is from manipulating register values (bytes of memory to setup various features and read/write data).

Learning this in ASM is going to be chip specific and probably a long process. This may be slightly simpler if you can write blocks of ASM in your PICAXE BASIC code but you'll still need to understand what the ASM is doing. If you go down this route you probably need to start off with something very basic (e.g. read in a gpio and set another gpio to mirror the input).

You may be better off learning a bit about C Programming and using that as a slightly higher level than ASM, you could still be manipulating register values but at least you should be able to use symbolc register names which will potentially work across various chips in the same family.
Reply 14
Original post by mfaxford
Whilst I've not got any experience with PIC microcontrollers (I've mostly worked on ATMega chips) my understanding is a lot of the hardware interaction is from manipulating register values (bytes of memory to setup various features and read/write data).

Learning this in ASM is going to be chip specific and probably a long process. This may be slightly simpler if you can write blocks of ASM in your PICAXE BASIC code but you'll still need to understand what the ASM is doing. If you go down this route you probably need to start off with something very basic (e.g. read in a gpio and set another gpio to mirror the input).

You may be better off learning a bit about C Programming and using that as a slightly higher level than ASM, you could still be manipulating register values but at least you should be able to use symbolc register names which will potentially work across various chips in the same family.


In this thread I've been given a few alternatives, but I am limited to the OSHONSOFT simulator language PIC BASIC, and the PIC I'm working with is 18F2431. And I need to be able to add ASM into the basic program. This PIC is a motor control chip and has good internal firmware for what I am doing.

Not wishing to change the subject, but part of this project is to re-program an Orange radio https://www.hobbyking.com/hobbyking/store/__27096__OrangeRx_Open_LRS_433MHz_9Ch_Receiver.html which has an Atmega 328p chip controlling the RF22s radio module. If you would like to help with this please let me know. (Very valuable)

Any help with the above ASM would be very helpful. So far I've turned a LED on by touching another pin:smile:

Camerart.
Original post by Camerart

Not wishing to change the subject, but part of this project is to re-program an Orange radio https://www.hobbyking.com/hobbyking/store/__27096__OrangeRx_Open_LRS_433MHz_9Ch_Receiver.html which has an Atmega 328p chip controlling the RF22s radio module. If you would like to help with this please let me know. (Very valuable)


I've not personally done much with the RFM22B (although I do have a couple of play with) but I know lots of people that have used them (there's even been one on a cubesat). I've done a bit of work with the newer RFM69. One word of warning, if you want to stay legal check the allowed bands, power and duty cycle that can be used license free (I think you're limited to a small range of frequencies around 434MHz and 10mW for license free usage - IR2030 is likely the best starting place for that in the UK). I believe the RFM22 is end of Life now (although still available) so if this for a new project you might be better looking at something else.

I would also highly encourage using C and a native avr compiler rather than going down the arduino (based around C++) route for the 328p and also learn about interrupt routines as that can make the code much more efficient.

Original post by Camerart

Any help with the above ASM would be very helpful. So far I've turned a LED on by touching another pin:smile:


That sounds like a decent start, I'm afraid I can't help much as I've not worked with PICs and don't do much with ASM - although I'm sure there are forums around dedicated to the sort of thing you're doing.
Reply 16
Original post by mfaxford
I've not personally done much with the RFM22B (although I do have a couple of play with) but I know lots of people that have used them (there's even been one on a cube sat). I've done a bit of work with the newer RFM69. One word of warning, if you want to stay legal check the allowed bands, power and duty cycle that can be used license free (I think you're limited to a small range of frequencies around 434MHz and 10mW for license free usage - IR2030 is likely the best starting place for that in the UK). I believe the RFM22 is end of Life now (although still available) so if this for a new project you might be better looking at something else.

I would also highly encourage using C and a native avr compiler rather than going down the arduino (based around C++) route for the 328p and also learn about interrupt routines as that can make the code much more efficient.



That sounds like a decent start, I'm afraid I can't help much as I've not worked with PICs and don't do much with ASM - although I'm sure there are forums around dedicated to the sort of thing you're doing.


Please let me know about anything regarding the RFM22B as it is the one in the radio modules I have. If you are able to program later modules such as the RFM69 or similar, I'll also be interested, especially if they have an interface so I can use them. (I'm not natural at reading programs other than BASIC) I need to be able to send data and hopefully video (not high quality)

The UK frequencies are between 458.5 - 459.5 MHz.

I need to add some ASM sections into PICbasic any thing on 'comparing two numbers' and 'if this then that' would be very useful.

C.

Thanks.
Original post by Camerart
Please let me know about anything regarding the RFM22B as it is the one in the radio modules I have. If you are able to program later modules such as the RFM69 or similar, I'll also be interested, especially if they have an interface so I can use them. (I'm not natural at reading programs other than BASIC) I need to be able to send data and hopefully video (not high quality)

The UK frequencies are between 458.5 - 459.5 MHz.


The RFM22B datasheet suggests it only goes up to 453MHz, It may be configurable for higher but you'll be out of spec for the onboard filtering so there could be a significant impact on how well it works.

The RFM modules I've seen are generally all configured over SPI and you use that same interface to send it data to packetise and transmit. For any sort of video you're going to have to do a fair bit of processing so I'm not sure how feasible it is. It may help to know what sort of thing you're trying to achieve.
Reply 18
Original post by mfaxford
The RFM22B datasheet suggests it only goes up to 453MHz, It may be configurable for higher but you'll be out of spec for the onboard filtering so there could be a significant impact on how well it works.

The RFM modules I've seen are generally all configured over SPI and you use that same interface to send it data to packetise and transmit. For any sort of video you're going to have to do a fair bit of processing so I'm not sure how feasible it is. It may help to know what sort of thing you're trying to achieve.


Hi,

In an effort to lower the frequency of models for use in wooded areas, where higher frequencies get lost. I need different transmitter/receiver pairs with the lowest frequencies, for controlling the models while also receiving video of a quality for observation. While bearing in mind aerial length. Also frequencies not too close to one another.

So say 35Mhz for control and 459Mhz for data/video would be good.

I've looked at your suggestion of later models and a quick skim of the RFM69 data sheet and it seems a better idea to go with later models, than the RFM22B.

I think it might be better to start another 'Thread'. 'Programming radio modules' Does this sound ok?

C.
(edited 9 years ago)
Reply 19
Original post by Camerart
I need to add some ASM sections into PICbasic any thing on 'comparing two numbers' and 'if this then that' would be very useful.

C.

Thanks.


It depends on platform but generally conditional branching is achieved in ASM via either conditional moves (efficient but not use-able in many situations) or conditional jumps (unpredictable conditional jumps lead to heavy branch mispredictions). Control flow in ASM is a bit nasty. I think PIC-Basic has a GOTO instruction. Basically try writing all your control flow logic using only GOTO (no for/while loops etc) and you will know roughly what it's like.

Comparison in ASM is done via instructions that set flags e.g. in x86/x64 there is a CMP instruction that is exactly the same as the subtract (SUB) instruction except it doesn't modify the destination operand...

mov r1, 14
mov r2, 14
mov r3, 14

sub r1, r2 ;sets r1 to 0 and thus sets the ZERO flag
jz label ;jump to label if ZERO flag is set

;random code here

label:

cmp r2, r3 ;sets the ZERO flag but r2 is still 14 as CMP differs from sub and doesn't modify the destination

jz label ;create infinite loop

Quick Reply

Latest

Trending

Trending