|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Thu Oct 03, 2013 4:27 am |
|
|
I'd suggest, depending on the compiler version, adding setup_adc(NO_ANALOGS); at the start of the code. The 26J50, is one of the chips that with some compiler versions wakes up with the analogs enabled.
The INT_EXT line will never work if this is the case.
Repeat PCM_programmers statements though:
Post your code.
What is your compiler version ?
Best Wishes |
|
|
JosedeJesusC
Joined: 29 Mar 2013 Posts: 24
|
|
Posted: Sun Oct 06, 2013 6:26 pm |
|
|
Hi thanks for your reply here is my code.
my compiler version is PCWHD 4.105
Code: |
#include<18f26J50.h>
#fuses HSPLL, NOWDT, NOPROTECT, NODEBUG, PLLDIV1, NOCPUDIV, STVREN, NOXINST
#USE delay(clock = 48000000)
#define INTCON 0XFF2
#bit GIEH = INTCON.7// set up global all high priority interrupts
#bit GIEL = INTCON.6// set up global all low priority interrupts
#bit INT0IE = INTCON.4// anable interrupts by RB0
#bit INT0F = INTCON.1// Flag if interrupt ocurred
#byte INTCON2 = 0XFF1
#byte INTCON3 = 0XFF0
#define RCON 0xFD0
#BIT IPEN = RCON.7
#define ADS1251_DOUT_DRDY_PIN PIN_B0
#define ADS1251_SCLK_PIN PIN_B1
//----------------------Define ADS1254 COSNTANTS---------------------
#define ADS_CLK_FREQ 320000
#define ADS_SAMPLE_FREQ (ADS_CLK_FREQ / (6 * 64)) // A/D samples/second
#define ADS_CONVERSION_CYCLE_PERIOD_IN_USEC ((384 * 100000) / ADS_CLK_FREQ)
#define ADS_TIMEOUT_IN_USEC ADS_CONVERSION_CYCLE_PERIOD_IN_USEC
//------------------------------------------------------
// Utility macros
#define BytePtr(var, offset) (&(char)var + offset)
#ifdef __PCM__
#define interrupt_enabled(x) !!(*make8(x,1) & make8(x,0))
#endif
#ifdef __PCH__
#define interrupt_enabled(x) !!(*(make8(x,1) | 0xF00) & make8(x,0))
#endif
#ifdef __PCB__
#error interrupt_enabled(x) is not supported for the PCB compiler.
#endif
#ifdef __PCD__
#error interrupt_enabled(x) is not supported for the PCD compiler.
#endif
int8 read_ads1251(signed int32 &result)
{
int i = 0, gie_enabled;
output_high(PIN_B7); // IT TURN ON
if(interrupt_enabled(GLOBAL))// another way it tried if((GEIH == true) || (GEIL == true))
{
disable_interrupts(GLOBAL);
gie_enabled = TRUE;
}
else
{
gie_enabled = FALSE;
output_low(PIN_B7);
}
ext_int_edge(H_TO_L);
clear_interrupt(INT_EXT);
output_high(PIN_B6); // ALL IS WORKING TILL NOW
for(i = 0; i < ADS_TIMEOUT_IN_USEC; i++) // 8 ins. cycles/loop
{
//if(INTOF == TRUE) another way I tried
if(interrupt_active(INT_EXT))// <--- here the pic is broken in any way
{
break;
INT0F = FALSE;
output_high(PIN_B5);
}
delay_us(1);
} // end of for Loop
if(i == ADS_TIMEOUT_IN_USEC)return(FALSE);
delay_us(2);
// -------------- forward never is executed------------------------
output_high(PIN_B4);
for(i = 0; i < 6; i++)
{
output_low(ADS1251_SCLK_PIN);
shift_left(&result, 3, input(ADS1251_DOUT_DRDY_PIN));
output_high(ADS1251_SCLK_PIN);
output_low(ADS1251_SCLK_PIN);
shift_left(&result, 3, input(ADS1251_DOUT_DRDY_PIN));
output_high(ADS1251_SCLK_PIN);
output_low(ADS1251_SCLK_PIN);
shift_left(&result, 3, input(ADS1251_DOUT_DRDY_PIN));
output_high(ADS1251_SCLK_PIN);
output_low(ADS1251_SCLK_PIN);
shift_left(&result, 3, input(ADS1251_DOUT_DRDY_PIN));
output_high(ADS1251_SCLK_PIN);
}// end of for loop
output_low(ADS1251_SCLK_PIN);
if(gie_enabled)
{
enable_interrupts(GLOBAL);
}
if(bit_test(result, 23))
*BytePtr(result, 3) = 0xFF;
else
*BytePtr(result, 3) = 0x00;
return(TRUE);
}//end of ADS1254_READ
void main(void)
{
int8 status;
signed int32 adc_value;
INTCON2 = 0X00; // making sure rb3 and RBport priority interrupts are low
INTCON3 = 0X00; // making sure rb3, rb2 and rb1 interrupts are disabled and its priority are low
IPEN = 0X00; // making sure low priority
output_low(PIN_B3);
output_low(PIN_B2);
status = read_ads1251(adc_value);
// -------- never are executed-------------------------
if(status == TRUE)
{
output_high(PIN_B3);
output_low(PIN_B2);
}
else
{
output_high(PIN_B2);
output_low(PIN_B3);
}
delay_ms(1000);
}
|
As you can see, to verify where is the problem, I used LED in PIN_B7, PIN_B6, PIN_B5, PIN_B4, PIN_B3 and PIN_B2.
In the part of the for loop where the PIC have to verify if the interruption PIN_B0 flag is ocurred, the program never pass of this loop, because the leds PIN_B5 to PIN_B2 never are turned on.
In the oscilloscope the PIN_B1 it's in LOW, so the ADS1254 is waiting the SCLK signal, only I can see is the falling edge from the ADC.
I'm going to try that, you told me Ttelmah.
Thanks so much for your reply best regards have a good day |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Oct 06, 2013 9:11 pm |
|
|
Quote: | #define ADS_CLK_FREQ 320000 |
Do you really have only a 320 KHz clock frequency for the ads chip ?
Quote: | #define ADS_CONVERSION_CYCLE_PERIOD_IN_USEC ((384 * 100000) / ADS_CLK_FREQ) |
Why did you change this to 100000 ? It was 1000000 in my example
program. The purpose of that equation is to calculate the conversion
cycle period in microseconds. By changing the constant to only 100000
you have messed it up. With the correct constant of 1000000, the
result will be 1200 usec timeout period with your 320 KHz clock.
You have caused it to be 120 usec timeout, which is totally wrong.
Quote: | int i = 0, gie_enabled; |
Also, for the correct timeout value of 1200, 'i' must be declared as an int16. |
|
|
JosedeJesusC
Joined: 29 Mar 2013 Posts: 24
|
|
Posted: Sun Oct 06, 2013 10:56 pm |
|
|
OMG!!!! PCM programmer I'm so sorry. I'm wrong.
Integer of 8 bits just can represent till 255 :S.
I can achieve 8 MHz but It's just a trial, It seems the PIC is working now adding that instruction setup_adc(NO_ANALOGS); because it's lighting up the PIN_B4 and its after the loop where was the problem.
I'm going to check this out with the Oscilloscope I hope it's Ok.
Thanks so much for your time PCM Programer and Ttelmah. Best wishes |
|
|
|
|
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
|