SimpleIDE C code problem ...
Rsadeika
Posts: 3,837
in Propeller 1
… I think. Since the Activity Board only has four ADC channels, I am adding a Micromite chip, which has six ADC channels available. Plus, I might be able to offload some other stuff from the Activity Board, to keep within the RAM confines.
When I run the C program, I get the following output. I cannot figure out why I am getting 'Val2: 0.00'. It seems that the fromMM1() function should be providing the Val2 values. When I comment out the Val1 code, I get 'Val1: 0.00 Val2: 8.01'. This is a mystery to me, hope somebody picks up on a silly mistake that I am making.
Thanks
Ray
SimpleIDE terminal output
SimpleIDE C code
Micromite
When I run the C program, I get the following output. I cannot figure out why I am getting 'Val2: 0.00'. It seems that the fromMM1() function should be providing the Val2 values. When I comment out the Val1 code, I get 'Val1: 0.00 Val2: 8.01'. This is a mystery to me, hope somebody picks up on a silly mistake that I am making.
Thanks
Ray
SimpleIDE terminal output
Val1: 8.01 Val2: 0.00
Val1: 8.01 Val2: 0.00
Val1: 8.06 Val2: 0.00
Val1: 8.01 Val2: 0.00
Val1: 8.01 Val2: 0.00
Val1: 8.08 Val2: 0.00
Val1: 8.07 Val2: 0.00
Val1: 8.07 Val2: 0.00
Val1: 8.05 Val2: 0.00
Val1: 8.06 Val2: 0.00
Val1: 8.01 Val2: 0.00
Val1: 8.05 Val2: 0.00
Val1: 8.04 Val2: 0.00
Val1: 7.97 Val2: 0.00
SimpleIDE C code
/* homesta1.c May 10, 2019 New home station sensors setup. Uses: Activity WX Board and two Micromite uMCU(12 ADC channels total, ... Only have one Micromite on line. */ #include "simpletools.h" #include "wifi.h" #include "fdserial.h" #include "simpletext.h" serial *ser; /***********************/ /* wifi */ int event, id, handle; int getFromPageId; char cmdStr[64]; char *path; /***********************/ /***********************/ /* Global Variables */ volatile float mm1val1,mm1val2; //debug //int dbugc; /***********************/ /***********************/ /* COGed */ void fromMM1(); /***********************/ int main() { // Add startup code here. cog_run(fromMM1,128); pause(150); wifi_start(31, 30, 115200, WX_ALL_COM); pause(50); getFromPageId = wifi_listen(HTTP, "/tpfm*"); while(1) { // Add main loop code here. wifi_poll(&event, &id, &handle); if(event == 'G') { if(id == getFromPageId) { memset(cmdStr, 0, sizeof(cmdStr)); sprint(cmdStr, "PATH:%d\r", handle); path = wifi_command(cmdStr); if(strstr(path, "/Batt") != 0) { wifi_print(GET, handle, "%.2f", mm1val1); } } } else if(event == 'P') { } //pause(200); //debug print("Val1: %.2f ",mm1val1); print("Val2: %.2f\n",mm1val2); //print("%c\n",dbugc); pause(1000); } } /****************************/ /*COGed, receiving info fromm Micromite chip #1. */ void fromMM1() { ser = fdserial_open(1, 2, 0, 9600); float val1,val2; while(1) { writeDec(ser,1); // Send AIN channel 1 request. pause(165); val1 = readFloat(ser); // Receive data. if(val1 > 0 && val1 < 20.00) // Bracket the values. { mm1val1 = val1; // Make it global. } // Get the next AIN channel. pause(50); writeDec(ser,2); pause(165); val2 = readFloat(ser); if(val2 > 0 && val2 < 20) { mm1val2 = val2; } } }
Micromite
Open"COM2:9600" As #2 Do indi$ = " " Pause 150 indi$ = Input$(1,#2) If indi$ = "1" Then SetPin 2,AIN Print #2, Pin(2)*5.20945 ElseIf indi$ = "2" Then SetPin 3,AIN Print #2,Pin(3)*5.2094 'ElseIf indi$ = "3" Then ' SetPin 4,AIN ' Print #2,Pin(4) 'ElseIf indi$ = "4" Then ' SetPin 5,AIN ' 'ElseIf indi$ = "5" Then ' SetPin 6,AIN ' 'ElseIf indi$ = "6" Then ' SetPin 7,AIN ' EndIf loop
Comments
Mike
My guess is that fromMm1 needs more space. You might try starting it with 256 longs instead of 128 and see if that fixes your problem.
The only other thing that I can think of is maybe some kind of a timing problem between the two chips, in terms of reading and writing the data. Although their is no problem with the first go around, maybe something is going on with the second go around. Now how do I test that out. I tried inserting some more pauses, but that is not helping. Anybody have some better ideas?
I was also thinking about what is happening with the fdserial being opened and used in a COGed function. Is their something that I should be aware of, that might be affecting the functionality.
Ray
Now, I am wondering, maybe, instead of the serial approach, I should think about using an I2C setup?? So, maybe some of you experts could advise me with the serial vs I2C approach, for accomplishing my objective.
Ray
On the Micromite, I am using a do … loop, on the Activity Board, I am using a while() loop. So, how do I sync these two up, in order for them to talk to each other. On the Micromite, the input command does not have a, wait for data then continue feature, it just keeps looping.
Maybe I have to reverse the process, have the Micromite continuously send the data, and have the C code sort out the data that it has received. I sounds kind of awkward, but it may accomplish the desired affect. Also the Micromite has a pin interrupt feature, maybe have the C code trigger the Micromite ADC pin, to get the data that way. Boy, this is starting to look like some very complicated code on both ends.
Ray
I don't see the problem.
Mike
I think that I will wait for the P2 to become available. Not sure but I think the P2 will have multiple AD capable pins for usage. The next step in my project will need at least 12 ADC channels. Since I am using some voltage divider breakout boards that can bring down the DC voltage to less than three volts, then the usage of the P2 pins is a viable option, I am hoping. Also, some kind of WiFi module attachment would be a bonus. That with a SimpleIDE Linux version that could program the WiFi module, would be great.
Ray
I noticed the next batch of P2s got moved to Aug, I might have to get something then. But, the only problem that I can see is there has been no movement for a SimpleIDE for the P2, my preference for working with the Px. And, since I like working with the Px setup remotely, I guess the WiFi component is very important. I hope some of these things starts to fall into place, soon.
Ray
https://github.com/totalspectrum/spin2cpp/releases
Ray