View previous topic :: View next topic |
Author |
Message |
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
PWM fast interupt and EEprom write. |
Posted: Mon Apr 05, 2004 4:02 pm |
|
|
Hello,
I'm working on a project where I do 4 output 8 bit PWM at 150 Hz.
When I want to write some value to EEprom I get a break in the PWM signal.
Is there a way to avoid this
I'm using the standart CCS write_eeprom();
I'm using CCS PCH C Compiler, Version 3.180 with 18F242.
Any point to a direction is welcome.
Kind regards,
Gerrit |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Apr 05, 2004 4:53 pm |
|
|
The readme file has instructions on writing to EEPROM while performing other task. I never got it to work correctly. It does look good on paper though. |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Apr 05, 2004 5:22 pm |
|
|
This may help...have you tried writing to EEPROM using assembly rather than the CCS function? The device datasheet doesn't mention any thing on interruption in the PWM module, so this should be doable.
Code: |
MOVLW DATA_EE_ADDR ;
MOVWF EEADR ; Data Memory Address to read
MOVLW DATA_EE_DATA ;
MOVWF EEDATA ; Data Memory Value to write
BCF EECON1, EEPGD ; Point to DATA memory
BCF EECON1, CFGS ; Access program FLASH or Data EEPROM memory
BSF EECON1, WREN ; Enable writes
BCF INTCON, GIE ; Disable interrupts
MOVLW 55h ;Required Sequence
MOVWF EECON2 ; Write 55h, Required Sequence
MOVLW AAh ;
MOVWF EECON2 ; Write AAh
BSF EECON1, WR ; Set WR bit to begin write
BSF INTCON, GIE ; Enable interrupts
BCF EECON1, WREN ; Disable writes on write complete (EEIF set) |
|
|
|
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Mon Apr 05, 2004 5:32 pm |
|
|
Neuton, Haplo,
I will go in this tomorrow. I think it has somethink to do with disabling interrupts.
Haplo I do software PWM, I have a fast int on timer2
every 26 uS
Gerrit |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Apr 05, 2004 5:37 pm |
|
|
That's the culprit then. Interrupts are disabled during EEPROM writes. According to the spec a write takes about 4ms, and your PWM period is 26us. That's why your PWM stops working for a short time. |
|
|
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Mon Apr 05, 2004 11:34 pm |
|
|
Yes I think so, but is it not that only the 0x55, 0xAA seqence has to be without interrupt ?
I will check data sheet to see why CCS disables interrupt for the
compleet write.
Gerrit |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Apr 06, 2004 12:39 am |
|
|
Yes, the interrupts need to be disabled only during the 55/AA sequence.
I checked the ASM code created by CCS, it disables the interrupts before writing the 0x55, but doesn't enable them until the write is done (which is 4ms later):
Code: |
0613: BCF INTCON.7 <--Interrupts disabled
0614: BSF STATUS.5
0615: BSF STATUS.6
0616: MOVLW 55
0617: MOVWF EECON2
0618: MOVLW AA
0619: MOVWF EECON2
061A: BSF EECON1.1
061B: BTFSC EECON1.1
061C: GOTO 61B <--Wait until done
061D: BCF EECON1.2
061E: MOVF @77,W
061F: BCF STATUS.5
0620: BCF STATUS.6
0621: IORWF INTCON,F <--Interrupts enabled
|
In the ASM code I posted earlier (from the device datasheet), the interrupts are disabled only during the 55/AA writing sequence. So if you use that code, you should experience almost no breaks in your PWM signal. It may still happen, but the chance is very very low. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Tue Apr 06, 2004 7:15 am |
|
|
Try this Quote: |
New directive to prevent WRITE_EEPROM from hanging while
the write takes place:
#device WRITE_EEPROM=ASYNC
If you use this do not write to the EERPOM from both an ISR
and outside an ISR.
|
And see how it compiles. I personaly believe that something about the silicon is messed up such that performing writes to EEPROM while other task are being performed does not always work as expected. |
|
|
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Wed Apr 07, 2004 1:59 am |
|
|
Hello Neutone,
I get several errors when placing this directive in the source code at
diverent lines.
When was this directive introduced ( I have version 3.180).
Kind regards,
Gerrit Faas |
|
|
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Wed Apr 07, 2004 5:59 am |
|
|
Thanks all,
I have done my own EEprom write routine and now notting can been
seen in de PWM (led controle) output.
Only disable during 55 AA sequence.
regards,
Gerrit |
|
|
|