Jump to content

RJS

EstablishedMember
  • Content Count

    25
  • Joined

  • Last visited

Posts posted by RJS


  1. Thanks Reynard!

     

    I see that the Microchip documents do state 1E000h as the EEPROM address, however, when programming the device this does not work. I am not sure if MPLAB is not interperting it correctly or just an error in the document but if you set _EEPROM to F000h the data is written to the EEPROM in the correct location. I hate modifying header files as they will get over written next time I update so I just set the correct value in my code.

     

    Randy


  2. Mac,
    While you gentlemen are talking about the -rb linker option, may I ask if there's a way to tell the linker to use that option from within the source file? Via a #PRAGMA statement perhaps?

     

    Kind regards, Mike

     

    There is no way yet. This is on our todo list.

     

    Regards

    Dave

     

    I can confirm that the updated linker fixes the problem - downloaded to 18f2620 and confirmed working.

     

    I agree with Mac - a pragma for the -rb option would be much nicer than having to use the ide command line settings dialog - means the bootloader config could be automated before building.

     

    cheers

    Ian.

     

     

    Soooo where would one get this new linker from?

     

    Thanks,

     

    Randy


  3. Still cannot get it working.

     

    Does anybody have a working version of code for a2d conv. on a 12f675 that I can compare to?

     

    I would guess the problem is the comparator needs to be turned off but I am not sure how that would affect the AD since you are using it on a different pin.

     

    I do not have the 12F675 but I here is some code that works on the 12F683 which should work the same on the 12F675 except for the configuration bits

     

    ////////////////////////////////////////////////////////////////

    #include <system.h>

     

    #pragma CLOCK_FREQ 1000000

     

    #pragma DATA _CONFIG, _FCMEN_OFF & _IESO_OFF & _CPD_OFF & _BOD_ON & _CP_OFF &

    _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTOSCIO

     

    unsigned short ADRead( void );

     

    #define LED gpio.2

     

    main()

    {

    unsigned short adc;

     

    trisio = 0b11111011; // Port I/O configuration

     

    osccon = 0b01000001; // Set to 1MHZ

    cmcon0 = 0b00000111; // disable comparator

    ansel = 0b01000010; // Fosc/4, AN1 selected

    adcon0 = 0b10000101; // Right justified, AN1, A/D on

     

    LED = 0;

     

    while( 1 )

    {

    adc = ADRead(); // Read Analog value

    LED = !LED; // toggle LED

    delay_ms( adc >> 2 ); // delay based on 1/4 Analog value

    }

    }

     

    unsigned short ADRead( void )

    {

    adcon0.GO_DONE = 1; // start AD conversion

    while( adcon0.GO_DONE ); // wait for it to complete

     

    return( (adresh << 8 ) + adresl );

    }

     

     

    Perhaps not very interesting of a program but it shows how to setup and use the ADC. It just blinks an LED at a rate based on the AD output.

     

    RJS


  4. The "bloated" code is initialisation of this argument that is part of all class methods except static ones. Static class methods do not have this argument. Please try SourceBoost release candidate 6.91 that will be available within next couple of days. It has this issue sorted out.

     

    Regards,

    Pavel

     

    I tried 6.91 RC2 and the static keyword now works for all functions and reduced my program size by 2K ;)

     

    Thanks for the quick fix, you guys are are the best!!!!

     

    RJS


  5. I just upgraded to the C++ version of the compiler and while the compiler does not affect the size of my existing code when I recompile it, it does seem to create bloated code when using classes. For example in the non C++ version the function call func( a ); generates the following assembler code:

     

    0012 5002 MOVF main_1_a, W

    0014 6E03 MOVWF func_00001_arg_a

    0016 EC02F000 CALL func_00001

     

    However using a C++ version of the function, foo.func( a ); the following code is generated

     

    0012 0E00 MOVLW HIGH(gbl_foo+D'0')

    0014 6E04 MOVWF func_00000_arg_this+D'1'

    0016 0E01 MOVLW LOW(gbl_foo+D'0')

    0018 6E03 MOVWF func_00000_arg_this

    001A 5002 MOVF main_1_a, W

    001C 6E05 MOVWF func_00000_arg_a

    001E EC02F000 CALL func_00000

     

    I could understand this if I was using indirection or virtual functions but since the location of the function in my case is always deterministic I do not understand why the additional code is necessary. I have tried using the static keyword and it creates asm similar to the non C++ code in this simple example but a class with multiple functions is causes duplicate references and other errors and I could find any other way to use the static keyword or to otherwise reduce the code size.

     

    Here is the example of a multi function class where I tried to use static but does not compile:

     

    // test.cpp 
    #include <system.h> 
    
    #pragma CLOCK_FREQ 8000000 
    
    #include "foo.h" 
    
    FOO foo; 
    
    void main( void ) 
    { 
    
    char a; 
    
    for( a = 0; a < 100; ++a ) 
    foo.func( a ); 
    
    } 
    
    // foo.h 
    
    class FOO 
    { 
    public: 
    static void func( char a ); 
    static void anotherfunc( char a ); 
    }; 
    
    // foo.cpp 
    #include "foo.h" 
    
    void FOO::func( char a ) 
    { 
    char b; 
    
    b = a; 
    
    anotherfunc( b ); 
    } 
    
    void FOO::anotherfunc( char a ) 
    { 
    char b; 
    
    b = a; 
    }

     

     

    Please let me know if there is any way to better optimize this while still using c++

     

    Thanks,

     

    RJS


  6. Hi,

    I'm a new user to the SourceBoost C compiler, so sorry about this basic problem. The code below is giving me the error message "Unresolved external function" at build time for the 'memcmp' library function. Can anyone help please. ;)

     

    Thanks

     

    Alastair

     

    #include <system.h>

    #include <memory.h>

    #pragma CLOCK_FREQ 8000000

    #define LED latd.1

    char data1[256];

    char buffer1[256];

     

     

    void main(void){

     

    if(memcmp(data1,buffer1,256))

    {

    LED=1;

    delay_ms(150);

    LED=0;

    delay_ms(150);

    }

    }

     

    Are you using MPLAB or the SourceBoost IDE? If you are using MPLAB make sure you are linking with the library file, it is not included automatically like with the SourceBoost IDE. memcmp should be in libc.pic16.lib (or libc.pic18.lib if you are using a 18Fxxx.) To add the library, in the project window, right click on the "Library Files" folder and select "Add File..." and browse to the SourceBoost/lib directory and select the correct library for your PIC.

     

    Hope that helps,

     

    RJS


  7. Sweet! Great work guys. Mind if I make a post about this on the web site?

     

    cheers

    Ian.

     

    If you have the watchdog timer enabled in the config, let it take you back to the reset state. It is very similar to MCLR.

     

    Cheers

     

    Reynard

     

    Reynard,

     

    Thanks for the suggestion. It helped to find the source of the problem by changing the timing a bit more and it is now working. It turns out that the problem was disabling the UART before the reset. Taking out the statements

     

    txsta = 0;

    rcsta = 0;

     

    from the reset sequence resolved the problem and I can upload new firmware automatically and wirelessly!

     

    Thanks,

     

    RJS

     

    I do not have any issues with you posting this.


  8. Without knowing your hardware design I am not sure if this will cause a problem or not but Port B has built in pull-up resistors. option_reg.RBPU = 0 will force the bits (pins) on port B high (logical 1) and then when the button is pressed the input will go low (logical 0). If that is not an option use 10K resistors to VDD on the pin with the button this will have the same effect.

     

    Also you may want to consider using a 1K resistor to GND from the button. You can get away without doing this but I always feel safer limiting the current below the 20ma max for a pin in case there is a short elsewhere.

     

    RJS


  9. If you have the watchdog timer enabled in the config, let it take you back to the reset state. It is very similar to MCLR.

     

    Cheers

     

    Reynard

     

    Reynard,

     

    Thanks for the suggestion. It helped to find the source of the problem by changing the timing a bit more and it is now working. It turns out that the problem was disabling the UART before the reset. Taking out the statements

     

    txsta = 0;

    rcsta = 0;

     

    from the reset sequence resolved the problem and I can upload new firmware automatically and wirelessly!

     

    Thanks,

     

    RJS


  10. I did not see any posts on this so I do not know if I am just missing something simple or charting a new area. I just started playing with the bootloader from Embedded Adventures and discovered that it can be used wirelessly with an XBee. However, as incredibly exciting as that is, I just have to try to push this one step further. The next step is to get this working without a manual reset or cycling the power. I hoped this would be a simple as calling the reset() function after receiving a specific sequence, but apparently not :angry:

     

    As best as I can tell it does appears to go thought the reset ( I also tried forcing the PCL and PCLATH start to 0x0000.) I tried modifying the bootloader to see if it was getting executed and while it seems to be getting to the bootloader code it will not initiate the upload. I have tried a number of different timings incase that was the problem but I still cannot get this to work. I also had the same results with a wired connection.

     

    What am I missing?

     

    Has anyone already got this to work?

     

    Here is the code:

     

    #include <system.h>

     

    #pragma CLOCK_FREQ 4000000

     

    void SendStr( char *p );

     

    #pragma DATA _CONFIG1, _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF

    & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF

    & _INTRC_CLKOUT

     

    #pragma DATA _CONFIG2, _IESO_OFF & _FCMEN_OFF

     

    #define BAUD 25 /* 9600 */

     

    char recdata;

    char rmreset;

     

    void interrupt()

    {

    recdata = rcreg;

    if( recdata == 'r' )

    rmreset = 1;

    porta.1 = !porta.1;

    }

     

    main()

    {

    unsigned char a;

     

    ansel = 0b00000000; // all ports digital

    trisa = 0b00100000; // PortA I/O configuration

    trisb = 0b00000100; // PortB I/O configuration

    osccon = 0b01100000; // Set to 4MHz

    porta = 0; // clear ports

    portb = 0;

     

    // Setup Serial port

    spbrg = BAUD; // Set baud rate

    txsta = 0b00100110; // transmit enabled async mode, 8 bit high speed baud generator

    rcsta = 0b10010000; // enable serial & continous receive

     

    // Setup interrupts

    intcon = 0b11000000; // Global & Peripheral interrupts on

    pie1.RCIE = 1; // interrupts on receive

    pir1.RCIF = 0;

     

    rmreset = 0;

     

    while( 1 )

    {

    porta.1 = !porta.1;

    delay_s( 5 );

    if( rmreset )

    {

    SendStr( "\r\rReset in 10 Seconds\r" );

    txsta = 0;

    rcsta = 0;

    delay_s( 7 );

    for( a = 0; a < 10; ++a )

    {

    porta.1 = !porta.1;

    delay_ms( 100 );

    }

    porta.1 = 0;

    asm clrf _pclath

    asm clrf _pcl

    // reboot();

    }

    SendStr( "Hello\r" );

     

    }

     

    }

    void SendStr( char *p )

    {

    while( *p != 0 )

    {

    while( txsta.TRMT == 0 );

    txreg = *p++;

    }

     

    }

     

    Thanks for any suggestions or assistance.

     

    RJS

×
×
  • Create New...