Entropy wrote:...
This is a pic from my remote control captured signal
http://i.imgur.com/TBCsc5n.jpg
So far I figureout that a cicle is 883µs, a low is 485µs and a high is 398µs, but I cant get how to combine one low fallow by a high to give a "1" and a high fallow by a low to give a "0"
ric wrote:So do you know what to do now?
Entropy wrote:ric wrote:So do you know what to do now?
not yet, that toggle bit is a problem for me, http://www.pcbheaven.com/userpages/The_ ... _Protocol/ that purple thing between field and address
even Saleae is confused by it, this is a few tries I did for long button press and short clicks: http://i.imgur.com/ia2Jqe0.png , notice at the short clicks where the toggle is different, Saleae analyzer dont know where the adsress-command is anymore.
Yesterday I was thinking for a normal bit:
1. check the status of the pin if is low or high
2. start a timer up to 883µs
3. if an intrerrupt occurs and the timer is bellow lets say 490µs then check the status of the pin again
4. make a small case scenario like HIGH then LOW = 1 LOW->HIGH = 0 and store the result somewhere
5. 398µs after the intrerupt, it mean that the bit is done and resets the timer from point 2. Also this can be used to recalibrate(sync?) the timers. I notice that the timers vary even 5µs between bits. Puting 883µs on a fix loop probably will go wild after a while
#include <stdlib.h>
#include <xc.h>
#pragma config PLLDIV = 1 // PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CPUDIV = OSC1_PLL2// System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
#pragma config USBDIV = 1 // USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator (HS))
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOR = ON // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3 // Brown-out Reset Voltage bits (Minimum setting)
#pragma config VREGEN = OFF // USB Voltage Regulator Enable bit (USB voltage regulator disabled)
#pragma config WDT = ON // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
#pragma config CCP2MX = ON // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = OFF // Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM is not code-protected)
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM is not write-protected)
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)
#define _XTAL_FREQ 8000000
unsigned char i, byte;
unsigned char yolo[3];
void myputs( char *data)
{
while (*data) //loop until we hit a NULL Transmit a byte
{
while(PIR1bits.TXIF == 0); //wait until USART TX buffer is not full
TXREG = *data++; //send next character, then bump pointer
};
}
void interrupt docrap (void) {
INTCONbits.INT0E=0; //Disable the INT0 external interrupt
INTCONbits.INT0IF=0; //CLEAR
byte=0;
for (i=0;i<18;i++) {__delay_us(880);} //bits I dont care about
for (i=0;i<8;i++) {
__delay_us(880);
LATBbits.LB1=1;LATBbits.LB1=0; //here is a small impulse to see it on the scope
byte = (byte << 1) | PORTBbits.RB0;
}
if (byte==12){LATBbits.LB2=1;}else LATBbits.LB2=0;
itoa(yolo, byte, 10);
myputs(yolo);
while(BusyUSART());
__delay_us(800); // just a delay extra for making sure we are past the string comming from IR sensor
INTCONbits.INT0E=1; //Enables the INT0 external interrupt
INTCON2bits.INTEDG0=0; //Interrupt on falling edge
INTCONbits.INT0IF=0; //CLEAR
LATBbits.LB1=0;
}
void main(void){
ADCON1=0b00001111;
TRISBbits.TRISB0=1; // input from the sensor
TRISBbits.TRISB1=0; // for calibrating reading RB0 time
TRISBbits.TRISB2=0; //computer shut down
LATBbits.LB2=0;
LATBbits.LB0=0;
LATBbits.LB1=0;
OpenUSART (USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH &
USART_ADDEN_OFF, 51); //for 8MHz
while(BusyUSART());
INTCONbits.GIE=1; //Enables all unmasked interrupts
INTCONbits.PEIE=0; //Disables all peripheral interrupts
//There is no priority bit associated with INT0. It is always a high-priority interrupt source.
INTCONbits.INT0E=1; //Enables the INT0 external interrupt
//INT0 External Interrupt Flag bit 1 = The INT0 external interrupt occurred (must be cleared in software)
//DONT FORGET TO LEAR THIS
INTCON2bits.INTEDG0=0;//External Interrupt 0 Edge Select bit. Interrupt on falling edge
INTCONbits.INT0IF=0;
while (1){
LATBbits.LB1=0;
}
}
Return to Other PICmicro topics
Users browsing this forum: No registered users and 1 guest