CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PWM fast interupt and EEprom write.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gerrit



Joined: 15 Sep 2003
Posts: 58

View user's profile Send private message

PWM fast interupt and EEprom write.
PostPosted: Mon Apr 05, 2004 4:02 pm     Reply with quote

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 Mad 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

View user's profile Send private message

PostPosted: Mon Apr 05, 2004 4:53 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 05, 2004 5:22 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 05, 2004 5:32 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 05, 2004 5:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 05, 2004 11:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 06, 2004 12:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 06, 2004 7:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 1:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 07, 2004 5:59 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group