Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MPLAB X Help

Status
Not open for further replies.

jpanhalt

Well-Known Member
Most Helpful Member
I spent somewhat more than 3 hours trying MPLAB X. That time was not even enough to get me on the learning curve. Three newbie questions related to debugging:

1) "Animate" has been removed. Is there a work around besides hitting run/stop and hoping you are somewhere near where you want to be or inserting an enormous number of breakpoints?
2) Is it possible to get relatively live register updates, except while single stepping? I was wondering whether one could reduce the simulation processor speed to something like an animate speed and see the registers.
3) I could watch SFR's, but didn't find the trick to add my own registers ("symbols"). I could get them in the watch window, but they disappeared as soon as I did something, like click on run or step.

Thanks,

John
 
I see what you mean... Total disaster for asm users.... I use ISIS anyway so I hardly ever use MPLAB sim..

I have just loaded your project in there and am surprised to see the animate function gone...
 
I forgot to mention the good news. It actually did simulate my 12F1840 using capture (CCP1) mode. Of course, since I wasn't able to see the non-SPF registers, it was hard to check the output, and particularly my math. (My newest version takes multiple, sequential reads and incorporates subwfb and addwfc instructions in the double-precision math to save two steps in each routine. I confirmed both protocols by register injection, but I would still like to test in a more realistic and simpler to manipulate environment.)

John
 
I use only assembly. Let me find the clean code that I tested, and I will post it here.

John
 
I found MPLABX and C a steep learning curve, I had a few years with PIC16 and asm with MPLAB 8xx , Have not found lack of animate a problem . PK3 debug is the tool ! just set a break point then hover mouse over variables ( turn it yellow) and IDE shows values etc , single step or run to cursor etc.

Example

ADwork.jpg
 
Last edited:
I found MPLABX and C a steep learning curve, I had a few years with PIC16 and asm with MPLAB 8xx , Have not found lack of animate a problem . PK3 debug is the tool ! just set a break point then hover mouse over variables ( turn it yellow) and IDE shows values etc , single step or run to cursor etc.

Me too, but I've been learning it and now mostly comfortable with XC8 with the exception of external libraries.
 
Hi Bill,

Surprise, MPLAB X didn't save the source file where I thought it would be saved. Here is a slightly fixed original version. I fixed PortA to be PORTA because of the case sensitivity issue. There are some other case errors, but I don't remember what they were. I will attach two files:

#1 (Read8.asm) is a file treated with Pommie's CodeTidy. It may look better, but has case errors.

#2(MPLAB X Test.asm) is cut and paste from what I simulated on MPLAB X this morning. Hopefully all of the case errors are corrected, but it may not look as nice. I have also commented out delays and waits for the oscillator to stabilize.

Basically, the idea is to capture a PWM signal from an AMS AS5048A angle sensor. Since that 12-bit PWM is clocked at about 4.5 MHz and my 12F1840 is at 16 MHz (4 MHz instruction cycle), I figured I could measure 8 cycles to reduce error in an 11-to-12-bit result and still not exceed 16 bits. Actually, a single reading is not bad, and a double read is better and probably good enough, but this was just an experiment. The error correction I mention refers to the fact the the signal has a fixed prefix of about 12 cycles and a suffix of about 4 cycles, which will need to be subtracted before calculating the duty cycle. But that is not my worry right now. There are several rotates rights that have been commented out that were added to make my reading easier.

I can work though the math. The part I am really worried about is trying to sample multiple times without missing a beat. The PWM signal from this particular device goes from almost 0% at 364.8° to almost 100% at 0.2° (CW turning). Of course, I have the suffixes and prefixes to give me time to capture and store the counts, and I can always limit the useful range to something like 5° to 360° without affecting its utility for my purpose. I can test that using a synchronous stimulus, if I can see the registers.

The registers I want to track are count, and anything beginning with CCP_Txx. Later (much later), I will be adding calculation of the actual angle. By that time, I should be much better at using MPLAB X.

Edit: If I go to hardware simulation, I only get one breakpoint with that chip and my ICD3. I would probably revert at this stage back to MPLAB and ICD3 simulation. The registers are right there to see.

John
 

Attachments

  • Read8.asm
    15.2 KB · Views: 228
  • MPLAB X Test.asm
    13.9 KB · Views: 223
Any reason you're not using the PLL to get 32MHz? Or is 16MHz desired?

Here's a bit of your code in XC8 format, I'm learning so it was educational for me. No bank selecting makes it much easier than ASM.
Code:
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>

#pragma config FOSC = INTOSC,WDTE = OFF, MCLRE = ON, PLLEN = OFF
#define        Data_PWM        PORTAbits.RA2        //pin5 pwm input
#define        Ser_out        PORTAbits.RA0        //pin7 serial output to LCD

#define _XTAL_FREQ 32000000
// putting variables here makes them Global, probably bad programming practice
unsigned int CCP_T0, CCP_T1, CCP_T2, CCP_T3 = 0;


void init() { // I ususally set the oscillator first.
    OSCCON = 0b01111010; // 1111 = 16MHz internal OSC
    while (OSCSTATbits.HFIOFS == 1) { // wait till oscilator's stable
    }
    T1CON = 1; // T1CON,0 = TMR1 start/stop, 1=enables, 0=stops
    T1GCON = 0;
    ADCON0 = 0;
    TRISA = 0b00001100; // RA2,RA3(MCLR)are input,others output
    OPTION_REG = 0; // weak pullups?
    CM1CON0bits.C1ON = 0; // comparators off
    ANSELA = 0; // all digital
// I assume the Parallax LCD is serial? 9600,N,8,1?
    __delay_ms(50);
}

void main() {
    init;
    while (1) {
// mainline code goes here, loops forever
    TMR1 = 0; // clear the timer

    }
}
 
Last edited:
No well thought out reason whatsoever. Since the signal is a 12-bit digitally generated signal and sensor frequency can vary from a little more than 4 MHz to 4.5 MHz -- it is production lot and temperature dependent -- I figured it would be better to measure two or more cycles to average out measurement imprecision, than to measure one cycle more accurately.

The sensor also outputs an SPI or I2C digital signal, depending on whether it is the A or B version, respectively. In reality, any serious application will probably just read those signals. This was a quick and dirty way to get a feel for it and have some fun. I am basically trying to learn and improve my programming skills with a focus, arbitrary as it may be, rather than in a vacuum. As you may remember, two years ago, I was learning to manipulate a GLCD, and a good part of last year was spent chasing bugs and getting my wireless link working. That project is now almost done.

Anything is better than watching television. I don't even have a TV where I am living now.

John
 
What's the part number or data sheet of the sensor, the LCD display would be handy too.

Nevermind, got the data sheet.

Is the project just to convert & transmit that sensor data to serial?
 
Last edited:
Bill , My most recent project used an accelerometer as a remote sensor to help me level pallet forks attached to the front loader of my tractor. Then I found out about the magnet sensors from AMS and AVAGO and was quite impressed. It has been much too cold to test the accelerometer solution in real life, but I anticipate one problem will be vibration and bounce on the tires and tracks. The magnetic sensors could measure the angles between fairly rigid parts and should be less sensitive to bounce. In answer to your question, my rough plan is to use one or more sensors to transmit serial data to a master control. For the tractor, I would probably use two sensors. The master unit that you and others helped me with has a 16F1519 and GLCD. Wireless link uses an XBee, which will likely change in the future.


John
 
Last edited by a moderator:
I though I had MPLAB X working until about 2 hours ago. My watch window had both SFR's and what are now called Symbols showing, and when paused they nicely updated. Stopped to do something else and when I reopened, every line with a semicolon in it gave an error. The error was:

Makefile:2:***missing rule before recipe. Stop.

After a little digging, I guess MPLAB X decided to make me use C whether I liked it or not. Not being able to find what got corrupted, I discarded that project and built a new one. That now builds and simulates, but I cannot get Symboles in the Watch window; only SFR's appear.

The Help window says:

upload_2015-3-28_13-17-7.png


I have tried everything and have no memory of what I did yesterday to make the register symbols show up with their current content value.

Very frustrating. I suspect MPLAB X will go down in history as Microchip's version of Windows 8

John
 
Just looking myself... Whilst debugger is paused... I right click on the global variable, the context menu has "New Watch..." as the first menu option... It automatically added the variable to the watch window..
 
I get exactly the same windows, but when I click on OK, it just disappears. Are you in C or ASM? I suspect C. C is all the help window shows. I am using Assembly absolute mode.

After 30+ hours over a bit more than 3 days, I think the best solution is simply to use a signal generator to the CCP1 pin and do in-circuit debugging, if there is something unique for the 12F1840 that needs to be tested. As for now, I can easily adapt the part of the code in question to run on a 12F683, except for the enhanced addition and subtraction instructions, and those are not critical.

One other disturbing thing is that MPLAB X apparently thinks it is running on an AMD64 processor, which it is not. I can fully appreciate the reasons behind Microchip's decision to outsource further development of its IDE, but I don't think it was well planned or implemented.

Thanks for taking a look at this issue with your version.

John
 
MPLABX is a bug castle... what version u using. Have you tried typing directly into the watch window ( case ).
 
I get exactly the same windows, but when I click on OK, it just disappears. Are you in C or ASM? I suspect C. C is all the help window shows. I am using Assembly absolute mode.
I'm using your asm code... The one you posted earlier in the week..
After 30+ hours over a bit more than 3 days, I think the best solution is simply to use a signal generator to the CCP1 pin and do in-circuit debugging, if there is something unique for the 12F1840 that needs to be tested. As for now, I can easily adapt the part of the code in question to run on a 12F683, except for the enhanced addition and subtraction instructions, and those are not critical.

One other disturbing thing is that MPLAB X apparently thinks it is running on an AMD64 processor, which it is not. I can fully appreciate the reasons behind Microchip's decision to outsource further development of its IDE, but I don't think it was well planned or implemented.

Thanks for taking a look at this issue with your version.

John
Would you like me to sim it in ISIS for you???
 
I appreciate the offer, but my 2-part simulation will do fine for now. I may check out using the 16F1519 that I have experience with instead of the 12F683. I know that MPLab SIM simulates EUSART with that chip, so it might also simulate CCP1 capture. That would make the pseudo-simulation even easier.

I have not given up on MPLAB X yet. I am just giving it a rest. The "about" showing the wrong CPU may be a flag that it did not install correctly. My PC is most definitely an Intel.

upload_2015-3-28_16-43-44.png


So, I uninstalled MPLAB X and its related folders (that option was a nice addition to the uninstall process). When I have more time, I will re-install it with fresh eyes.

Thanks again.

John
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top