Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
March 19, 2024, 03:47:31 03:47


Login with username, password and session length


Pages: [1] 2  All
Print
Author Topic: PIC Dimmer issue with LCD display  (Read 12269 times)
0 Members and 1 Guest are viewing this topic.
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« on: July 05, 2013, 08:37:32 08:37 »

I'm experimenting a dimmer using PIC (with CCS C v4.14) and it works as expected. However the light is flickering after adding LCD support.

Code:
//Dimmer - 220V/50Hz

#include <16F886.h>

#fuses XT
#FUSES NOPUT      //No Power Up Timer
#FUSES NOPROTECT  //Code not protected from reading
#FUSES MCLR       //Master Clear enabled
#FUSES BROWNOUT   //Reset when brownout detected
#FUSES INTRC_IO   //Internal RC Osc, no CLKOUT

#use delay(int=4000000)

#include <LCDX.c>

int1 ZC=FALSE;

#INT_EXT                         //External Interrupt
void  EXT_isr(void)
{
   if(!ZC){     //check if Triac is really OFF
     output_low(PIN_C0);
   }
   ZC = TRUE;

}

//------------------------------
void main( void ) {
   int8 firing_angle;
   
   //drive all pins low, except B0, set as input
   output_b(0);
   output_c(0);
   output_float(PIN_B0);

   lcd_init();           //Initialize LCD

   lcd_putc("\f");       // Clear the LCD
   delay_ms(100);
   lcd_putc("WELCOME");  // WELCOME MESSAGE

   ext_int_edge(L_TO_H);    //set the rising edge to trigger INT

   clear_interrupt(INT_EXT);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

  while (1) {
     firing_angle = 8;   //Test: set firing delay
     if (ZC)
     {
        delay_ms(firing_angle);       
        output_high(PIN_C0);     //Turn the triac ON
        delay_uS(100);
        output_low(PIN_C0);      //Turn the triac OFF
        ZC = FALSE;
     }

   //-------------------------------------
   //LCD function generates blinking light
   lcd_gotoxy(1,2);    //Goto second line
   printf(lcd_putc, "Intensity: %u  ", firing_angle);  //Show Intensity
   //-------------------------------------
   
  }
}

Please take a look on the while loop. I suppose the light is blinking due to the extra delay caused by the LCD driver.
PIC experts please advice how to overcome this problem.
Logged
j0k3r
Junior Member
**
Offline Offline

Posts: 40

Thank You
-Given: 43
-Receive: 18


« Reply #1 on: July 05, 2013, 09:47:44 09:47 »

Hi, remove the "firing_angle" from the while loop, and put on a timer.

Use a timer to count the "angle" and to activate the triac.

like this:
Code:
#int_EXT
void  EXT_isr(void)
{
if (i==1){
EXT_INT_EDGE(L_TO_H);i=0;
}
else
{
EXT_INT_EDGE(H_TO_L);i=1;
}
    output_low(ch1);
   
    set_timer0(power);
   
}

#int_TIMER0
void  TIMER0_isr(void)
{   

 output_high(ch1);   

 }
« Last Edit: July 05, 2013, 09:54:04 09:54 by j0k3r » Logged
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #2 on: July 05, 2013, 11:01:25 11:01 »

Thanks j0k3r.

Actually I use Timer0 INT in the main program. However it is the same with LCD option. Don't understand really what's wrong.

Code:
#int_EXT
void  EXT_isr(void)
{   
   if(!ZC)                     //Check if Triac really turned OFF
   {
      output_low(GATE);
   }

   ZC=1;                       //Zero cross occured
   set_timer0(firing_angle);   //Reload Timer0 for next trigger
}

#int_TIMER0
void  TIMER0_isr(void)
{
   set_timer0(0);   //Stop Timer0
   if(ZC)
   {
      output_high(GATE);  //Turn the gate ON
      delay_uS(100);
      output_low(GATE);   //Turn the gate OFF
      ZC=0;
   }
}
Logged
robotai
Junior Member
**
Offline Offline

Posts: 60

Thank You
-Given: 27
-Receive: 23


« Reply #3 on: July 05, 2013, 11:15:45 11:15 »

@leaveme, seems you are using <LCDX.c>. Maybe you may check that file to see is there any extra delay inside its functions.

BTW. I suppose you are using 50HZ signal from power line to trigger the interrupt. So is your trigger rate being 50HZ = 20ms?
Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #4 on: July 05, 2013, 11:29:27 11:29 »

The flickering is the result of the delay in LCD write functions. Default LCD write functions poll the 'busy flag' of lcd after sending the data to be displayed. That is for each and every character transmitted. So the lcd routines in your 'while' loop is corrupting your timings. I can suggest you 2 solutions to overcome this,

1- Use an external interrupt to detect the status of the busy flag and transmit the next character to be displayed. To achieve this you'll need to rewrite all the lcd routines again which makes the harder option.

2- On detection of a zero crossing, fire a timer inside the external interrupt. Timers value will be loaded with the firing angle data (calculated carefully), and that timer overflows fire your triac. You can also get rid of 'ZC' (Zero Crossing?) by implementing this option.

robotai: With a 50Hz power line, trigger rate is 10ms as there are 100 zero crossings for a 50Hz sinusoidal signal.
Logged

Regards...
robotai
Junior Member
**
Offline Offline

Posts: 60

Thank You
-Given: 27
-Receive: 23


« Reply #5 on: July 05, 2013, 11:50:17 11:50 »

@hate, he set the trigger from "L to H" only, not zero cross. So if he use only simple "diode" to filter out the negative signal, the frequency will be only 50HZ. If he use "bridge" to switch the negative side into positive, the frequency will become, yes, 100HZ. Am I right?
Logged
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #6 on: July 05, 2013, 12:19:09 12:19 »

@robotai:
I use Rising edge only. Frequency or ZC is not my cencern. It is working great and I can vary the luminosity by the ADC. No flickring at all. But the whole thing changes after adding the LCD. That is my worry.

@hate:
Your option-2 is not very clear to me.
I'm already with your option-2. Since I already fire a timer inside the EXT INT (see post#3 for original project). I'm getting firing-angle data from the ADC (in while loop). But still LCD is disturbing my timer.

I also checked the LCD driver (it is the same driver provided with CCS).
Can't find the way out to overcome the lcd delay.
« Last Edit: July 05, 2013, 01:45:25 13:45 by leaveme » Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #7 on: July 05, 2013, 01:37:28 13:37 »

@hate, he set the trigger from "L to H" only, not zero cross. So if he use only simple "diode" to filter out the negative signal, the frequency will be only 50HZ. If he use "bridge" to switch the negative side into positive, the frequency will become, yes, 100HZ. Am I right?
Yes you are right. But how do you know he filters the negative signal? That's definitely not clear to me. A 'L to H' pulse can be adjusted easily using a bridge rectifier or even using a half-bridge rectifier, I've done that many times before so I don't see any reason to assume negative sine is filtered. That's why I think the trigger rate is 10ms, that still depends on his hardware though as you said.

leaveme: Option-2 needs some calculations. In more detail, what you need to evaluate is the trigger delay for the triac after zero crossing. Suppose you have a timer which overflows every 10ms and you have 50Hz mains power which makes 100 zero-crossings per second and 10ms period. What you need to do is to start the timer with a suitable value according to your firing angle when external interrupt triggers. i.e. for a half-dim start the timer at 5ms, for a quater-dim start at 2.5ms etc...

Btw there is nothing wrong with the LCD driver. I'll explain in detail. LCDs need some processing time to display anything after the data to be displayed is transferred to the lcd. Afaik that's 5ms for 4-bit connection. So that means each time a character is transferred lcd write routine waits for 5ms before transmitting the next character. Considering the string "Intensity: %u  " in your code, your code will wait at least 13x5ms=65ms while writing this string to lcd. That's at least 7 zero crossing missed till the printf function is finished which results in the triac not fired ever during this period. That's the flickering you realize. Hope it's more clear now.
Logged

Regards...
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #8 on: July 05, 2013, 01:59:38 13:59 »

Thanks hate.
Here is my original project. I also attached the basic schematic.

Code:
#include <16F886.h>

#device adc=10

#fuses HS
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOPROTECT                //NO Code protected
#FUSES NOBROWNOUT               //No brownout reset
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT

#use delay(int=8000000)         //Use 8MHz Internal OSC


#include <LCDX.c>


//------------------------------------------------------------------------------
#define MINIMUM_FIRING_ENGLE   100      //Min intensity
#define MAXIMUM_FIRING_ENGLE   220      //Max intensity

#define ZERO_CROSS             PIN_B0   //Zero cross input
#define GATE                   PIN_C0   //Firing output
#define SPEED_POT              sAN0     //ADC input for Pot

//------------------------------------------------------------------------------
int8 firing_angle;
int1 ZC=FALSE;

//------------------------------------------------------------------------------
#int_EXT
void  EXT_isr(void)
{    
   if(!ZC)                     //Check if Triac really turned OFF
   {
      output_low(GATE);
   }

   ZC=1;                       //Zero cross occured
   set_timer0(firing_angle);   //Reload Timer0 for next trigger
}

//------------------------------------------------------------------------------
#int_TIMER0
void  TIMER0_isr(void)
{
   set_timer0(0);   //Stop Timer0
   if(ZC)
   {
      output_high(GATE);  //Turn the gate ON
      delay_uS(100);
      output_low(GATE);   //Turn the gate OFF
      ZC=0;
   }

}

//------------------------------------------------------------------------------
void main()
{
   int8 adc_temp_data;

   //drive all pins low
   output_b(0);
   output_c(0);
  
   output_float(ZERO_CROSS);  //set as input
   lcd_init();                //Initialize LCD

   setup_adc_ports(SPEED_POT|VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_32);

   setup_timer_0(T0_INTERNAL|T0_DIV_128);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   //initialize_variables();

   lcd_putc("\f");       // Clear the LCD
   delay_ms(100);
   lcd_putc("WELCOME");  //SHOW WELCOME MESSAGE

   clear_interrupt(INT_EXT);  
   clear_interrupt(INT_TIMER0);  
   ext_int_edge(L_TO_H);           //set the rising edge to trigger INT_EXT
   enable_interrupts(INT_EXT);     //EXT INT
   enable_interrupts(INT_TIMER0);  //TIMER0 INT
   enable_interrupts(GLOBAL);

   while(TRUE)
   {
      //removed ADC calculation stuff
      
      firing_angle = MINIMUM_FIRING_ENGLE + adc_temp_data;
      
      lcd_gotoxy(1,2);    //Goto second line
      printf(lcd_putc, "Intensity: %u  ", firing_angle);  //Show Intensity
      
   }
}
« Last Edit: July 05, 2013, 02:05:16 14:05 by leaveme » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #9 on: July 05, 2013, 03:21:09 15:21 »

Hint: Start to hate to use DELAY on programming.

-ichan
Logged

There is Gray, not only Black or White.
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #10 on: July 05, 2013, 03:56:36 15:56 »

Hint: Start to hate to use DELAY on programming.

-ichan
Any idea to remove the delay from the LCD routine?
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #11 on: July 05, 2013, 04:09:31 16:09 »

To totally remove delay on lcd routine will need the hardware wired to the lcd so it can read the lcd status.

Mostly LCD's only need long delay on initializing, other delay can be replaced by a series of NOP (for FOSC < 25MHz).

But the problem is not there... the mcu need to fire the thyristor on every cycle, nothing allowed prevent it. No problem if the LCD write took a long time to complete as long as the firing routine can interrupt it (in short periode) to do the the important task.

-ichan
Logged

There is Gray, not only Black or White.
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #12 on: July 05, 2013, 04:29:10 16:29 »

... the mcu need to fire the thyristor on every cycle, nothing allowed prevent it. No problem if the LCD write took a long time to complete as long as the firing routine can interrupt it (in short periode) to do the the important task.

-ichan
I totaly agree.
My understanding is (in my case), Timer0 INT must fire on every cycle...no matter what happened in other areas. But this is not happening here.

Code:
#priority int_EXT, int_TIMER0

Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #13 on: July 05, 2013, 04:46:55 16:46 »

Remove the delay on the interrupt...

-ichan
Logged

There is Gray, not only Black or White.
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #14 on: July 05, 2013, 05:42:26 17:42 »

100uS delay in Timer0 has been used for pulse. However I removed it and modified the interrupt. But it's same.
Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #15 on: July 05, 2013, 05:44:17 17:44 »

Any idea to remove the delay from the LCD routine?
You can't remove the delay in lcd routine. You can only make the mcu deal with other things while lcd is busy as 'Ichan' said. I already told you how to do that in option-1 but that's the worst way to accomplish what you are trying to do so I suggest you go for option-2.

First of all your hardware (consisting of R2, R3, R4, R5, C2, Q1) detects every zero crossing, namely all 100 of them. That makes your period 1/100=10ms Don't use timer0 for firing angle. Afaik timer0 can't be stopped, it always runs so it will fire the interrupt no matter what. Use timer1 in 16 bit mode.

A quick calculation gives 4/8000000*65536=32.768ms for timer1 overflow in 16bit mode with 8MHz crystal. But you need it 10ms max. So your offset for timer1 will be 45536.
If you need 255 dim levels, you need to add your firing angle value to this offset. Assuming 'a' is your firing angle, your final timer1 start value will be sv=45536+20000*a/255.

What you'll do is start timer1 with 'sv' preloaded when external interrupt triggers and fire the triac and stop the timer when the timer overflows. Take a look at the code below for further reference.
Code:
int8 firing_angle;
//int1 ZC=FALSE; <-- Get rid of this.
int16 sv;

//------------------------------------------------------------------------------
#int_EXT
void  EXT_isr(void)
{   
  // Load timer1 with sv, make sure timer1 is stopped when initialized.
  // That code may not work, you may need to insert your own code to load the 16-bit timer1 with a 16-bit variable.
   set_timer1(sv);   //Reload Timer1 for next trigger
   enable_timer1();  // I'm not sure there is a function with that name but I'm sure you got the point.
}

//------------------------------------------------------------------------------
#int_TIMER1 <-- This and below must be for timer1.
void  TIMER1_isr(void)
{

   set_timer1(0);   //This code doesn't stop timer1, just loads it with 0, you may want to look for a 'disable_timer1()' function.

      output_high(GATE);  //Turn the gate ON
      delay_uS(100);        // I remember 2 micro seconds is enough to fire a triac, check triacs datasheet.
      output_low(GATE);   //Turn the gate OFF
}

//------------------------------------------------------------------------------
void main()
{
   // Calculate 'sv' here according to the adc or any other method of your choice.
}
Also don't forget to read my comments.
Logged

Regards...
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #16 on: July 06, 2013, 07:54:20 07:54 »

Thank you, hate.
I modified the code considering your references. It is now adapted for TIMER1 (in 16bit mode). Basic thing works, brightness varies depends on the sv value. However I still do not see the difference with LCD though.

Code:
#include <16F886.h>

#device adc=10

#fuses HS
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOPROTECT                //NO Code protected
#FUSES NOBROWNOUT               //No brownout reset
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES NOPUT                    //No Power Up Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT

#use delay(int=8000000)         //Use 8MHz Internal OSC

//#priority int_EXT, int_TIMER1


#include <LCDX.c>

#define ZERO_CROSS             PIN_B0   //Zero cross input
#define GATE                   PIN_C0   //Firing output

//-----------------------------------------------------------------------------

int16 sv;

//-----------------------------------------------------------------------------
#int_EXT
void  EXT_isr(void)
{   
   set_timer1(sv);                 //Reload Timer1 for next trigger
   enable_interrupts(INT_TIMER1);  //Enable TIMER1 INT
}

//-----------------------------------------------------------------------------
#int_TIMER1
void  TIMER1_isr(void)
{
   disable_interrupts(INT_TIMER1);  //Disable TIMER1 INT

   output_high(GATE);              //Turn the gate ON
   delay_uS(5);                    //5us triggering delay
   output_low(GATE);               //Turn the gate OFF
   enable_interrupts(INT_TIMER1);  //Enable TIMER1 INT
}

//-----------------------------------------------------------------------------
void main()
{
   int16 step;
   
   //drive all pins low
   output_b(0);
   output_c(0);
 
   output_float(ZERO_CROSS);  //set as input

   lcd_init();                //Initialize LCD

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_timer_2(T2_DISABLED,0,1);

   lcd_putc("\f");            // Clear the LCD
   delay_ms(100);
   lcd_putc("WELCOME");       //SHOW WELCOME MESSAGE

   clear_interrupt(INT_EXT); 
   clear_interrupt(INT_TIMER1); 
   
   ext_int_edge(L_TO_H);      //set the rising edge to trigger INT_EXT
   
   enable_interrupts(INT_EXT);  //Enable EXT INT
   enable_interrupts(GLOBAL);   //Enable Global INT

   while(TRUE)
   {
      //for test
      //sv = 47096;
     
      step = 78 * 20;
      sv = 45536 + step;

      //lcd_gotoxy(1,2);    //Goto second line
      //printf(lcd_putc, "Intensity: %Lu   ", sv);  //Show Intensity

   }
}

I also noticed a funny thing today. Take a look on while loop. I get a steady light if I use sv = 47096. However light starts blinking with the math sv = 45536 + step.
Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #17 on: July 06, 2013, 10:32:54 10:32 »

Code:
//-----------------------------------------------------------------------------
#int_TIMER1
void  TIMER1_isr(void)
{
   disable_interrupts(INT_TIMER1);  // You should disable timer1 itself not its interrupt.

   output_high(GATE);              //Turn the gate ON
   delay_uS(5);                    //5us triggering delay
   output_low(GATE);               //Turn the gate OFF

   enable_interrupts(INT_TIMER1);  // <-- Get rid of this line. Why enable timer1 here?
}
Why are you enabling timer1 again inside timer1_isr? This doesn't make sense! This way timer1 always fires the triac with no reference to zero crossing.

You must disable or enable timer1 itself not timer1 interrupt. There is a huge difference between the 2. Use 'setup_timer1(SOME_CONSTANT)' function to enable or disable timer1.

The offset value (45536) I calculated depends on perfect conditions but not all zero crossing detectors are perfected. Your zero crossing detector for example detects zero before crossing it so the triac might get fired before zero that results in triac entering cut-off region at zero. You might get erratic behavior because of this. 47096 might be a safer value to use as it shortens timer overflow time, just use it. You might also be getting this because you enabled timer1 (interrupt) in timer1_isr.

However I still do not see the difference with LCD though.
What do you mean by that? You don't understand the functional difference or your code still doesn't work as intended when lcd is in action?
Logged

Regards...
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #18 on: July 06, 2013, 11:21:03 11:21 »

Sorry hate, I have been following this thread and this guy doesn't seem to know what he is doing. I believe he should read/think more before he tries to code such a project.
Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #19 on: July 06, 2013, 12:29:35 12:29 »

No need to be mate. At least he's trying. Wink
Logged

Regards...
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #20 on: July 06, 2013, 12:32:20 12:32 »

@metal:
Everybody starts steping at some point and can't walk alone. Sorry buddy if my statement hurts you but yours really hurts.  Embarrassed

@hate:
So much thanks for comming back.

Code:
 
...
////set_timer1(0);   //This code doesn't stop timer1, just loads it with 0, you may want to look for a 'disable_timer1()' function.
...

Seems I misinterpreted.
There are only two functions in CCS, disable_interrupts(INT_TIMERx) or clear_interrupts(INT_TIMERx). My understanding was that... set_timer1(0) stops the timer.

I calculated 47096 a safer value. It triggeres correctly with apprx 10% luminosity. I'll try once again and come back.
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #21 on: July 06, 2013, 12:50:19 12:50 »

stepping occurs after you understand what you are trying to do provided you understand your hardware, the way you are working is kinda like waves poppling which produces nothing but froth.
Logged
leaveme
Junior Member
**
Offline Offline

Posts: 93

Thank You
-Given: 38
-Receive: 15


« Reply #22 on: July 06, 2013, 01:01:50 13:01 »

If I understand then I should not be here and should be doing it without asking you guys.
I know you're sound in PIC and C. If you want to help, please help. if you don't, don't but I would appreciate no criticize.

thanks
Logged
gan_canny
Junior Member
**
Offline Offline

Posts: 89

Thank You
-Given: 101
-Receive: 26


« Reply #23 on: July 06, 2013, 01:07:57 13:07 »

PIC interrupts as the name implies interrupt the normal process of the MCU ( executing the code in main). The interrupts can be triggered externally or internally. For an internally triggered timer the source of the trigger is the oscillator and the pre-scale and post-scale counters. Interrupts can be enabled or disabled individually and enabled or disabled globally. Care is needed when enabling since the trigger may already have occurred ( disabling the interrupt doesn't disable the triggering ( just the interrupt). Since entering and exiting an enabled interrupt after a trigger has occurred consumes MCU cycles care must be taken to keep the cycles consumed in the user code of the interrupt. A good interrupt service routine (ISR) should always be as short as possible. Fewer lines of code is good but remember it is MCU cycles that are the issue. Avoid floating point trig functions printf and delay in an isr. Avoid code that alters other interrupts from within a specific interrupt. Communicate with the main code via global variables (a.k.a flags). An interrupt can occur at anytime in the main code ( that means within a line of code). An example what can go wrong could be assigning a value to a 32 bit variable in main that also will be altered inside an isr. The main code moves the first 8 bits into the 32 bit variable then the interrupt occurs which writes a new 32 bit value and returns to main in which the next 3 8 bit operations override the isr value. The result is first 8 bits from isr last 24 bits from main. Not a happy result so the main code 32 bit assignment would need protecting by a disable and enable of the interrupt. The trigger would still have occurred so upon enabling the isr would assign the new 32 bit value. 32 bits is used for illustration purposes but any variable assignment requiring more than one instruction to perform is vulnerable.
Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #24 on: July 06, 2013, 02:38:40 14:38 »

leaveme:
stepping occurs after you understand what you are trying to do provided you understand your hardware, the way you are working is kinda like waves poppling which produces nothing but froth.
What Metal tries to say is you are being careless and I definitely agree with him as you are still on the wrong path.

Code:
   
...
////set_timer1(0);   //This code doesn't stop timer1, just loads it with 0, you may want to look for a 'disable_timer1()' function.
...

Seems I misinterpreted.
There are only two functions in CCS, disable_interrupts(INT_TIMERx) or clear_interrupts(INT_TIMERx). My understanding was that... set_timer1(0) stops the timer.
Let me repeat one last time. You need to enable or disable timer1 NOT timer1 interrupt. I don't know which CCS function makes it possible but that is your job to find. Probably setup_timer1() function has a parameter to STOP TIMER1. Check CCS compiler manual or whatever. I hope that is clear.

Also scrutinize and carefully answer my previous post pointed at you. If you will just glance at what I write, I will no longer help you cuz I don't like repeating things many times.
Logged

Regards...
Pages: [1] 2  All
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC