|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19278
|
|
Posted: Mon Feb 08, 2016 1:26 am |
|
|
Currently your code dies after it is called 8 times. It drops off the end, and goes to sleep forever.....
Editing this:
You say:
Quote: |
As I understand the PIC will execute again the while loop and check for the character 'S' has been sent. But this does not occur.
|
The PIC _only_ does what you tell it. If you want it to loop back and start testing again, then you have to tell it to do this.
However an obvious comment arises. Why are you looping 8 times?.
There is no difference between any of the 8 loops. Your code simply reads 'S' and replies with 8 readings. If this is wanted to happen 'forever', then make the outer loop around this be 'forever'. Why do you limit it to 8 times?..... |
|
|
arelone
Joined: 06 Dec 2015 Posts: 42
|
|
Posted: Tue Feb 09, 2016 11:25 pm |
|
|
Hi,
The actual code is actually very long code. The code that I attached is to simplify the discussion. I would like to test the code if it can loop as required. In the discussion the code will read from 8 adc channels and tried to loop the code as required by the user. If the user required to have 4 frames than the code will loop for 4 times (8 samples x 4 frames=32 samples). In real application the samples in each frames will be different i.e frame#1: ch0,ch1...ch7; frame2: ch1,ch2,ch3...ch7,ch0 and so on. I make a little changes from the earlier code as to ensure it will loop forever. When the code completed acquire 8 samples a termination character 'A' will be send.
Code: |
#include <18F4580.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define button (PIN_B0)
void main()
{
unsigned char char_in;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_8);
const int8 channel1[]=0,1,2,3,4,5,6,7;
int16 ADC_value[sizeof(channel1)];
int8 value;
int z;
SETUP_ADC_PORTS(ALL_ANALOG); //all analogue
output_low(PIN_B6);
output_low(PIN_B7);
while(TRUE) //loop forever
//for (z=0;z<5;z++) //loop for 8 times ; 8x x 8 samples=64 =1 frame
{
while (TRUE)
{
//wait till 'S' is received to start acquisition if not send 'n' reply
//char_in=getc(); //get character from UART
//if (char_in=='S')
if(input(button) == 0) //RB0 when pressed o/p will be 0
break; //exit loop if 'S'
else
//putc('n'); //not 'S'
output_high(PIN_B6);
}
//get here when 'S' is pressed
for (z=0;z<1;z++) //1x=8 samples data for 1 frame image
{
output_low(PIN_B6);
output_low(PIN_B7);
for (value=0;value<sizeof(channel1);value++)
// read from 9 adc channels
{
set_adc_channel(channel1[value]);
ADC_value[value]=read_adc(); //ADC readings
printf("%04lu\r\n", ADC_value[value]); //4 digit adc value and new line between value
output_high(PIN_B7);
delay_ms(100);
}
//putc('A'); //send character 'E' for end of data
printf("A\r\n");
}
}
}
|
and I obtained the output from the code as following:
Quote: |
0255
0251
0142
0098
0075
0086
0072
0047
A
0255
0251
0151
0103
0074
0074
0080
0053
A
0255
0245
0163
0111
0075
|
From the code instead of sending the samples 8 times per frame is it possible to send all the 8 samples at one time when sample from each channels are available? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19278
|
|
Posted: Wed Feb 10, 2016 2:51 am |
|
|
Of course it is possible.
This is called programming....
To change the number of frames, you'd need to add commands to do this.
This is _not_ a general 'learn to program' forum.
This is a forum for specific 'CCS/PIC' questions/problems.
We stretch the point a little, but for general 'how can I make my program do this' questions, you need to go to a general programming forum.
The problems that were specific to CCS, have already been answered. |
|
|
|
|
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
|