Internal Eeprom/flash , what are you doing ?


Closed Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52

    Default Internal Eeprom/flash , what are you doing ?

    Hi there,

    New problem. Eeprom doesn't seem to 'store' values. What is going on ?
    Due to the fact that i could'nt get the eeprom part of my code to work, i changed the program to read value, increment, write value and flash led 'value' times. Every time i apply Vdd the value in eeprom should be 1 more then before. Unfortunately, this code always flashes twice, what's going on ?

    Code:
    '==== Set fuses =============================================
    @ device  pic12F519, intrc_osc, wdt_off, mclr_off, ioscfs_off, protect_off, cpdf_off
    
    '==== Set defines ============================================
    DEFINE OSC 8                                            'Int OSC @ 8 Mhz
    OPTION_REG = %10000000
    
    '==== Set variables ===========================================
    Y       VAR word                                        '
    TMP     var BYTE                                        'Temp variable
    tmp2    var byte                                         'Temp variable
    
    
    '==== Set IO ================================================    
    TRISB   = %00111100                                     'Set TRIS register input's & output's
    PORTB   = %00000000                                     'Set all digital low
    led     var PORTB.0                                     'led pin
    
    '==== Main program ===========================================
    MAIN:
    pause 400
    
    read 1,tmp            'read previously written value
    pauseus 100
    
    tmp = tmp + 1        'increment value
    
    write 1,tmp            'store new value
    pauseus 100
    
    tmp2 = 0
    for tmp2 = 0 to tmp
        led = 1
        pause 300
        led = 0
        pause 700
    next tmp2
    
    pause 500
    
    theend:
    goto theend
    Anybody ??

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Increase the pause time after the writes to about 10ms, not 100us...just like the book says...

  3. #3
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Skimask, hi !

    I tried the 10ms delays after read and write, but still no results, keep getting those 2 flashes.
    When i read back the hex location 0x400 always reads 0001 (1 flash one 0, and one on 1, two flashes)

    I have changed the code a little bit to let the variable increment whilst the power is on to be sure it increments, but after power off, power on, again two flashes ...

    Here's the code:
    Code:
    '==== Set fuses ============================================
    @ device  pic12F519, intrc_osc, wdt_off, mclr_off, ioscfs_on, protect_off, cpdf_off
    
    '==== Set defines =========================================
    OPTION_REG = %10000000
    
    '==== Set variables ============================================
    Y       VAR word                                        'To Hold the 12-bit RC5 code
    TMP     var BYTE                                        'Temp variable
    tmp2    var byte
    
    
    '==== Set IO =================================================    
    TRISB   = %00111100                                     'Set TRIS register input's & output's
    PORTB   = %00000000                                     'Set all digital low
    led     var PORTB.0                                     'led pin
    
    '==== Main program ============================================
    MAIN:
    pause 400
    tmp = 0
    
    read 0,tmp
    pause 10
    if tmp > 50 then tmp = 1
    if tmp < 1 then tmp = 1
    
    again:
    tmp = tmp + 1
    write 0,tmp
    pause 10
    tmp2 = 0
    
    for tmp2 = 1 to tmp
        led = 1
        pause 200
        led = 0
        pause 400
    next tmp2
    
    pause 2000
    goto again
    end
    What is wrong, here ?

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    @ device pic12F519, intrc_osc, wdt_off, mclr_off, ioscfs_on, protect_off, cpdf_off
    option_reg=$80 : tmp var byte : tmp2 var byte : ledtmp var byte
    badflag var bit : trisb = $3c : portb=0 : led var portb.0
    main: badflag = 0 : for tmp=0 to 63 : write tmp,tmp : pause 10 : read tmp,tmp2
    if tmp<>tmp2 then gosub flashbad
    next tmp : if badflag = 0 then gosub flashgood
    goto main
    flashbad:  badflag = 1 : for ledtmp=0 to 9 : led=1 : pause 50 : led=0
    pause 50 : next ledtmp : return
    flashgood: for ledtmp=0 to 9 : led=1 : pause 500 : led=0 : pause 500
    next ledtmp : return
    end
    Code will write the value into the eeprom location, then read it back, stepping thru each eeprom location in the '519.
    If the readback doesn't match what was written, the led will flash fast 10 times.
    If the readback is good, it'll flash slowly 10 times after the loop is complete, then start over...

  5. #5


    Did you find this post helpful? Yes | No

    Default

    I don't know if this has anything to do with it but it looks like the PIC doesn't have portb. It has GPIO's. Try changing portb.0 to gpio.0 and trisb to trisio.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by peterdeco1 View Post
    I don't know if this has anything to do with it but it looks like the PIC doesn't have portb. It has GPIO's. Try changing portb.0 to gpio.0 and trisb to trisio.
    That was discussed in another thread earlier today...
    Apparently, PBP aliases GPIO to PORTB and TRISIO to TRISB for the 12F519...
    Go figure eh? I wouldn't have found that... Handy though...

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    In general, writes to internal EEPROM are self timed. No pauses are needed.

    However, on the 12F519, there isn't any EEPROM.
    There's 64 bytes of Flash memory instead.

    That memory is erased in blocks of 8 bytes at a time, and can't just be overwritten byte by byte like you can with EEPROM.

    For what you want to do, it'll be a lot easier to change chips.
    <br>
    DT

  8. #8
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Thanks for your replies guys !

    I could'nt get back to you any sooner, cause the forum was offline.

    The reason i would like to use the 519 is because it's the cheapest and smallest
    pic micro that has memory on it. I did some projects on the 12F635, and that works
    like a charm, however, it's more expensive and isn't available in a MSOP package ...

    OK, so read and write is not going to work then ?

    Is there anyway i can make this work Darrel or Skimask ?

    The project is very small step up dimmer for small led lights. It uses a i2c digital potentiometer to influence a sense resistor. Each time the pic get Vdd it reads the previous value and adds 1 to it and applies the setting to the digital pot. So, by switching the lights on and off a few times the dimmer state can be influenced ...

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ultiblade View Post
    Is there anyway i can make this work Darrel or Skimask ?
    The project is very small step up dimmer for small led lights. It uses a i2c digital potentiometer to influence a sense resistor. Each time the pic get Vdd it reads the previous value and adds 1 to it and applies the setting to the digital pot. So, by switching the lights on and off a few times the dimmer state can be influenced ...
    Using a digital pot for LEDs (i.e. varying the current) isn't the way to go with LEDs. Sure, it'll work, but the results won't be very linear at the lower light levels. Best bet with an LED is to use PWM of some sort of another. If you look at the datasheet for whatever LED you've got, you'll notice that the color/intensity/etc are all referenced to a normalized current drive (or at least a range of current). Go outside of that range and the performance drops. If you use PWM, you drive the LED at an efficient level, with a varying duty cycle. And it saves power too...

    As far as the FLASH in the 12F519? I didn't realize it was 64 bytes of FLASH either, I thought it was EEPROM. I don't have a 519 handy, and I haven't tried it either, so I don't know if PBP supports it in the same way it supports the other PICs with EEPROMs or not. You might end up writing an assembly subroutine to handle read, modifying, and re-writing the FLASH in 8 byte rows.

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ultiblade View Post
    Is there anyway i can make this work Darrel or Skimask ?
    I think so.

    Been looking through the 12F library, and it looks like the READ and WRITE commands still do the right thing. But there's no way (in PBP) to erase a block before writing.

    This might work. It's a macro that will erase 1 block at a time using a Constant for the address.

    To erase the first block (bytes 0-7), you can ...
    @ EraseFlash 0

    To erase the second block
    @ EraseFlash 8

    Put it right before the WRITE command.

    And put this macro somewhere near the top of the program.
    Code:
    ASM
    EraseFlash  macro Addr
      local EraseLoop
        MOVE?CB  (Addr & 0x38), EEADR
        BSF      EECON,FREE          ; SELECT ERASE
        BSF      EECON,WREN          ; ENABLE WRITES
        BSF      EECON,WR            ; INITITATE ERASE
    EraseLoop 
        btfsc    EECON, WR           ; Wait for the erase to complete
        goto     EraseLoop
      endm
    ENDASM
    DT

  11. #11
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52


    Did you find this post helpful? Yes | No

    Talking

    You're both absolutely right.

    I forgot to mention I'm using Cree powerled's, that are driven by a supertex led driver. This driver uses a sense resistor to measure the current, if we influence the current ( by adding a resistor parallel to the sense resistor), we can influence the intensity of the powerled's.

    Darrel, i'm going to try the erase macro immediately, will post my findings ....

    Thanks Experts !

  12. #12
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52


    Did you find this post helpful? Yes | No

    Thumbs up

    Hi Guys,

    I have tried your code Darrel, and erasing the blocks before writing does the trick !!! Thank you !
    Skimask, thank you for your quick replies and expert information !!



    Best regards,

    Ultiblade
    Last edited by ultiblade; - 20th October 2008 at 11:11.

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Woohoo!

    Hope she's my prize.
    <br>
    DT

  14. #14
    Join Date
    Apr 2006
    Location
    GearSweaterMountain, The Netherlands
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    [loud laughter]

    I will ask her to contact you !

    [/loud laughter]

Similar Threads

  1. Internal vs. external osc for comms
    By mtripoli in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th January 2010, 14:58
  2. 12F683 internal pull up
    By hvacrtech in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 27th July 2008, 02:35
  3. Use internal program memory like DATA memory
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th December 2006, 18:38
  4. PIC12F675, accuracy of baud rate with Internal Oscillator
    By Chris Mayhew in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 22:41
  5. 12f675 internal osc question.....
    By Gabe@SPdFtsh in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th January 2004, 06:33

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts