electronicsfreak
Member
Hello everyone. Man it's been forever since I've posted here
Anywhoo here's the situation. for a class project dealing with a different micro-controller, the HCS12, we were to build a spectrum analyzer. Succeeded, and thankfully passed.
So, for fun, I figured why not try to do the same thing using a PIC. In this case, the PIC12F675. I've gotten the setup to "work", but not quite to the state I'd like. I'd like to refresh its display every so often instead of as fast as possible, so I figured a timer interrupt would be perfect.
Here's the situation. I'm having a bit of trouble tripping an interrupt from the timer0 module. I think I've got all of my initialization registers setup correctly, but I could be wrong. In particular the OPTION and INTCON registers.
Having broken down to the problem as much as I can, I've got a simple tidbit of code in the actual interrupt routine:
My main routine after setup simply sits in a never ending for loop periodically kicking the dog, heheh.
The intent with this test is to try to pull a ~60Hz square wave on the scope from the appropriate pin (strobe is set to GPIO1), eventually changing my pre-scaler and counter values to adjust a display refresh rate. However I can't seem to get anything out of it from the ISR, as my scope signal lays dead at the logical high STROBE is left at initially.
Any thoughts, comments, suggestions? Possible conflicts you've dealt with in the past? I'm fairly new to PIC's with C, especially using any of the extra modules packed in the MCU. A slap in the face stupid newbie mistake is probably what you'll find (well, new to C with these little guys, just decided to make the switch from .asm) Thanks in advance for your time fellas!
Anywhoo here's the situation. for a class project dealing with a different micro-controller, the HCS12, we were to build a spectrum analyzer. Succeeded, and thankfully passed.
So, for fun, I figured why not try to do the same thing using a PIC. In this case, the PIC12F675. I've gotten the setup to "work", but not quite to the state I'd like. I'd like to refresh its display every so often instead of as fast as possible, so I figured a timer interrupt would be perfect.
Here's the situation. I'm having a bit of trouble tripping an interrupt from the timer0 module. I think I've got all of my initialization registers setup correctly, but I could be wrong. In particular the OPTION and INTCON registers.
Code:
/* setup stuff */
COUNT = 0x00; //clear timer module counter
OVERFLOW = 0; //clear the flag
TRISIO = 0x09; // GP3 always input, GP0 is analog input
GPIO = 0x00; // clear all outputs
STROBE = 1; // when not in use, should remain high
SELECT = 1; // same case
WPU = 0x00; // clear all weak pullups
//A/D MODULE
ADCON0 = 0x01; // AN0 selected, set ADON to turn on module, set GO/DONE to start an A/D conversion
ANSEL = 0x61; // AN0 selected as analog input, all other ports are digital
OPTION_REG = 0b10000101; //set timerpre-scaler to 64/prescaler assigned to timer module
// nGPPU = 1; // internal pullups disabled
// INTEDG = 0; // falling edge trigger the interrupt__don't care
// T0CS = 0; // timer transistion on cycle clock
// T0SE = 0 // increment on low to high transistion of GP2
// PSA = 0 // prescaler is set to the TIMER0 module
// ps>>101, or 64
INTCON = 0b11100000;
//GIE = 1 //enable global interrupts
//PEIE = 1 //enable peripheral interrupts
//T0IE = 1 //enable TMR0 interrupts
//INTE = 0 //disables GP2 interrupt
//GPIE = 0 //disables GPIO port change interrupt
//T0IF = 0 //timer0 overflow flag
//INTF = 0 //GP2 interrupt flag
//GPIF = 0 //ext pin change interrupt
T1CON = 0x00; //clear the friggin unused timer
PIE1 = 0x00; //nothing here is needed
Having broken down to the problem as much as I can, I've got a simple tidbit of code in the actual interrupt routine:
Code:
void interrupt ISR(){
if(T0IF){
//GPIO ^= 0x02 ;//pulse strobe
if (STROBE == 1){
STROBE = 0;
}
else{
STROBE = 1;
}
if(COUNT == 2){//prescaler =64, w/ 4mhz clock, this will reset overflow around 30Hz
OVERFLOW = 1;
}
T0IF = 0;//clear the overflow bit
TMR0 = 0;
//}
return;
}
My main routine after setup simply sits in a never ending for loop periodically kicking the dog, heheh.
The intent with this test is to try to pull a ~60Hz square wave on the scope from the appropriate pin (strobe is set to GPIO1), eventually changing my pre-scaler and counter values to adjust a display refresh rate. However I can't seem to get anything out of it from the ISR, as my scope signal lays dead at the logical high STROBE is left at initially.
Any thoughts, comments, suggestions? Possible conflicts you've dealt with in the past? I'm fairly new to PIC's with C, especially using any of the extra modules packed in the MCU. A slap in the face stupid newbie mistake is probably what you'll find (well, new to C with these little guys, just decided to make the switch from .asm) Thanks in advance for your time fellas!
Last edited: