What Is Lat Register In Pic
Y'all should upgrade or use an culling browser.
- Forums
- Homework Aid
- Engineering and Comp Sci Homework Help
Interrupts on pic18f452 not shooting in mplab X, aid? C language
- Comp Sci
- Thread starter Maniac_XOX
- Start engagement
-
- Tags
- C language Coding Computational Applied science Mechatronics Microcontroller Physics
- Homework Argument:
- Im trying to make an interrupt in my programme happen at 4 seconds
- Relevant Equations:
- (as below)
Hello delight help asap,
my specific instance I have:
4MHz crystal -----> 1 / (4MHz / 4) = 1MHz timer
I Demand to brand interrupts happen after 4 seconds
1MHz * 4s = 4,000,000 counts
Therefore i decided to apply a 16-bit with a one:64 Prescaler setting.
4,000,000 / 64 = 62,500 counts
The difference would therefore be: 65,536 - 62,500 = 3,036 as preload
the problem arises when I use a breakpoint and stopwatch in MPLAB X IDE to know if the program stops at that specific time ( 4 seconds ) when I initialise the timer part, merely the interrupt merely never happens.
Whatsoever help? it does not work in PROTEUS either, i accept tried earlier agreement the reason existence the preloading, after testing it out with unlike examples.
APPENDIX (lawmaking is in c language):
Edit by mentor -- added lawmaking tags.
#include "LED.h" #include "Timer.h" #include "Button.h" #define _XTAL_FREQ 4MHZ void InitialiseTimer(void) // four seconds TIMER { T0CONbits.TMR0ON = 1; //timer enabled T0CONbits.T08BIT = 0; // 16-bit set T0CONbits.T0CS = 0; // internal clock T0CONbits.T0SE = one; // high to depression transition T0CONbits.PSA = 0; // 1:64 prescale enabled (101) T0CONbits.T0PS2 = 1; T0CONbits.T0PS1 = 0; T0CONbits.T0PS0 = ane; } void chief(void) { InitialiseLED(); // this is from another header file InitialiseTimer(); while(1) // loop to check every run stops at the aforementioned time ( 4 seconds) { if(TimerOverflow()) { LEDToggle(LED1); } } }
Answers and Replies
#ascertain _XTAL_FREQ 4MHZ
one. I don't see that you have used this anywhere in your lawmaking.
2. Even worse, I don't see how it could possibly be used. Assuming that _XTAL_FREQ appears somewhere in your code, all that volition happen is that this cord of characters will exist replaced by the string "4MHZ". This isn't a valid numeric value that the code can utilize.
lol sorry that was a typo in the code i actually write it equally 4000000 then information technology would be 4MHz, simply the problem persistsYou accept this preprocessor directive --
#define _XTAL_FREQ 4MHZone. I don't run across that you have used this anywhere in your lawmaking.
2. Even worse, I don't run into how information technology could peradventure be used. Assuming that _XTAL_FREQ appears somewhere in your code, all that will happen is that this string of characters will be replaced by the string "4MHZ". This isn't a valid numeric value that the lawmaking tin can employ.
I take this circuit in proteus shown at the bottom of the text.
The code:
#ascertain _XTAL_FREQ 4000000 //Set the config bits #pragma config WDT = OFF, BOR = OFF, LVP = OFF, OSC = XT // setting up BUTTONS void InitialiseButtons(void); unsigned char ReadButton(void); #ascertain Upward 0 #define DOWN one #define BUTTON_S2 0x01 #define BUTTON_S3 0x10 #define BUTTON_S2_S3 0x00 void InitialiseButtons(void) { TRISA |= 0x10; TRISB |= 0x01; } //Detects a alter of country of buttons // Buttons are active low unsigned char ReadButton(void) { char ButtonState; static char ButtonFlag = 0x11; //Read Land of both buttons ButtonState = (PORTA & 0x10) | (PORTB & 0x01); if(ButtonFlag != ButtonState) //there has been a change { ButtonFlag = ButtonState; render ButtonFlag; } return 0x11; } // setting up LEDs #define LED0 0x01 #define LED1 0x02 #define LED2 0x04 #define LED3 0x08 void InitialiseLED(void); //paradigm functions void LEDOn(unsigned char TheLED); void LEDOff(unsigned char TheLED); void LEDToggle(unsigned char TheLED); void LEDWrite(unsigned char LEDValue); void InitialiseLED(void) { TRISB = 0xF0; //Fix the port management register LATB = 0x00; //Clear the port } void LEDOn(unsigned char TheLED) { LATB |= TheLED; //Ready the required bit on PORTB } void LEDOff(unsigned char TheLED) { LATB &= (~TheLED); //Clear the required bit on PORTB } void LEDToggle(unsigned char TheLED) { LATB ^= TheLED; //XOR the required bit on PORTB } void LEDWrite(unsigned char LEDValue) { LATB = LEDValue; //Store a value on PORTB } // setting up TIMER void ResetSeconds(void) { seconds = 0; } unsigned char TimerOverflow(void) { char flag = 0; if(INTCONbits.TMR0IF) { INTCONbits.TMR0IF = 0; //flag = 1; seconds++; } //return flag; return seconds; // setting upwards STATEMACHINE with TIMER enum { S_OFF S_STATE1 S_STATE2 }States; enum { E_T1, E_T2, E_BUTTON }Events; #define T3s 3 #define T5s v unsigned char GetEvent(void); unsigned char State = S_OFF; void DoStateMachine(void) { unsigned char Event; Event = GetEvent(); switch(State) { case S_OFF: LEDOff(LED3); LEDOff(LED2); if(Event == E_BUTTON) { ResetSeconds(); State = S_STATE1; } interruption; case S_STATE1: LEDOn(LED3); LEDOff(LED2); if(Event == E_T1) { ResetSeconds(); Country = S_STATE2; } if(Event == E_BUTTON) State = S_OFF; pause; case S_STATE2: LEDOff(LED3); LEDOn(LED2); if(Event == E_T2) { ResetSeconds(); State = S_STATE1; } if(Event == E_BUTTON) State = S_OFF; break; } } unsigned char GetEvent(void) { if(TimerOverflow() == T3s) return E_T1; if(TimerOverflow() == T5s) return E_T2; if(ReadButton() == BUTTON_S2) render E_BUTTON; void main(void) { InitialiseLED(); InitialiseButtons(); InitialiseTimer(); Lcd_Init(); while(1) { DoStateMachine(); } }
When Switch RA4 is pressed, the system flashes the 2nd and 3rd LEDs intermittently.
RA4 is the activate/deactivate switch as i understand, merely since I changed it to RD4, as well as the settings that involve PORT/TRIS/LAT A to PORT/TRIS/LAT D, the LEDs keep flashing and the switch stops working. How do I fix that?
It's also requested that my RESET switch is continued to RC4, non certain how that works either every bit I am aware the MCLR pin is the one that resets the MCU? How can the RC4 pin reset the system?
Concluding issue, the first LED should simply be on when the organization is on, but if the power terminal isnt pesent they won't plow on at all..
Appreciate your help a real lot!
I don't know what you're doing in your line to a higher place with 4MHz crystal and 1MHz timer.my specific case I have:4MHz crystal -----> 1 / (4MHz / 4) = 1MHz timer
I Demand to make interrupts happen after iv seconds
1 / (4MHz / 4) = 1/1MHz = (1/1,000,000) sec./bicycle or 1 microsec/bike.
What's the meaning of the 4 divisor in 4MHz/4?
I don't sympathize how this preload gets set in your code for InitialiseTimer()...1MHz * 4s = 4,000,000 countsTherefore i decided to apply a 16-scrap with a 1:64 Prescaler setting.
4,000,000 / 64 = 62,500 countsThe difference would therefore be: 65,536 - 62,500 = 3,036 every bit preload
4MHz is the the frequency of the oscillator (Fosc), to detect the the frequency of the internal instructions (set in the timer0 control annals, TMR0CON) you divide Fosc by four. So the fourth dimension for one instuction takes 1/frequency = 1/(4/4)I don't know what y'all're doing in your line to a higher place with 4MHz crystal and 1MHz timer.
one / (4MHz / iv) = i/1MHz = (1/1,000,000) sec./cycle or 1 microsec/bike.
What's the meaning of the 4 divisor in 4MHz/4?
And so far i have used TMR0L = whatsoever integer to preload the timer and it worked, non sure why information technology does not work with bigger numbers though, it confuses meI don't understand how this preload gets set up in your code for InitialiseTimer()...
Microcontroller lawmaking is Not an essay that seems to work. Y'all must get inside the motorcar and make certain that admittedly everything must always piece of work.Appreciate your help a existent lot!
Bigger numbers that cause instability are almost e'er due to container size and range. If you lot do a binary search for the maximum size before onset of failure, you will take a clue to the size of the register that is too pocket-sized for the task assigned. A real time clock in software, that fails after 18 hours, 12 minutes and 15 seconds, is a dead requite abroad.
I wrote a existent fourth dimension operating system from scratch in assembly for the PIC16F84. Y'all have an advantage and a disadvantage here, because you are separated from the critical details of the internal auto by the C language. Lawmaking productivity volition be greater, just things can fall through the hidden cracks between assembly and C.
You will demand to write separate minimum size test sequences for the modules, to verify and debug, before rolling it all together.
I accept actually managed to get the seconds right with the correct calculations and settings finally!!Microcontroller code is NOT an essay that seems to work. You lot must get inside the machine and make sure that absolutely everything must e'er work.Bigger numbers that cause instability are well-nigh e'er due to container size and range. If y'all practice a binary search for the maximum size before onset of failure, yous will have a inkling to the size of the register that is too small for the chore assigned. A real time clock in software, that fails after eighteen hours, 12 minutes and 15 seconds, is a expressionless give away.
I wrote a real time operating system from scratch in assembly for the PIC16F84. You accept an reward and a disadvantage here, because y'all are separated from the critical details of the internal machine by the C language. Lawmaking productivity will exist greater, but things can autumn through the subconscious cracks between associates and C.
Yous volition need to write separate minimum size test sequences for the modules, to verify and debug, before rolling it all together.
Would you mind taking a look at the merged thread that is on reply #four? I accept a couple questions on there regarding my proteus design and things i need to change in it, here information technology is below:
#define _XTAL_FREQ 4000000 //Set up the config bits #pragma config WDT = OFF, BOR = OFF, LVP = OFF, OSC = XT // setting upwardly BUTTONS void InitialiseButtons(void); unsigned char ReadButton(void); #define Up 0 #define DOWN 1 #ascertain BUTTON_S2 0x01 #ascertain BUTTON_S3 0x10 #define BUTTON_S2_S3 0x00 void InitialiseButtons(void) { TRISA |= 0x10; TRISB |= 0x01; } //Detects a alter of land of buttons // Buttons are active low unsigned char ReadButton(void) { char ButtonState; static char ButtonFlag = 0x11; //Read State of both buttons ButtonState = (PORTA & 0x10) | (PORTB & 0x01); if(ButtonFlag != ButtonState) //in that location has been a change { ButtonFlag = ButtonState; return ButtonFlag; } return 0x11; } // setting up LEDs #define LED0 0x01 #define LED1 0x02 #ascertain LED2 0x04 #define LED3 0x08 void InitialiseLED(void); //paradigm functions void LEDOn(unsigned char TheLED); void LEDOff(unsigned char TheLED); void LEDToggle(unsigned char TheLED); void LEDWrite(unsigned char LEDValue); void InitialiseLED(void) { TRISB = 0xF0; //Gear up the port direction register LATB = 0x00; //Clear the port } void LEDOn(unsigned char TheLED) { LATB |= TheLED; //Set the required fleck on PORTB } void LEDOff(unsigned char TheLED) { LATB &= (~TheLED); //Clear the required bit on PORTB } void LEDToggle(unsigned char TheLED) { LATB ^= TheLED; //XOR the required bit on PORTB } void LEDWrite(unsigned char LEDValue) { LATB = LEDValue; //Store a value on PORTB } // setting up TIMER void ResetSeconds(void) { seconds = 0; } unsigned char TimerOverflow(void) { char flag = 0; if(INTCONbits.TMR0IF) { INTCONbits.TMR0IF = 0; //flag = ane; seconds++; } //return flag; render seconds; // setting up STATEMACHINE with TIMER enum { S_OFF S_STATE1 S_STATE2 }States; enum { E_T1, E_T2, E_BUTTON }Events; #define T3s 3 #define T5s 5 unsigned char GetEvent(void); unsigned char State = S_OFF; void DoStateMachine(void) { unsigned char Consequence; Event = GetEvent(); switch(State) { case S_OFF: LEDOff(LED3); LEDOff(LED2); if(Issue == E_BUTTON) { ResetSeconds(); State = S_STATE1; } break; case S_STATE1: LEDOn(LED3); LEDOff(LED2); if(Result == E_T1) { ResetSeconds(); State = S_STATE2; } if(Event == E_BUTTON) State = S_OFF; break; instance S_STATE2: LEDOff(LED3); LEDOn(LED2); if(Upshot == E_T2) { ResetSeconds(); State = S_STATE1; } if(Event == E_BUTTON) Country = S_OFF; pause; } } unsigned char GetEvent(void) { if(TimerOverflow() == T3s) render E_T1; if(TimerOverflow() == T5s) return E_T2; if(ReadButton() == BUTTON_S2) render E_BUTTON; void chief(void) { InitialiseLED(); InitialiseButtons(); InitialiseTimer(); Lcd_Init(); while(1) { DoStateMachine(); } }
When Switch RA4 is pressed, the system flashes the 2nd and 3rd LEDs intermittently.
RA4 is the activate/conciliate switch as i empathise, but since I changed it to RD4, too equally the settings that involve PORT/TRIS/LAT A to PORT/TRIS/LAT D, the LEDs proceed flashing and the switch stops working. How do I set that?
It's also requested that my RESET switch is connected to RC4, not sure how that works either as I am aware the MCLR pin is the one that resets the MCU? How tin the RC4 pivot reset the system?
Final effect, the first LED should only exist on when the system is on, but if the ability terminal isnt pesent they won't plow on at all..
Capeesh your assistance a real lot!
View attachment 300883
Related Threads on Interrupts on pic18f452 not shooting in mplab X, help? C language
- Last Mail service
- Final Post
- Last Mail service
- Last Mail service
- Last Postal service
- Last Post
- Terminal Mail
- Last Mail
- Final Post
- Last Post
- Forums
- Homework Assistance
- Engineering and Comp Sci Homework Help
What Is Lat Register In Pic,
Source: https://www.physicsforums.com/threads/interrupts-on-pic18f452-not-shooting-in-mplab-x-help-c-language.1014780/
Posted by: mckenzieallat1971.blogspot.com
0 Response to "What Is Lat Register In Pic"
Post a Comment